blob: 79cdd8d6125e78bae6647d34f04911ca81ced2dd [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
Sean McCulloughb29f8912025-04-20 15:39:11 -070019test("dispatches view-mode-select event when clicking a mode button", async ({
20 mount,
21}) => {
22 const component = await mount(SketchViewModeSelect, {});
23
24 // Set up promise to wait for the event
25 const eventPromise = component.evaluate((el) => {
26 return new Promise((resolve) => {
27 el.addEventListener(
28 "view-mode-select",
29 (event) => {
30 resolve((event as CustomEvent).detail);
31 },
32 { once: true },
33 );
34 });
Sean McCullough86b56862025-04-18 13:04:03 -070035 });
36
Sean McCulloughb29f8912025-04-20 15:39:11 -070037 // Click the diff button
38 await component.locator("#showDiffButton").click();
Sean McCullough86b56862025-04-18 13:04:03 -070039
Sean McCulloughb29f8912025-04-20 15:39:11 -070040 // Wait for the event and check its details
41 const detail: any = await eventPromise;
42 expect(detail.mode).toBe("diff");
43});
Sean McCullough86b56862025-04-18 13:04:03 -070044
Sean McCulloughb29f8912025-04-20 15:39:11 -070045test("updates the active mode when receiving update-active-mode event", async ({
46 mount,
47}) => {
48 const component = await mount(SketchViewModeSelect, {});
Sean McCullough86b56862025-04-18 13:04:03 -070049
Sean McCulloughb29f8912025-04-20 15:39:11 -070050 // Initially should be in chat mode
51 let activeMode = await component.evaluate(
52 (el: SketchViewModeSelect) => el.activeMode,
53 );
54 expect(activeMode).toBe("chat");
Sean McCullough86b56862025-04-18 13:04:03 -070055
Sean McCulloughb29f8912025-04-20 15:39:11 -070056 // Dispatch the update-active-mode event
57 await component.evaluate((el) => {
Sean McCullough86b56862025-04-18 13:04:03 -070058 const updateEvent = new CustomEvent("update-active-mode", {
59 detail: { mode: "diff" },
Sean McCullough71941bd2025-04-18 13:31:48 -070060 bubbles: true,
Sean McCullough86b56862025-04-18 13:04:03 -070061 });
62 el.dispatchEvent(updateEvent);
Sean McCullough86b56862025-04-18 13:04:03 -070063 });
64
Sean McCulloughb29f8912025-04-20 15:39:11 -070065 // Check that the mode was updated
66 activeMode = await component.evaluate(
67 (el: SketchViewModeSelect) => el.activeMode,
68 );
69 expect(activeMode).toBe("diff");
Sean McCullough86b56862025-04-18 13:04:03 -070070
Sean McCulloughb29f8912025-04-20 15:39:11 -070071 // Check that the diff button is now active
72 await expect(component.locator("#showDiffButton.active")).toBeVisible();
73});
Sean McCullough71941bd2025-04-18 13:31:48 -070074
Sean McCulloughb29f8912025-04-20 15:39:11 -070075test("correctly marks the active button based on mode", async ({ mount }) => {
76 const component = await mount(SketchViewModeSelect, {
77 props: {
78 activeMode: "terminal",
79 },
Sean McCullough86b56862025-04-18 13:04:03 -070080 });
Sean McCulloughb29f8912025-04-20 15:39:11 -070081
82 // Terminal button should be active
83 await expect(component.locator("#showTerminalButton.active")).toBeVisible();
84
85 // Other buttons should not be active
86 await expect(
87 component.locator("#showConversationButton.active"),
88 ).not.toBeVisible();
89 await expect(component.locator("#showDiffButton.active")).not.toBeVisible();
90 await expect(component.locator("#showChartsButton.active")).not.toBeVisible();
Sean McCullough86b56862025-04-18 13:04:03 -070091});