45 lines
1.4 KiB
TypeScript
45 lines
1.4 KiB
TypeScript
/**
|
|
* @file splitViewStorage.test.ts
|
|
* @description Tests for the splitViewStorage module.
|
|
* @author Nguyễn Ngọc Trí Vĩ <vinnt@smartgift.vn>
|
|
*/
|
|
|
|
import { describe, it, expect, beforeEach } from "vitest";
|
|
import {
|
|
readSplitViewState,
|
|
writeSplitViewState,
|
|
defaultSplitViewState,
|
|
} from "../splitViewStorage";
|
|
|
|
describe("splitViewStorage", () => {
|
|
beforeEach(() => {
|
|
localStorage.clear();
|
|
});
|
|
|
|
it("returns the default state when nothing is stored", () => {
|
|
expect(readSplitViewState()).toEqual(defaultSplitViewState());
|
|
});
|
|
|
|
it("defaults to a single unselected pane", () => {
|
|
expect(defaultSplitViewState()).toEqual({ layout: 1, paneLaneIds: [null] });
|
|
});
|
|
|
|
it("round-trips a written state", () => {
|
|
writeSplitViewState({ layout: 4, paneLaneIds: [1, 2, null, null] });
|
|
expect(readSplitViewState()).toEqual({ layout: 4, paneLaneIds: [1, 2, null, null] });
|
|
});
|
|
|
|
it("falls back to the default when stored JSON is malformed", () => {
|
|
localStorage.setItem("ccam.workspace.splitView", "{not json");
|
|
expect(readSplitViewState()).toEqual(defaultSplitViewState());
|
|
});
|
|
|
|
it("falls back to the default when the stored layout is not 1, 2, or 4", () => {
|
|
localStorage.setItem(
|
|
"ccam.workspace.splitView",
|
|
JSON.stringify({ layout: 3, paneLaneIds: [] })
|
|
);
|
|
expect(readSplitViewState()).toEqual(defaultSplitViewState());
|
|
});
|
|
});
|