test: ≥95% coverage — daemon 96.9% (go), web 95.5-99% (vitest 142 tests); store.ts hooks-order crash fix
This commit is contained in:
@@ -0,0 +1,60 @@
|
||||
import { beforeEach, describe, expect, it } from "vitest";
|
||||
import {
|
||||
buildWsUrl,
|
||||
clearSettings,
|
||||
getSettings,
|
||||
saveSettings,
|
||||
} from "./settings";
|
||||
|
||||
describe("settings", () => {
|
||||
beforeEach(() => {
|
||||
localStorage.clear();
|
||||
});
|
||||
|
||||
it("getSettings returns null when absent", () => {
|
||||
expect(getSettings()).toBeNull();
|
||||
});
|
||||
|
||||
it("saveSettings then getSettings round-trips", () => {
|
||||
saveSettings({ serverUrl: "http://x:8686", token: "t1" });
|
||||
expect(getSettings()).toEqual({ serverUrl: "http://x:8686", token: "t1" });
|
||||
});
|
||||
|
||||
it("clearSettings removes stored settings", () => {
|
||||
saveSettings({ serverUrl: "http://x", token: "t" });
|
||||
clearSettings();
|
||||
expect(getSettings()).toBeNull();
|
||||
});
|
||||
|
||||
it("rejects corrupt JSON", () => {
|
||||
localStorage.setItem("lvmh.settings", "{not json");
|
||||
expect(getSettings()).toBeNull();
|
||||
});
|
||||
|
||||
it("rejects wrong shapes", () => {
|
||||
localStorage.setItem(
|
||||
"lvmh.settings",
|
||||
JSON.stringify({ serverUrl: 1, token: "x" }),
|
||||
);
|
||||
expect(getSettings()).toBeNull();
|
||||
localStorage.setItem("lvmh.settings", JSON.stringify("nope"));
|
||||
expect(getSettings()).toBeNull();
|
||||
localStorage.setItem(
|
||||
"lvmh.settings",
|
||||
JSON.stringify({ serverUrl: "http://x" }),
|
||||
);
|
||||
expect(getSettings()).toBeNull();
|
||||
});
|
||||
|
||||
it("buildWsUrl converts scheme and appends encoded token", () => {
|
||||
expect(buildWsUrl({ serverUrl: "http://a:1", token: "tok" })).toBe(
|
||||
"ws://a:1/ws?token=tok",
|
||||
);
|
||||
expect(buildWsUrl({ serverUrl: "https://a:1/", token: "tok" })).toBe(
|
||||
"wss://a:1/ws?token=tok",
|
||||
);
|
||||
expect(buildWsUrl({ serverUrl: "http://a:1//", token: "a b/c" })).toBe(
|
||||
"ws://a:1/ws?token=a%20b%2Fc",
|
||||
);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user