All of the mid-session and step-up auth work
This commit is contained in:
parent
1f31e0f1f8
commit
562bdd00f1
1 changed files with 11437 additions and 1212 deletions
44
clients/web/src/utils/browserTabVisibility.test.ts
Normal file
44
clients/web/src/utils/browserTabVisibility.test.ts
Normal file
|
|
@ -0,0 +1,44 @@
|
|||
import { describe, it, expect, vi, beforeEach, afterEach } from "vitest";
|
||||
import {
|
||||
isBrowserTabVisible,
|
||||
onBrowserTabVisible,
|
||||
} from "./browserTabVisibility.js";
|
||||
|
||||
describe("browserTabVisibility", () => {
|
||||
beforeEach(() => {
|
||||
vi.stubGlobal("document", {
|
||||
visibilityState: "visible",
|
||||
addEventListener: vi.fn(),
|
||||
removeEventListener: vi.fn(),
|
||||
});
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
vi.unstubAllGlobals();
|
||||
});
|
||||
|
||||
it("isBrowserTabVisible reflects document.visibilityState", () => {
|
||||
expect(isBrowserTabVisible()).toBe(true);
|
||||
(document as { visibilityState: string }).visibilityState = "hidden";
|
||||
expect(isBrowserTabVisible()).toBe(false);
|
||||
});
|
||||
|
||||
it("onBrowserTabVisible invokes callback when becoming visible", () => {
|
||||
let handler: (() => void) | undefined;
|
||||
vi.mocked(document.addEventListener).mockImplementation((_event, fn) => {
|
||||
handler = fn as () => void;
|
||||
});
|
||||
|
||||
const callback = vi.fn();
|
||||
onBrowserTabVisible(callback);
|
||||
expect(handler).toBeDefined();
|
||||
|
||||
(document as { visibilityState: string }).visibilityState = "hidden";
|
||||
handler!();
|
||||
expect(callback).not.toHaveBeenCalled();
|
||||
|
||||
(document as { visibilityState: string }).visibilityState = "visible";
|
||||
handler!();
|
||||
expect(callback).toHaveBeenCalledOnce();
|
||||
});
|
||||
});
|
||||
Loading…
Reference in a new issue