blob: 0b3ae6af024ce3c5a6773253a0949270f2625ee0 [file] [log] [blame]
Pokey Rulee7c9a442025-04-25 20:02:22 +01001import { test, expect } from "@sand4rt/experimental-ct-web";
2import { SketchAppShell } from "./sketch-app-shell";
3import { initialMessages, initialState } from "../fixtures/dummy";
4
5test("renders app shell with mocked API", async ({ page, mount }) => {
6 // Mock the state API response
7 await page.route("**/state", async (route) => {
8 await route.fulfill({ json: initialState });
9 });
10
11 // Mock the messages API response
12 await page.route("**/messages*", async (route) => {
13 const url = new URL(route.request().url());
14 const startIndex = parseInt(url.searchParams.get("start") || "0");
15 await route.fulfill({ json: initialMessages.slice(startIndex) });
16 });
17
18 // Mount the component
19 const component = await mount(SketchAppShell);
20
21 // Wait for initial data to load
22 await page.waitForTimeout(500);
23
24 // Verify the title is displayed correctly
25 await expect(component.locator(".chat-title")).toContainText(
26 initialState.title,
27 );
28
29 // Verify core components are rendered
30 await expect(component.locator("sketch-container-status")).toBeVisible();
31 await expect(component.locator("sketch-timeline")).toBeVisible();
32 await expect(component.locator("sketch-chat-input")).toBeVisible();
33 await expect(component.locator("sketch-view-mode-select")).toBeVisible();
34
35 // Default view should be chat view
36 await expect(component.locator(".chat-view.view-active")).toBeVisible();
37});
38
39const emptyState = {
40 message_count: 0,
41 total_usage: {
42 start_time: "2025-04-25T19:07:24.94241+01:00",
43 messages: 0,
44 input_tokens: 0,
45 output_tokens: 0,
46 cache_read_input_tokens: 0,
47 cache_creation_input_tokens: 0,
48 total_cost_usd: 0,
49 tool_uses: {},
50 },
51 initial_commit: "08e2cf2eaf043df77f8468d90bb21d0083de2132",
52 title: "",
53 hostname: "MacBook-Pro-9.local",
54 working_dir: "/Users/pokey/src/sketch",
55 os: "darwin",
56 git_origin: "git@github.com:boldsoftware/sketch.git",
57 inside_hostname: "MacBook-Pro-9.local",
58 inside_os: "darwin",
59 inside_working_dir: "/Users/pokey/src/sketch",
60};
61
62test("renders app shell with empty state", async ({ page, mount }) => {
63 // Mock the state API response
64 await page.route("**/state", async (route) => {
65 await route.fulfill({ json: emptyState });
66 });
67
68 // Mock the messages API response
69 await page.route("**/messages*", async (route) => {
70 await route.fulfill({ json: [] });
71 });
72
73 // Mount the component
74 const component = await mount(SketchAppShell);
75
76 // Wait for initial data to load
77 await page.waitForTimeout(500);
78
79 // Verify the title is displayed correctly
80 await expect(component.locator(".chat-title")).toContainText(
81 emptyState.title,
82 );
83
84 // Verify core components are rendered
85 await expect(component.locator("sketch-container-status")).toBeVisible();
86 await expect(component.locator("sketch-chat-input")).toBeVisible();
87 await expect(component.locator("sketch-view-mode-select")).toBeVisible();
Pokey Rulee7c9a442025-04-25 20:02:22 +010088});