feat: add shared toolbox header and appearance
This commit is contained in:
63
packages/contract/test/preferences.test.ts
Normal file
63
packages/contract/test/preferences.test.ts
Normal file
@@ -0,0 +1,63 @@
|
||||
import {
|
||||
TOOLBOX_PREFERENCES_KEY,
|
||||
defaultToolboxPreferences,
|
||||
parseToolboxPreferences,
|
||||
readToolboxPreferences,
|
||||
writeToolboxPreferences,
|
||||
} from "../src/index.js";
|
||||
import { describe, expect, it } from "vitest";
|
||||
|
||||
function memoryStorage(initial?: string) {
|
||||
const values = new Map<string, string>();
|
||||
if (initial !== undefined) values.set(TOOLBOX_PREFERENCES_KEY, initial);
|
||||
return {
|
||||
getItem: (key: string) => values.get(key) ?? null,
|
||||
setItem: (key: string, value: string) => values.set(key, value),
|
||||
};
|
||||
}
|
||||
|
||||
describe("shared toolbox preferences", () => {
|
||||
it("parses version 1 and removes duplicate ids", () => {
|
||||
expect(
|
||||
parseToolboxPreferences({
|
||||
version: 1,
|
||||
pinned: ["pdf", "pdf"],
|
||||
order: ["pdf", "xslt"],
|
||||
hidden: [],
|
||||
theme: "dark",
|
||||
}),
|
||||
).toEqual({
|
||||
version: 1,
|
||||
pinned: ["pdf"],
|
||||
order: ["pdf", "xslt"],
|
||||
hidden: [],
|
||||
theme: "dark",
|
||||
});
|
||||
});
|
||||
|
||||
it("returns independent defaults for missing or corrupt storage", () => {
|
||||
const missing = readToolboxPreferences(memoryStorage());
|
||||
const corrupt = readToolboxPreferences(memoryStorage("not json"));
|
||||
missing.pinned.push("pdf");
|
||||
expect(corrupt).toEqual(defaultToolboxPreferences);
|
||||
expect(corrupt.pinned).toEqual([]);
|
||||
});
|
||||
|
||||
it("writes validated preferences under the compatible portal key", () => {
|
||||
const storage = memoryStorage();
|
||||
writeToolboxPreferences(
|
||||
{
|
||||
version: 1,
|
||||
pinned: ["pdf"],
|
||||
order: ["pdf"],
|
||||
hidden: [],
|
||||
theme: "light",
|
||||
},
|
||||
storage,
|
||||
);
|
||||
expect(readToolboxPreferences(storage)).toMatchObject({
|
||||
pinned: ["pdf"],
|
||||
theme: "light",
|
||||
});
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user