blob: da4d10cd5d51dbbb9e368f26ee7bca4e22ca85d9 [file] [log] [blame]
philip.zeyliger26bc6592025-06-30 20:15:30 -07001/* eslint-disable @typescript-eslint/no-explicit-any */
Sean McCulloughb29f8912025-04-20 15:39:11 -07002import { test, expect } from "@sand4rt/experimental-ct-web";
3import { SketchViewModeSelect } from "./sketch-view-mode-select";
Sean McCullough86b56862025-04-18 13:04:03 -07004
Sean McCulloughb29f8912025-04-20 15:39:11 -07005test("initializes with 'chat' as the default mode", async ({ mount }) => {
6 const component = await mount(SketchViewModeSelect, {});
7
8 // Check the activeMode property
9 const activeMode = await component.evaluate(
10 (el: SketchViewModeSelect) => el.activeMode,
11 );
12 expect(activeMode).toBe("chat");
13
bankseand5c849d2025-06-26 15:48:31 +000014 // Check that the chat button has the active styling (dark blue border indicates active)
15 await expect(component.locator("#showConversationButton")).toHaveClass(
16 /border-b-blue-600/,
17 );
Sean McCulloughb29f8912025-04-20 15:39:11 -070018});
19
Sean McCulloughb29f8912025-04-20 15:39:11 -070020test("dispatches view-mode-select event when clicking a mode button", async ({
21 mount,
22}) => {
23 const component = await mount(SketchViewModeSelect, {});
24
25 // Set up promise to wait for the event
26 const eventPromise = component.evaluate((el) => {
27 return new Promise((resolve) => {
28 el.addEventListener(
29 "view-mode-select",
30 (event) => {
31 resolve((event as CustomEvent).detail);
32 },
33 { once: true },
34 );
35 });
Sean McCullough86b56862025-04-18 13:04:03 -070036 });
37
Sean McCulloughb29f8912025-04-20 15:39:11 -070038 // Click the diff button
Philip Zeyliger272a90e2025-05-16 14:49:51 -070039 await component.locator("#showDiff2Button").click();
Sean McCullough86b56862025-04-18 13:04:03 -070040
Sean McCulloughb29f8912025-04-20 15:39:11 -070041 // Wait for the event and check its details
42 const detail: any = await eventPromise;
Philip Zeyliger272a90e2025-05-16 14:49:51 -070043 expect(detail.mode).toBe("diff2");
Sean McCulloughb29f8912025-04-20 15:39:11 -070044});
Sean McCullough86b56862025-04-18 13:04:03 -070045
Sean McCulloughb29f8912025-04-20 15:39:11 -070046test("updates the active mode when receiving update-active-mode event", async ({
47 mount,
48}) => {
49 const component = await mount(SketchViewModeSelect, {});
Sean McCullough86b56862025-04-18 13:04:03 -070050
Sean McCulloughb29f8912025-04-20 15:39:11 -070051 // Initially should be in chat mode
52 let activeMode = await component.evaluate(
53 (el: SketchViewModeSelect) => el.activeMode,
54 );
55 expect(activeMode).toBe("chat");
Sean McCullough86b56862025-04-18 13:04:03 -070056
Sean McCulloughb29f8912025-04-20 15:39:11 -070057 // Dispatch the update-active-mode event
58 await component.evaluate((el) => {
Sean McCullough86b56862025-04-18 13:04:03 -070059 const updateEvent = new CustomEvent("update-active-mode", {
Philip Zeyliger272a90e2025-05-16 14:49:51 -070060 detail: { mode: "diff2" },
Sean McCullough71941bd2025-04-18 13:31:48 -070061 bubbles: true,
Sean McCullough86b56862025-04-18 13:04:03 -070062 });
63 el.dispatchEvent(updateEvent);
Sean McCullough86b56862025-04-18 13:04:03 -070064 });
65
Sean McCulloughb29f8912025-04-20 15:39:11 -070066 // Check that the mode was updated
67 activeMode = await component.evaluate(
68 (el: SketchViewModeSelect) => el.activeMode,
69 );
Philip Zeyliger272a90e2025-05-16 14:49:51 -070070 expect(activeMode).toBe("diff2");
Sean McCullough86b56862025-04-18 13:04:03 -070071
bankseand5c849d2025-06-26 15:48:31 +000072 // Check that the diff button is now active (has dark blue border)
73 await expect(component.locator("#showDiff2Button")).toHaveClass(
74 /border-b-blue-600/,
75 );
Sean McCulloughb29f8912025-04-20 15:39:11 -070076});
Sean McCullough71941bd2025-04-18 13:31:48 -070077
Sean McCulloughb29f8912025-04-20 15:39:11 -070078test("correctly marks the active button based on mode", async ({ mount }) => {
79 const component = await mount(SketchViewModeSelect, {
80 props: {
81 activeMode: "terminal",
82 },
Sean McCullough86b56862025-04-18 13:04:03 -070083 });
Sean McCulloughb29f8912025-04-20 15:39:11 -070084
bankseand5c849d2025-06-26 15:48:31 +000085 // Terminal button should be active (has dark blue border)
86 await expect(component.locator("#showTerminalButton")).toHaveClass(
87 /border-b-blue-600/,
88 );
Sean McCulloughb29f8912025-04-20 15:39:11 -070089
bankseand5c849d2025-06-26 15:48:31 +000090 // Other buttons should not be active (should not have dark blue border)
91 await expect(component.locator("#showConversationButton")).not.toHaveClass(
92 /border-b-blue-600/,
93 );
94 await expect(component.locator("#showDiff2Button")).not.toHaveClass(
95 /border-b-blue-600/,
96 );
Sean McCullough86b56862025-04-18 13:04:03 -070097});