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:
62
test/common/auth/token_storage/askWrite.test.ts
Normal file
62
test/common/auth/token_storage/askWrite.test.ts
Normal 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);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user