import { afterEach, beforeEach, describe, expect, it, vi } from "vitest"; import { _resetSharedPlayerStyleSheet, applyPlayerStyles, getSharedPlayerStyleSheet, PLAYER_STYLES, } from "./styles.js"; type AdoptingShadowRoot = ShadowRoot & { adoptedStyleSheets: CSSStyleSheet[]; }; function createShadowHost(): AdoptingShadowRoot { const host = document.createElement("div"); document.body.appendChild(host); return host.attachShadow({ mode: "open" }) as AdoptingShadowRoot; } describe("getSharedPlayerStyleSheet", () => { beforeEach(() => { _resetSharedPlayerStyleSheet(); }); it("returns the same CSSStyleSheet instance across calls", () => { const a = getSharedPlayerStyleSheet(); const b = getSharedPlayerStyleSheet(); expect(a).not.toBeNull(); expect(a).toBe(b); }); it("returns null and memoizes the failure when CSSStyleSheet is unavailable", () => { const original = globalThis.CSSStyleSheet; (globalThis as { CSSStyleSheet?: unknown }).CSSStyleSheet = undefined; try { expect(getSharedPlayerStyleSheet()).toBeNull(); expect(getSharedPlayerStyleSheet()).toBeNull(); } finally { globalThis.CSSStyleSheet = original; } }); }); describe("applyPlayerStyles", () => { beforeEach(() => { _resetSharedPlayerStyleSheet(); }); afterEach(() => { document.body.innerHTML = ""; }); it("adopts the shared sheet on a fresh shadow root and adds no