登录页UI及长时间未操作锁定逻辑优化
This commit is contained in:
@@ -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("");
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user