using AcDream.App.Studio; using AcDream.App.UI; using AcDream.App.UI.Layout; using DatReaderWriter; using DatReaderWriter.Options; namespace AcDream.App.Tests.Studio; /// /// Unit tests for . The dat-backed test skips cleanly /// when the real dats are not present (CI / dev machines without AC installed). /// public class LayoutSourceTests { private static (uint handle, int width, int height) NoTex(uint _) => (1u, 1, 1); /// Resolve the client dat directory, or null if unavailable (skip the test). private static string? ResolveDatDir() { var fromEnv = Environment.GetEnvironmentVariable("ACDREAM_DAT_DIR"); if (!string.IsNullOrWhiteSpace(fromEnv) && Directory.Exists(fromEnv)) return fromEnv; var def = Path.Combine( Environment.GetFolderPath(Environment.SpecialFolder.UserProfile), "Documents", "Asheron's Call"); return Directory.Exists(def) ? def : null; } /// /// Load the vitals LayoutDesc (0x2100006C) from the real dats and verify /// that LayoutSource returns a non-null root with the layout id findable. /// Skips when the dats are unavailable. /// /// Note: the spec asserts FindElement(0x2100006Cu) — that is the layout dat /// id, not an element id in the widget tree. The actual vitals root element id /// is 0x100005F9 (confirmed from vitals_2100006C.json fixture). We assert /// FindElement(0x100005F9) here which verifies the same integration path: the /// layout was successfully loaded and the element dict was populated. /// [Fact] public void LoadsDatLayout_byId() { var dir = ResolveDatDir(); if (dir is null) return; // Skip: dats not available on this machine / CI. using var dats = new DatCollection(dir, DatAccessType.Read); var src = new LayoutSource(dats, NoTex, datFont: null); var root = src.Load(new StudioOptions(dir, 0x2100006Cu, null)); // root must be non-null: Import found the LayoutDesc and built the tree. Assert.NotNull(root); Assert.NotNull(src.CurrentLayout); // The vitals root element id is 0x100005F9 (layout dat id 0x2100006C ≠ element id). // Asserting FindElement verifies the byId dict was populated by the importer. Assert.NotNull(src.CurrentLayout!.FindElement(0x100005F9u)); Assert.Equal(LayoutSourceKind.DatLayout, src.Kind); } }