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

branding.test.ts

105 lines3.0 KB

1import { afterEach, describe, expect, it, vi } from "vite-plus/test";
2import {
3 resolveServerBackedAppDisplayName,
4 resolveServerBackedAppStageLabel,
5} from "./branding.logic";
6​
7const originalWindow = globalThis.window;
8​
9afterEach(() => {
10 vi.resetModules();
11​
12 if (originalWindow === undefined) {
13 Reflect.deleteProperty(globalThis, "window");
14 return;
15 }
16​
17 globalThis.window = originalWindow;
18});
19​
20describe("branding", () => {
21 it("uses injected desktop branding when available", async () => {
22 Object.defineProperty(globalThis, "window", {
23 configurable: true,
24 value: {
25 desktopBridge: {
26 getAppBranding: () => ({
27 baseName: "T3 Code",
28 stageLabel: "Nightly",
29 displayName: "T3 Code (Nightly)",
30 }),
31 },
32 },
33 });
34​
35 const branding = await import("./branding");
36​
37 expect(branding.APP_BASE_NAME).toBe("T3 Code");
38 expect(branding.APP_STAGE_LABEL).toBe("Nightly");
39 expect(branding.APP_DISPLAY_NAME).toBe("T3 Code (Nightly)");
40 });
41​
42 it("normalizes hosted app channel metadata", async () => {
43 vi.stubEnv("VITE_HOSTED_APP_CHANNEL", "nightly");
44​
45 const branding = await import("./branding");
46​
47 expect(branding.HOSTED_APP_CHANNEL).toBe("nightly");
48 expect(branding.HOSTED_APP_CHANNEL_LABEL).toBe("Nightly");
49 expect(branding.APP_STAGE_LABEL).toBe("Nightly");
50 expect(branding.APP_DISPLAY_NAME).toBe("T3 Code (Nightly)");
51 });
52​
53 it("ignores unknown hosted app channels", async () => {
54 vi.stubEnv("VITE_HOSTED_APP_CHANNEL", "preview");
55​
56 const branding = await import("./branding");
57​
58 expect(branding.HOSTED_APP_CHANNEL).toBeNull();
59 expect(branding.HOSTED_APP_CHANNEL_LABEL).toBeNull();
60 });
61});
62​
63describe("branding logic", () => {
64 it("returns Nightly for nightly primary server versions", () => {
65 expect(
66 resolveServerBackedAppStageLabel({
67 primaryServerVersion: "0.0.28-nightly.20260616.12",
68 fallbackStageLabel: "Alpha",
69 }),
70 ).toBe("Nightly");
71 });
72​
73 it("updates the display name for nightly primary server versions", () => {
74 expect(
75 resolveServerBackedAppDisplayName({
76 baseName: "T3 Code",
77 fallbackDisplayName: "T3 Code (Alpha)",
78 fallbackStageLabel: "Alpha",
79 primaryServerVersion: "0.0.28-nightly.20260616.12",
80 }),
81 ).toBe("T3 Code (Nightly)");
82 });
83​
84 it("keeps the fallback display name for stable primary server versions", () => {
85 expect(
86 resolveServerBackedAppDisplayName({
87 baseName: "T3 Code",
88 fallbackDisplayName: "T3 Code (Alpha)",
89 fallbackStageLabel: "Alpha",
90 primaryServerVersion: "0.0.27",
91 }),
92 ).toBe("T3 Code (Alpha)");
93 });
94​
95 it("keeps the fallback display name for malformed nightly primary server versions", () => {
96 expect(
97 resolveServerBackedAppDisplayName({
98 baseName: "T3 Code",
99 fallbackDisplayName: "T3 Code (Alpha)",
100 fallbackStageLabel: "Alpha",
101 primaryServerVersion: "0.0.28-nightly.20260616",
102 }),
103 ).toBe("T3 Code (Alpha)");
104 });
105});