Files
v2rayA/gui/src/session.spec.ts
T
Zakk 89fb7d87b1 feat(gui): the spine — typed API, session, store, composables, theme
The backend's calls in one typed module with a session-scoped client
(a reset aborts every request, a 401 ends the session, a busy backend is
asked again for a read); the Pinia store; composables for dialogs,
notices, banners, loading, the message socket, the traffic ring buffer,
the log stream and outbound groups; the share-link codec moved from the
old editor; the Material 3 theme derived from a seed colour (tonal
spot, monochrome for colourless seeds), the type scale and the
component overrides.
2026-09-19 23:17:05 +10:00

38 lines
1.5 KiB
TypeScript

// @vitest-environment happy-dom
import { describe, expect, test } from "vitest";
import { createPinia, setActivePinia } from "pinia";
import { onSessionTeardown, resetSession, setSessionStarter } from "./session";
import { openDialog, dialogState } from "./composables/useDialog";
import { useNotify, noticeState } from "./composables/useNotify";
import { openLoading, loadingState } from "./composables/useLoading";
import { useAppStore } from "./stores/app";
describe("resetSession runs the teardown in order", () => {
test("teardown, then what is on screen, then the stores, then the starter", async () => {
const pinia = createPinia();
setActivePinia(pinia);
const order: string[] = [];
onSessionTeardown(() => order.push("teardown"));
openDialog({ render: () => null }).result.then(() =>
order.push("dialog closed"),
);
useNotify().info("x");
openLoading();
const app = useAppStore(pinia);
app.setRunning("running");
setSessionStarter(async () => {
order.push(`start:${app.token}@${app.backendAddress}:${app.running}`);
});
await resetSession({ token: "tok-2", backendAddress: "http://b" }, pinia);
expect(order).toEqual([
"teardown",
"dialog closed",
"start:tok-2@http://b:checking",
]);
expect(dialogState.stack).toHaveLength(0);
expect(noticeState.current).toBeNull();
expect(loadingState.open.size).toBe(0);
expect(localStorage.getItem("token")).toBe("tok-2");
});
});