// @vitest-environment jsdom // // A panel's layout is seeded from the account's server prefs when the app mounts. The adopt effect this // replaced corrected it after mounting; with it gone, a seed that read only this browser's copy would // never show a layout changed on another device. import { beforeEach, describe, expect, it } from "vitest"; import { seedLayout } from "./panelLayout"; import { ACTIVE_ACCOUNT_KEY } from "./activeAccount"; import { accountKey, LS } from "./storage"; const local = { order: [], collapsed: { genre: true }, hidden: {} }; beforeEach(() => { localStorage.clear(); sessionStorage.setItem(ACTIVE_ACCOUNT_KEY, "5"); localStorage.setItem(accountKey(LS.plexLayout, 5)!, JSON.stringify(local)); }); describe("seedLayout", () => { it("takes the account's server layout over this browser's copy", () => { const l = seedLayout("plex", { plexLayout: { order: [], collapsed: {}, hidden: { year: true } }, }); expect(l.hidden).toEqual({ year: true }); expect(l.collapsed).toEqual({}); }); it("uses this browser's copy for a layout the server has never stored", () => { expect(seedLayout("plex", {}).collapsed).toEqual({ genre: true }); expect(seedLayout("plex", undefined).collapsed).toEqual({ genre: true }); }); });