Skip to content

Commit 7316d40

Browse files
committed
fix boot waits in e2e and test stall screen
1 parent 44f6cc4 commit 7316d40

3 files changed

Lines changed: 83 additions & 2 deletions

File tree

apps/code/tests/e2e/tests/smoke.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ test.describe("Smoke Tests", () => {
1616
await window.waitForSelector("#root > *", { timeout: 30000 });
1717

1818
await window
19-
.locator("text=Loading")
19+
.locator('[data-testid="app-loading-logo"]')
2020
.waitFor({ state: "hidden", timeout: 30000 })
2121
.catch(() => {});
2222

apps/code/tests/e2e/tests/visual.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ test.describe("Visual Stability", () => {
77
}) => {
88
await window.waitForSelector("#root > *", { timeout: 30000 });
99
await window
10-
.locator("text=Loading")
10+
.locator('[data-testid="app-loading-logo"]')
1111
.waitFor({ state: "hidden", timeout: 30000 })
1212
.catch(() => {});
1313

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
import { Theme } from "@radix-ui/themes";
2+
import { act, render, screen } from "@testing-library/react";
3+
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
4+
import { AppLoadingScreen } from "./AppLoadingScreen";
5+
6+
vi.mock("@posthog/ui/shell/openExternal", () => ({
7+
openExternalUrl: vi.fn(),
8+
}));
9+
10+
import { openExternalUrl } from "@posthog/ui/shell/openExternal";
11+
12+
const STALL_TIMEOUT_MS = 30_000;
13+
14+
function renderScreen() {
15+
return render(
16+
<Theme>
17+
<AppLoadingScreen />
18+
</Theme>,
19+
);
20+
}
21+
22+
describe("AppLoadingScreen", () => {
23+
beforeEach(() => {
24+
vi.useFakeTimers();
25+
});
26+
27+
afterEach(() => {
28+
vi.useRealTimers();
29+
vi.clearAllMocks();
30+
});
31+
32+
it("renders the loading logo immediately", () => {
33+
renderScreen();
34+
expect(screen.getByTestId("app-loading-logo")).toBeInTheDocument();
35+
expect(
36+
screen.queryByText("PostHog is taking longer than expected to start"),
37+
).not.toBeInTheDocument();
38+
});
39+
40+
it("keeps the logo until just before the stall timeout", () => {
41+
renderScreen();
42+
act(() => {
43+
vi.advanceTimersByTime(STALL_TIMEOUT_MS - 1);
44+
});
45+
expect(screen.getByTestId("app-loading-logo")).toBeInTheDocument();
46+
});
47+
48+
it("swaps to the stalled screen after the timeout", () => {
49+
renderScreen();
50+
act(() => {
51+
vi.advanceTimersByTime(STALL_TIMEOUT_MS);
52+
});
53+
expect(
54+
screen.getByText("PostHog is taking longer than expected to start"),
55+
).toBeInTheDocument();
56+
expect(screen.getByRole("button", { name: "Retry" })).toBeInTheDocument();
57+
expect(
58+
screen.getByRole("button", { name: "Get support" }),
59+
).toBeInTheDocument();
60+
expect(screen.queryByTestId("app-loading-logo")).not.toBeInTheDocument();
61+
});
62+
63+
it("clears the stall timer on unmount", () => {
64+
const { unmount } = renderScreen();
65+
unmount();
66+
expect(() => {
67+
vi.advanceTimersByTime(STALL_TIMEOUT_MS);
68+
}).not.toThrow();
69+
});
70+
71+
it("opens the support link from the stalled screen", () => {
72+
renderScreen();
73+
act(() => {
74+
vi.advanceTimersByTime(STALL_TIMEOUT_MS);
75+
});
76+
screen.getByRole("button", { name: "Get support" }).click();
77+
expect(openExternalUrl).toHaveBeenCalledWith(
78+
expect.stringContaining("discord"),
79+
);
80+
});
81+
});

0 commit comments

Comments
 (0)