blob: 3862393c652898822da78b175baf1865b15f3cc1 [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
bankseand5c849d2025-06-26 15:48:31 +000013 // Check that the chat button has the active styling (dark blue border indicates active)
14 await expect(component.locator("#showConversationButton")).toHaveClass(
15 /border-b-blue-600/,
16 );
Sean McCulloughb29f8912025-04-20 15:39:11 -070017});
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
Philip Zeyliger272a90e2025-05-16 14:49:51 -070038 await component.locator("#showDiff2Button").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;
Philip Zeyliger272a90e2025-05-16 14:49:51 -070042 expect(detail.mode).toBe("diff2");
Sean McCulloughb29f8912025-04-20 15:39:11 -070043});
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", {
Philip Zeyliger272a90e2025-05-16 14:49:51 -070059 detail: { mode: "diff2" },
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 );
Philip Zeyliger272a90e2025-05-16 14:49:51 -070069 expect(activeMode).toBe("diff2");
Sean McCullough86b56862025-04-18 13:04:03 -070070
bankseand5c849d2025-06-26 15:48:31 +000071 // Check that the diff button is now active (has dark blue border)
72 await expect(component.locator("#showDiff2Button")).toHaveClass(
73 /border-b-blue-600/,
74 );
Sean McCulloughb29f8912025-04-20 15:39:11 -070075});
Sean McCullough71941bd2025-04-18 13:31:48 -070076
Sean McCulloughb29f8912025-04-20 15:39:11 -070077test("correctly marks the active button based on mode", async ({ mount }) => {
78 const component = await mount(SketchViewModeSelect, {
79 props: {
80 activeMode: "terminal",
81 },
Sean McCullough86b56862025-04-18 13:04:03 -070082 });
Sean McCulloughb29f8912025-04-20 15:39:11 -070083
bankseand5c849d2025-06-26 15:48:31 +000084 // Terminal button should be active (has dark blue border)
85 await expect(component.locator("#showTerminalButton")).toHaveClass(
86 /border-b-blue-600/,
87 );
Sean McCulloughb29f8912025-04-20 15:39:11 -070088
bankseand5c849d2025-06-26 15:48:31 +000089 // Other buttons should not be active (should not have dark blue border)
90 await expect(component.locator("#showConversationButton")).not.toHaveClass(
91 /border-b-blue-600/,
92 );
93 await expect(component.locator("#showDiff2Button")).not.toHaveClass(
94 /border-b-blue-600/,
95 );
Sean McCullough86b56862025-04-18 13:04:03 -070096});