| 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 | |
| 13 | // Check that the chat button has the active class |
| 14 | await expect( |
| 15 | component.locator("#showConversationButton.active"), |
| 16 | ).toBeVisible(); |
| 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 | |
| Sean McCullough | b29f891 | 2025-04-20 15:39:11 -0700 | [diff] [blame] | 71 | // Check that the diff button is now active |
| Philip Zeyliger | 272a90e | 2025-05-16 14:49:51 -0700 | [diff] [blame] | 72 | await expect(component.locator("#showDiff2Button.active")).toBeVisible(); |
| Sean McCullough | b29f891 | 2025-04-20 15:39:11 -0700 | [diff] [blame] | 73 | }); |
| Sean McCullough | 71941bd | 2025-04-18 13:31:48 -0700 | [diff] [blame] | 74 | |
| Sean McCullough | b29f891 | 2025-04-20 15:39:11 -0700 | [diff] [blame] | 75 | test("correctly marks the active button based on mode", async ({ mount }) => { |
| 76 | const component = await mount(SketchViewModeSelect, { |
| 77 | props: { |
| 78 | activeMode: "terminal", |
| 79 | }, |
| Sean McCullough | 86b5686 | 2025-04-18 13:04:03 -0700 | [diff] [blame] | 80 | }); |
| Sean McCullough | b29f891 | 2025-04-20 15:39:11 -0700 | [diff] [blame] | 81 | |
| 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(); |
| Philip Zeyliger | 272a90e | 2025-05-16 14:49:51 -0700 | [diff] [blame] | 89 | await expect(component.locator("#showDiff2Button.active")).not.toBeVisible(); |
| Sean McCullough | b29f891 | 2025-04-20 15:39:11 -0700 | [diff] [blame] | 90 | await expect(component.locator("#showChartsButton.active")).not.toBeVisible(); |
| Sean McCullough | 86b5686 | 2025-04-18 13:04:03 -0700 | [diff] [blame] | 91 | }); |