| philip.zeyliger | 26bc659 | 2025-06-30 20:15:30 -0700 | [diff] [blame] | 1 | /* eslint-disable @typescript-eslint/no-explicit-any */ |
| Sean McCullough | b29f891 | 2025-04-20 15:39:11 -0700 | [diff] [blame] | 2 | import { test, expect } from "@sand4rt/experimental-ct-web"; |
| 3 | import { SketchViewModeSelect } from "./sketch-view-mode-select"; |
| Sean McCullough | 86b5686 | 2025-04-18 13:04:03 -0700 | [diff] [blame] | 4 | |
| Sean McCullough | b29f891 | 2025-04-20 15:39:11 -0700 | [diff] [blame] | 5 | test("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 | |
| banksean | d5c849d | 2025-06-26 15:48:31 +0000 | [diff] [blame] | 14 | // 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 McCullough | b29f891 | 2025-04-20 15:39:11 -0700 | [diff] [blame] | 18 | }); |
| 19 | |
| Sean McCullough | b29f891 | 2025-04-20 15:39:11 -0700 | [diff] [blame] | 20 | test("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 McCullough | 86b5686 | 2025-04-18 13:04:03 -0700 | [diff] [blame] | 36 | }); |
| 37 | |
| Sean McCullough | b29f891 | 2025-04-20 15:39:11 -0700 | [diff] [blame] | 38 | // Click the diff button |
| Philip Zeyliger | 272a90e | 2025-05-16 14:49:51 -0700 | [diff] [blame] | 39 | await component.locator("#showDiff2Button").click(); |
| Sean McCullough | 86b5686 | 2025-04-18 13:04:03 -0700 | [diff] [blame] | 40 | |
| Sean McCullough | b29f891 | 2025-04-20 15:39:11 -0700 | [diff] [blame] | 41 | // Wait for the event and check its details |
| 42 | const detail: any = await eventPromise; |
| Philip Zeyliger | 272a90e | 2025-05-16 14:49:51 -0700 | [diff] [blame] | 43 | expect(detail.mode).toBe("diff2"); |
| Sean McCullough | b29f891 | 2025-04-20 15:39:11 -0700 | [diff] [blame] | 44 | }); |
| Sean McCullough | 86b5686 | 2025-04-18 13:04:03 -0700 | [diff] [blame] | 45 | |
| Sean McCullough | b29f891 | 2025-04-20 15:39:11 -0700 | [diff] [blame] | 46 | test("updates the active mode when receiving update-active-mode event", async ({ |
| 47 | mount, |
| 48 | }) => { |
| 49 | const component = await mount(SketchViewModeSelect, {}); |
| Sean McCullough | 86b5686 | 2025-04-18 13:04:03 -0700 | [diff] [blame] | 50 | |
| Sean McCullough | b29f891 | 2025-04-20 15:39:11 -0700 | [diff] [blame] | 51 | // Initially should be in chat mode |
| 52 | let activeMode = await component.evaluate( |
| 53 | (el: SketchViewModeSelect) => el.activeMode, |
| 54 | ); |
| 55 | expect(activeMode).toBe("chat"); |
| Sean McCullough | 86b5686 | 2025-04-18 13:04:03 -0700 | [diff] [blame] | 56 | |
| Sean McCullough | b29f891 | 2025-04-20 15:39:11 -0700 | [diff] [blame] | 57 | // Dispatch the update-active-mode event |
| 58 | await component.evaluate((el) => { |
| Sean McCullough | 86b5686 | 2025-04-18 13:04:03 -0700 | [diff] [blame] | 59 | const updateEvent = new CustomEvent("update-active-mode", { |
| Philip Zeyliger | 272a90e | 2025-05-16 14:49:51 -0700 | [diff] [blame] | 60 | detail: { mode: "diff2" }, |
| Sean McCullough | 71941bd | 2025-04-18 13:31:48 -0700 | [diff] [blame] | 61 | bubbles: true, |
| Sean McCullough | 86b5686 | 2025-04-18 13:04:03 -0700 | [diff] [blame] | 62 | }); |
| 63 | el.dispatchEvent(updateEvent); |
| Sean McCullough | 86b5686 | 2025-04-18 13:04:03 -0700 | [diff] [blame] | 64 | }); |
| 65 | |
| Sean McCullough | b29f891 | 2025-04-20 15:39:11 -0700 | [diff] [blame] | 66 | // Check that the mode was updated |
| 67 | activeMode = await component.evaluate( |
| 68 | (el: SketchViewModeSelect) => el.activeMode, |
| 69 | ); |
| Philip Zeyliger | 272a90e | 2025-05-16 14:49:51 -0700 | [diff] [blame] | 70 | expect(activeMode).toBe("diff2"); |
| Sean McCullough | 86b5686 | 2025-04-18 13:04:03 -0700 | [diff] [blame] | 71 | |
| banksean | d5c849d | 2025-06-26 15:48:31 +0000 | [diff] [blame] | 72 | // 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 McCullough | b29f891 | 2025-04-20 15:39:11 -0700 | [diff] [blame] | 76 | }); |
| Sean McCullough | 71941bd | 2025-04-18 13:31:48 -0700 | [diff] [blame] | 77 | |
| Sean McCullough | b29f891 | 2025-04-20 15:39:11 -0700 | [diff] [blame] | 78 | test("correctly marks the active button based on mode", async ({ mount }) => { |
| 79 | const component = await mount(SketchViewModeSelect, { |
| 80 | props: { |
| 81 | activeMode: "terminal", |
| 82 | }, |
| Sean McCullough | 86b5686 | 2025-04-18 13:04:03 -0700 | [diff] [blame] | 83 | }); |
| Sean McCullough | b29f891 | 2025-04-20 15:39:11 -0700 | [diff] [blame] | 84 | |
| banksean | d5c849d | 2025-06-26 15:48:31 +0000 | [diff] [blame] | 85 | // Terminal button should be active (has dark blue border) |
| 86 | await expect(component.locator("#showTerminalButton")).toHaveClass( |
| 87 | /border-b-blue-600/, |
| 88 | ); |
| Sean McCullough | b29f891 | 2025-04-20 15:39:11 -0700 | [diff] [blame] | 89 | |
| banksean | d5c849d | 2025-06-26 15:48:31 +0000 | [diff] [blame] | 90 | // 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 McCullough | 86b5686 | 2025-04-18 13:04:03 -0700 | [diff] [blame] | 97 | }); |