| 1 | // Run: tsx src/__tests__/layout-style-defaults.test.ts |
| 2 | |
| 3 | import { JSDOM } from "jsdom"; |
| 4 | |
| 5 | let passed = 0; |
| 6 | let failed = 0; |
| 7 | |
| 8 | function eq(actual: unknown, expected: unknown, label: string) { |
| 9 | if (actual === expected) { |
| 10 | process.stdout.write(` PASS ${label}\n`); |
| 11 | passed += 1; |
| 12 | } else { |
| 13 | process.stdout.write(` FAIL ${label}: expected ${JSON.stringify(expected)}, got ${JSON.stringify(actual)}\n`); |
| 14 | failed += 1; |
| 15 | } |
| 16 | } |
| 17 | |
| 18 | console.log("\nlayout style defaults"); |
| 19 | |
| 20 | const dom = new JSDOM("<!doctype html><html><body></body></html>", { url: "http://localhost" }); |
| 21 | Object.defineProperty(dom.window, "innerWidth", { configurable: true, value: 1920 }); |
| 22 | globalThis.window = dom.window as unknown as Window & typeof globalThis; |
| 23 | |
| 24 | const layout = await import("../store/layout"); |
| 25 | |
| 26 | eq(layout.defaultSidebarWidth(), 300, "wide classic default remains responsive"); |
| 27 | eq(layout.useLayoutStore.getState().sidebarWidth, 300, "shared store starts from the classic sidebar default"); |
| 28 | eq(layout.useLayoutStore.getState().rightDockTreeWidth, 300, "shared store starts from the classic dock default"); |
| 29 | |
| 30 | layout.applyLayoutStyleDefaults("creation"); |
| 31 | eq(layout.useLayoutStore.getState().sidebarWidth, 236, "Creation applies its sidebar default after style hydration"); |
| 32 | eq(layout.useLayoutStore.getState().rightDockTreeWidth, 252, "Creation applies its dock default after style hydration"); |
| 33 | eq(dom.window.localStorage.getItem("reasonix.layoutPreferences.v1"), null, "applying defaults does not overwrite user preferences"); |
| 34 | |
| 35 | layout.applyLayoutStyleDefaults("workbench"); |
| 36 | eq(layout.useLayoutStore.getState().sidebarWidth, 300, "switching to workbench restores its responsive sidebar default"); |
| 37 | eq(layout.useLayoutStore.getState().rightDockTreeWidth, 300, "switching to workbench restores its dock default"); |
| 38 | |
| 39 | layout.saveSidebarWidth(286); |
| 40 | layout.saveRightDockTreeWidth(344); |
| 41 | layout.useLayoutStore.getState().setSidebarWidth(286); |
| 42 | layout.useLayoutStore.getState().setRightDockTreeWidth(344); |
| 43 | layout.applyLayoutStyleDefaults("creation"); |
| 44 | eq(layout.useLayoutStore.getState().sidebarWidth, 286, "Creation preserves a saved sidebar width"); |
| 45 | eq(layout.useLayoutStore.getState().rightDockTreeWidth, 344, "Creation preserves a saved dock width"); |
| 46 | |
| 47 | dom.window.close(); |
| 48 | |
| 49 | console.log(`\n${passed} passed, ${failed} failed, ${passed + failed} total`); |
| 50 | if (failed > 0) process.exit(1); |
| 51 |