blob: 6db790be6ca38e9edd304b241b49d4f3ccb0bb70 [file] [log] [blame]
Sean McCulloughb29f8912025-04-20 15:39:11 -07001import { test, expect } from "@sand4rt/experimental-ct-web";
2import { SketchViewModeSelect } from "./sketch-view-mode-select";
Sean McCullough86b56862025-04-18 13:04:03 -07003
Sean McCulloughb29f8912025-04-20 15:39:11 -07004test("initializes with 'chat' as the default mode", async ({ mount }) => {
5 const component = await mount(SketchViewModeSelect, {});
6
7 // Check the activeMode property
8 const activeMode = await component.evaluate(
9 (el: SketchViewModeSelect) => el.activeMode,
10 );
11 expect(activeMode).toBe("chat");
12
13 // Check that the chat button has the active class
14 await expect(
15 component.locator("#showConversationButton.active"),
16 ).toBeVisible();
17});
18
19test("displays all four view mode buttons", async ({ mount }) => {
20 const component = await mount(SketchViewModeSelect, {});
21
22 // Count the number of buttons
23 const buttonCount = await component.locator(".emoji-button").count();
24 expect(buttonCount).toBe(4);
25
26 // Check that each button exists
27 await expect(component.locator("#showConversationButton")).toBeVisible();
28 await expect(component.locator("#showDiffButton")).toBeVisible();
29 await expect(component.locator("#showChartsButton")).toBeVisible();
30 await expect(component.locator("#showTerminalButton")).toBeVisible();
31
32 // Check the title attributes
33 expect(
34 await component.locator("#showConversationButton").getAttribute("title"),
35 ).toBe("Conversation View");
36 expect(await component.locator("#showDiffButton").getAttribute("title")).toBe(
37 "Diff View",
38 );
39 expect(
40 await component.locator("#showChartsButton").getAttribute("title"),
41 ).toBe("Charts View");
42 expect(
43 await component.locator("#showTerminalButton").getAttribute("title"),
44 ).toBe("Terminal View");
45});
46
47test("dispatches view-mode-select event when clicking a mode button", async ({
48 mount,
49}) => {
50 const component = await mount(SketchViewModeSelect, {});
51
52 // Set up promise to wait for the event
53 const eventPromise = component.evaluate((el) => {
54 return new Promise((resolve) => {
55 el.addEventListener(
56 "view-mode-select",
57 (event) => {
58 resolve((event as CustomEvent).detail);
59 },
60 { once: true },
61 );
62 });
Sean McCullough86b56862025-04-18 13:04:03 -070063 });
64
Sean McCulloughb29f8912025-04-20 15:39:11 -070065 // Click the diff button
66 await component.locator("#showDiffButton").click();
Sean McCullough86b56862025-04-18 13:04:03 -070067
Sean McCulloughb29f8912025-04-20 15:39:11 -070068 // Wait for the event and check its details
69 const detail: any = await eventPromise;
70 expect(detail.mode).toBe("diff");
71});
Sean McCullough86b56862025-04-18 13:04:03 -070072
Sean McCulloughb29f8912025-04-20 15:39:11 -070073test("updates the active mode when receiving update-active-mode event", async ({
74 mount,
75}) => {
76 const component = await mount(SketchViewModeSelect, {});
Sean McCullough86b56862025-04-18 13:04:03 -070077
Sean McCulloughb29f8912025-04-20 15:39:11 -070078 // Initially should be in chat mode
79 let activeMode = await component.evaluate(
80 (el: SketchViewModeSelect) => el.activeMode,
81 );
82 expect(activeMode).toBe("chat");
Sean McCullough86b56862025-04-18 13:04:03 -070083
Sean McCulloughb29f8912025-04-20 15:39:11 -070084 // Dispatch the update-active-mode event
85 await component.evaluate((el) => {
Sean McCullough86b56862025-04-18 13:04:03 -070086 const updateEvent = new CustomEvent("update-active-mode", {
87 detail: { mode: "diff" },
Sean McCullough71941bd2025-04-18 13:31:48 -070088 bubbles: true,
Sean McCullough86b56862025-04-18 13:04:03 -070089 });
90 el.dispatchEvent(updateEvent);
Sean McCullough86b56862025-04-18 13:04:03 -070091 });
92
Sean McCulloughb29f8912025-04-20 15:39:11 -070093 // Check that the mode was updated
94 activeMode = await component.evaluate(
95 (el: SketchViewModeSelect) => el.activeMode,
96 );
97 expect(activeMode).toBe("diff");
Sean McCullough86b56862025-04-18 13:04:03 -070098
Sean McCulloughb29f8912025-04-20 15:39:11 -070099 // Check that the diff button is now active
100 await expect(component.locator("#showDiffButton.active")).toBeVisible();
101});
Sean McCullough71941bd2025-04-18 13:31:48 -0700102
Sean McCulloughb29f8912025-04-20 15:39:11 -0700103test("correctly marks the active button based on mode", async ({ mount }) => {
104 const component = await mount(SketchViewModeSelect, {
105 props: {
106 activeMode: "terminal",
107 },
Sean McCullough86b56862025-04-18 13:04:03 -0700108 });
Sean McCulloughb29f8912025-04-20 15:39:11 -0700109
110 // Terminal button should be active
111 await expect(component.locator("#showTerminalButton.active")).toBeVisible();
112
113 // Other buttons should not be active
114 await expect(
115 component.locator("#showConversationButton.active"),
116 ).not.toBeVisible();
117 await expect(component.locator("#showDiffButton.active")).not.toBeVisible();
118 await expect(component.locator("#showChartsButton.active")).not.toBeVisible();
Sean McCullough86b56862025-04-18 13:04:03 -0700119});