Skip to content
Source
Sign inSign up
pingdotgg/t3code
Open History to see the last commit

mobileThemeVariables.test.ts

101 lines4.1 KB

1import { describe, expect, it } from "vite-plus/test";
2​
3import { readDefaultMobileThemeVariables } from "./mobileTheme.test-support";
4import { getMobileThemeVariables, MOBILE_THEME_IDS, themeColorWithAlpha } from "./mobileTheme";
5import { getMobileThemeRuntimeVariables } from "./mobileThemeVariables";
6​
7describe("mobile theme runtime variables", () => {
8 it("matches the standard base palette to the generated stylesheet", () => {
9 expect(getMobileThemeRuntimeVariables("t3-code", "light", "web")).toEqual(
10 readDefaultMobileThemeVariables("light"),
11 );
12 expect(getMobileThemeRuntimeVariables("t3-code", "dark", "web")).toEqual(
13 readDefaultMobileThemeVariables("dark"),
14 );
15 });
16​
17 it("uses the same shared palette source as generated custom themes", () => {
18 expect(getMobileThemeRuntimeVariables("ocean", "light", "ios")).toEqual(
19 getMobileThemeVariables("ocean", "light"),
20 );
21 expect(getMobileThemeRuntimeVariables("iris", "dark", "ios")).toEqual(
22 getMobileThemeVariables("iris", "dark"),
23 );
24 });
25​
26 it.each(MOBILE_THEME_IDS)(
27 "keeps %s colors on Android with an opaque Material frame",
28 (themeId) => {
29 for (const appearance of ["light", "dark"] as const) {
30 const base = getMobileThemeVariables(
31 themeId === "material-you" ? "t3-code" : themeId,
32 appearance,
33 );
34 const android = getMobileThemeRuntimeVariables(themeId, appearance, "android");
35 expect(android).toEqual({
36 ...base,
37 "--color-header": themeColorWithAlpha(
38 base[
39 themeId === "t3-code" || themeId === "material-you"
40 ? "--color-row-hover"
41 : "--color-drawer"
42 ],
43 1,
44 ),
45 "--color-header-foreground": base["--color-drawer-foreground"],
46 });
47 expect(android["--color-header"]).toMatch(/^rgba\(\d+, \d+, \d+, 1\)$/);
48 }
49 },
50 );
51​
52 it.each(["t3-code", "material-you"] as const)(
53 "keeps the %s default Material frame distinct in both appearances",
54 (themeId) => {
55 for (const appearance of ["light", "dark"] as const) {
56 const variables = getMobileThemeRuntimeVariables(themeId, appearance, "android");
57 expect(variables["--color-header"]).toBe(
58 appearance === "light" ? "rgba(244, 244, 245, 1)" : "rgba(20, 20, 20, 1)",
59 );
60 for (const pane of ["--color-screen", "--color-sheet-solid", "--color-drawer"] as const) {
61 expect(variables["--color-header"]).not.toBe(themeColorWithAlpha(variables[pane], 1));
62 }
63 }
64 },
65 );
66​
67 it.each(["t3-code", "material-you"] as const)(
68 "adapts %s iPad chrome without reversing the dark desktop hierarchy",
69 (themeId) => {
70 for (const appearance of ["light", "dark"] as const) {
71 const ios = getMobileThemeRuntimeVariables(themeId, appearance, "ios");
72 const android = getMobileThemeRuntimeVariables(themeId, appearance, "android");
73 if (appearance === "light") {
74 expect(ios["--color-drawer"]).toBe(android["--color-header"]);
75 expect(ios["--color-header"]).toBe(android["--color-header"]);
76 expect(ios["--color-header-foreground"]).toBe(ios["--color-drawer-foreground"]);
77 } else {
78 expect(ios).toEqual(getMobileThemeVariables("t3-code", appearance));
79 expect(ios["--color-drawer"]).toBe(android["--color-drawer"]);
80 expect(ios["--color-drawer"]).toBe("#000000");
81 expect(ios["--color-thread-canvas"]).toBe("#0a0a0a");
82 }
83 expect(themeColorWithAlpha(ios["--color-thread-hover"], 1)).not.toBe(
84 themeColorWithAlpha(ios["--color-drawer"], 1),
85 );
86 expect(themeColorWithAlpha(ios["--color-thread-hover"], 1)).not.toBe(
87 themeColorWithAlpha(ios["--color-thread-selected"], 1),
88 );
89 for (const role of [
90 "--color-screen",
91 "--color-thread-canvas",
92 "--color-card",
93 "--color-composer-surface",
94 "--color-grouped-card",
95 ] as const) {
96 expect(ios[role]).toBe(android[role]);
97 }
98 }
99 },
100 );
101});