| 1 | import { describe, expect, it } from "vite-plus/test"; |
| 2 | |
| 3 | import { |
| 4 | createMobileThemeRuntimeOperations, |
| 5 | getMobileUniwindThemeName, |
| 6 | type MobileThemeRuntimeState, |
| 7 | } from "./mobileThemeRuntime"; |
| 8 | |
| 9 | const initialState: MobileThemeRuntimeState = { |
| 10 | baseFontSize: 16, |
| 11 | themeAppearance: "light", |
| 12 | themeMode: "system", |
| 13 | }; |
| 14 | |
| 15 | describe("mobileThemeRuntime", () => { |
| 16 | it("keeps the default palette on Uniwind's built-in appearance themes", () => { |
| 17 | expect(getMobileUniwindThemeName("t3-code", "light")).toBe("light"); |
| 18 | expect(getMobileUniwindThemeName("t3-code", "dark")).toBe("dark"); |
| 19 | }); |
| 20 | |
| 21 | it("maps custom palettes and appearances to registered themes", () => { |
| 22 | expect(getMobileUniwindThemeName("t3-chat", "dark")).toBe("t3-chat-dark"); |
| 23 | }); |
| 24 | |
| 25 | it("hydrates text variables and clears the native appearance override", () => { |
| 26 | const operations = createMobileThemeRuntimeOperations(null, initialState); |
| 27 | const variableOperations = operations.filter( |
| 28 | (operation) => operation.kind === "update-text-variables", |
| 29 | ); |
| 30 | |
| 31 | expect(variableOperations).toHaveLength(12); |
| 32 | expect(variableOperations.at(-1)?.themeName).toBe("iris-dark"); |
| 33 | expect(operations.at(-1)).toEqual({ |
| 34 | kind: "set-appearance-mode", |
| 35 | appearance: "light", |
| 36 | themeMode: "system", |
| 37 | }); |
| 38 | }); |
| 39 | |
| 40 | it("lets system appearance changes flow through the root ScopedTheme only", () => { |
| 41 | const operations = createMobileThemeRuntimeOperations(initialState, { |
| 42 | ...initialState, |
| 43 | themeAppearance: "dark", |
| 44 | }); |
| 45 | |
| 46 | expect(operations).toEqual([]); |
| 47 | }); |
| 48 | |
| 49 | it("updates native appearance once when the selected mode changes", () => { |
| 50 | const operations = createMobileThemeRuntimeOperations(initialState, { |
| 51 | ...initialState, |
| 52 | themeAppearance: "dark", |
| 53 | themeMode: "dark", |
| 54 | }); |
| 55 | |
| 56 | expect(operations).toEqual([ |
| 57 | { |
| 58 | kind: "set-appearance-mode", |
| 59 | appearance: "dark", |
| 60 | themeMode: "dark", |
| 61 | }, |
| 62 | ]); |
| 63 | }); |
| 64 | |
| 65 | it("updates text variables for every theme without switching palettes", () => { |
| 66 | const operations = createMobileThemeRuntimeOperations(initialState, { |
| 67 | ...initialState, |
| 68 | baseFontSize: 18, |
| 69 | }); |
| 70 | |
| 71 | expect(operations).toHaveLength(12); |
| 72 | expect(operations.every((operation) => operation.kind === "update-text-variables")).toBe(true); |
| 73 | expect(operations.at(-1)).toMatchObject({ |
| 74 | kind: "update-text-variables", |
| 75 | themeName: "iris-dark", |
| 76 | }); |
| 77 | }); |
| 78 | |
| 79 | it("does no native work when persistence echoes an already-applied state", () => { |
| 80 | expect(createMobileThemeRuntimeOperations(initialState, initialState)).toEqual([]); |
| 81 | }); |
| 82 | }); |