Open History to see the last commit
1import { describe, expect, it } from "vite-plus/test";
2
3import { defaultThemeGeneration, defaultThemeToApply } from "./useDefaultTheme";
4
5const BASE = {
6 environmentId: "env-1",
7 defaultTheme: "nightfall",
8 defaultThemeSetAt: "2026-08-28T00:00:00.000Z",
9 appliedGeneration: null,
10 resolves: true,
11} as const;
12
13describe("default theme adoption", () => {
14 it("applies a set this client has not seen", () => {
15 expect(defaultThemeToApply(BASE)).toBe(
16 defaultThemeGeneration(BASE.defaultTheme, BASE.defaultThemeSetAt),
17 );
18 });
19
20 it("does not replay a generation it already applied", () => {
21 const generation = defaultThemeGeneration(BASE.defaultTheme, BASE.defaultThemeSetAt);
22 expect(defaultThemeToApply({ ...BASE, appliedGeneration: generation })).toBe(null);
23 });
24
25 it("applies the same theme again when the environment re-sets it", () => {
26 const applied = defaultThemeGeneration(BASE.defaultTheme, "2026-08-28T00:00:00.000Z");
27 const next = defaultThemeToApply({
28 ...BASE,
29 defaultThemeSetAt: "2026-08-29T00:00:00.000Z",
30 appliedGeneration: applied,
31 });
32 expect(next).not.toBe(null);
33 expect(next).not.toBe(applied);
34 });
35
36 it("falls back to once-per-value without a set time", () => {
37 const generation = defaultThemeGeneration("nightfall", "");
38 expect(defaultThemeToApply({ ...BASE, defaultThemeSetAt: "", appliedGeneration: null })).toBe(
39 generation,
40 );
41 expect(
42 defaultThemeToApply({ ...BASE, defaultThemeSetAt: "", appliedGeneration: generation }),
43 ).toBe(null);
44 });
45
46 it("waits for a theme that has not arrived yet", () => {
47 expect(defaultThemeToApply({ ...BASE, resolves: false })).toBe(null);
48 });
49
50 it("leaves a client alone with no environment or no theme set", () => {
51 expect(defaultThemeToApply({ ...BASE, environmentId: null })).toBe(null);
52 expect(defaultThemeToApply({ ...BASE, defaultTheme: "" })).toBe(null);
53 });
54});