1
0
mirror of https://github.com/home-assistant/frontend.git synced 2026-04-19 08:20:41 +01:00

Use localStorage with Web Storage API (#23172)

This commit is contained in:
Wendelin
2024-12-10 11:14:15 +01:00
committed by GitHub
parent 008647aa7a
commit 8f19c0abb0
18 changed files with 773 additions and 38 deletions

View File

@@ -0,0 +1,62 @@
import { afterEach, describe, expect, test, vi } from "vitest";
let askWrite;
describe("token_storage.askWrite", () => {
afterEach(() => {
vi.resetModules();
});
test("askWrite", async () => {
vi.stubGlobal(
"window.__tokenCache",
(window.__tokenCache = {
tokens: undefined,
writeEnabled: true,
})
);
({ askWrite } = await import("../../../../src/common/auth/token_storage"));
expect(askWrite()).toBe(false);
});
test("askWrite prefilled token", async () => {
vi.stubGlobal(
"window.__tokenCache",
(window.__tokenCache = {
tokens: {
access_token: "test",
expires: 1800,
expires_in: 1800,
hassUrl: "http://localhost",
refresh_token: "refresh",
clientId: "client",
},
writeEnabled: undefined,
})
);
({ askWrite } = await import("../../../../src/common/auth/token_storage"));
expect(askWrite()).toBe(true);
});
test("askWrite prefilled token, write enabled", async () => {
vi.stubGlobal(
"window.__tokenCache",
(window.__tokenCache = {
tokens: {
access_token: "test",
expires: 1800,
expires_in: 1800,
hassUrl: "http://localhost",
refresh_token: "refresh",
clientId: "client",
},
writeEnabled: true,
})
);
({ askWrite } = await import("../../../../src/common/auth/token_storage"));
expect(askWrite()).toBe(false);
});
});