登录页UI及长时间未操作锁定逻辑优化

This commit is contained in:
Cheng Zhou
2026-03-10 10:10:58 +08:00
parent 7936c55f3f
commit 4c98147f3e
12 changed files with 2225 additions and 470 deletions
+49
View File
@@ -0,0 +1,49 @@
import { beforeEach, describe, expect, it } from "vitest";
import { createPinia, setActivePinia } from "pinia";
type StorageLike = {
getItem: (key: string) => string | null;
setItem: (key: string, value: string) => void;
removeItem: (key: string) => void;
clear: () => void;
};
const createStorage = (): StorageLike => {
const data = new Map<string, string>();
return {
getItem: (key) => data.get(key) ?? null,
setItem: (key, value) => {
data.set(key, String(value));
},
removeItem: (key) => {
data.delete(key);
},
clear: () => {
data.clear();
},
};
};
describe("auth store logout", () => {
beforeEach(() => {
setActivePinia(createPinia());
Object.defineProperty(window, "localStorage", {
value: createStorage(),
configurable: true,
});
});
it("clears session lock state when logging out", async () => {
const { useAuthStore } = await import("./auth");
const { useSessionStore } = await import("./session");
const session = useSessionStore();
const auth = useAuthStore();
session.lock("token_invalid", "demo@example.com", Date.now() + 60_000);
auth.logout();
expect(session.locked).toBe(false);
expect(session.lockReason).toBeNull();
expect(session.lockEmail).toBe("");
});
});