blob: beb0b6710eb7a785bd0bd8a72b50ae4620692e7e [file] [log] [blame]
Sean McCullough86b56862025-04-18 13:04:03 -07001import { html, fixture, expect, oneEvent, elementUpdated, fixtureCleanup } from "@open-wc/testing";
2import "./sketch-view-mode-select";
3import type { SketchViewModeSelect } from "./sketch-view-mode-select";
4
5describe("SketchViewModeSelect", () => {
6 afterEach(() => {
7 fixtureCleanup();
8 });
9
10 it("initializes with 'chat' as the default mode", async () => {
11 const el: SketchViewModeSelect = await fixture(html`
12 <sketch-view-mode-select></sketch-view-mode-select>
13 `);
14
15 expect(el.activeMode).to.equal("chat");
16 const chatButton = el.shadowRoot!.querySelector("#showConversationButton");
17 expect(chatButton!.classList.contains("active")).to.be.true;
18 });
19
20 it("displays all four view mode buttons", async () => {
21 const el: SketchViewModeSelect = await fixture(html`
22 <sketch-view-mode-select></sketch-view-mode-select>
23 `);
24
25 const buttons = el.shadowRoot!.querySelectorAll(".emoji-button");
26 expect(buttons.length).to.equal(4);
27
28 const chatButton = el.shadowRoot!.querySelector("#showConversationButton");
29 const diffButton = el.shadowRoot!.querySelector("#showDiffButton");
30 const chartsButton = el.shadowRoot!.querySelector("#showChartsButton");
31 const terminalButton = el.shadowRoot!.querySelector("#showTerminalButton");
32
33 expect(chatButton).to.exist;
34 expect(diffButton).to.exist;
35 expect(chartsButton).to.exist;
36 expect(terminalButton).to.exist;
37
38 expect(chatButton!.getAttribute("title")).to.equal("Conversation View");
39 expect(diffButton!.getAttribute("title")).to.equal("Diff View");
40 expect(chartsButton!.getAttribute("title")).to.equal("Charts View");
41 expect(terminalButton!.getAttribute("title")).to.equal("Terminal View");
42 });
43
44 it("dispatches view-mode-select event when clicking a mode button", async () => {
45 const el: SketchViewModeSelect = await fixture(html`
46 <sketch-view-mode-select></sketch-view-mode-select>
47 `);
48
49 const diffButton = el.shadowRoot!.querySelector("#showDiffButton") as HTMLButtonElement;
50
51 // Setup listener for the view-mode-select event
52 setTimeout(() => diffButton.click());
53 const { detail } = await oneEvent(el, "view-mode-select");
54
55 expect(detail.mode).to.equal("diff");
56 });
57
58 it("updates the active mode when receiving update-active-mode event", async () => {
59 const el: SketchViewModeSelect = await fixture(html`
60 <sketch-view-mode-select></sketch-view-mode-select>
61 `);
62
63 // Initially should be in chat mode
64 expect(el.activeMode).to.equal("chat");
65
66 // Dispatch the update-active-mode event to change to diff mode
67 const updateEvent = new CustomEvent("update-active-mode", {
68 detail: { mode: "diff" },
69 bubbles: true
70 });
71 el.dispatchEvent(updateEvent);
72
73 // Wait for the component to update
74 await elementUpdated(el);
75
76 expect(el.activeMode).to.equal("diff");
77 const diffButton = el.shadowRoot!.querySelector("#showDiffButton");
78 expect(diffButton!.classList.contains("active")).to.be.true;
79 });
80
81 it("correctly marks the active button based on mode", async () => {
82 const el: SketchViewModeSelect = await fixture(html`
83 <sketch-view-mode-select activeMode="terminal"></sketch-view-mode-select>
84 `);
85
86 // Terminal button should be active
87 const terminalButton = el.shadowRoot!.querySelector("#showTerminalButton");
88 const chatButton = el.shadowRoot!.querySelector("#showConversationButton");
89 const diffButton = el.shadowRoot!.querySelector("#showDiffButton");
90 const chartsButton = el.shadowRoot!.querySelector("#showChartsButton");
91
92 expect(terminalButton!.classList.contains("active")).to.be.true;
93 expect(chatButton!.classList.contains("active")).to.be.false;
94 expect(diffButton!.classList.contains("active")).to.be.false;
95 expect(chartsButton!.classList.contains("active")).to.be.false;
96 });
97
98
99});