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