| Philip Zeyliger | 99a9a02 | 2025-04-27 15:15:25 +0000 | [diff] [blame] | 1 | import { test, expect } from "@sand4rt/experimental-ct-web"; |
| 2 | import { SketchCallStatus } from "./sketch-call-status"; |
| 3 | |
| 4 | test("initializes with zero LLM calls and empty tool calls by default", async ({ |
| 5 | mount, |
| 6 | }) => { |
| 7 | const component = await mount(SketchCallStatus, {}); |
| 8 | |
| 9 | // Check properties via component's evaluate method |
| 10 | const llmCalls = await component.evaluate( |
| 11 | (el: SketchCallStatus) => el.llmCalls, |
| 12 | ); |
| 13 | expect(llmCalls).toBe(0); |
| 14 | |
| 15 | const toolCalls = await component.evaluate( |
| 16 | (el: SketchCallStatus) => el.toolCalls, |
| 17 | ); |
| 18 | expect(toolCalls).toEqual([]); |
| 19 | |
| 20 | // Check that badges are not shown |
| 21 | await expect(component.locator(".count-badge")).toHaveCount(0); |
| 22 | }); |
| 23 | |
| 24 | test("displays the correct state for active LLM calls", async ({ mount }) => { |
| 25 | const component = await mount(SketchCallStatus, { |
| 26 | props: { |
| 27 | llmCalls: 3, |
| 28 | toolCalls: [], |
| 29 | }, |
| 30 | }); |
| 31 | |
| 32 | // Check that LLM indicator is active |
| 33 | await expect(component.locator(".llm-indicator")).toHaveClass(/active/); |
| 34 | |
| 35 | // Check that badge shows correct count |
| 36 | await expect(component.locator(".llm-indicator .count-badge")).toHaveText( |
| 37 | "3", |
| 38 | ); |
| 39 | |
| 40 | // Check that tool indicator is not active |
| 41 | await expect(component.locator(".tool-indicator")).not.toHaveClass(/active/); |
| 42 | }); |
| 43 | |
| 44 | test("displays the correct state for active tool calls", async ({ mount }) => { |
| 45 | const component = await mount(SketchCallStatus, { |
| 46 | props: { |
| 47 | llmCalls: 0, |
| 48 | toolCalls: ["bash", "think"], |
| 49 | }, |
| 50 | }); |
| 51 | |
| 52 | // Check that tool indicator is active |
| 53 | await expect(component.locator(".tool-indicator")).toHaveClass(/active/); |
| 54 | |
| 55 | // Check that badge shows correct count |
| 56 | await expect(component.locator(".tool-indicator .count-badge")).toHaveText( |
| 57 | "2", |
| 58 | ); |
| 59 | |
| 60 | // Check that LLM indicator is not active |
| 61 | await expect(component.locator(".llm-indicator")).not.toHaveClass(/active/); |
| 62 | }); |
| 63 | |
| 64 | test("displays both indicators when both call types are active", async ({ |
| 65 | mount, |
| 66 | }) => { |
| 67 | const component = await mount(SketchCallStatus, { |
| 68 | props: { |
| 69 | llmCalls: 1, |
| 70 | toolCalls: ["patch"], |
| 71 | }, |
| 72 | }); |
| 73 | |
| 74 | // Check that both indicators are active |
| 75 | await expect(component.locator(".llm-indicator")).toHaveClass(/active/); |
| 76 | await expect(component.locator(".tool-indicator")).toHaveClass(/active/); |
| 77 | |
| 78 | // Check that badges show correct counts |
| 79 | await expect(component.locator(".llm-indicator .count-badge")).toHaveText( |
| 80 | "1", |
| 81 | ); |
| 82 | await expect(component.locator(".tool-indicator .count-badge")).toHaveText( |
| 83 | "1", |
| 84 | ); |
| 85 | }); |
| 86 | |
| 87 | test("has correct tooltip text for LLM calls", async ({ mount }) => { |
| 88 | // Test with singular |
| 89 | let component = await mount(SketchCallStatus, { |
| 90 | props: { |
| 91 | llmCalls: 1, |
| 92 | toolCalls: [], |
| 93 | }, |
| 94 | }); |
| 95 | |
| 96 | await expect(component.locator(".llm-indicator")).toHaveAttribute( |
| 97 | "title", |
| 98 | "1 LLM call in progress", |
| 99 | ); |
| 100 | |
| 101 | await component.unmount(); |
| 102 | |
| 103 | // Test with plural |
| 104 | component = await mount(SketchCallStatus, { |
| 105 | props: { |
| 106 | llmCalls: 2, |
| 107 | toolCalls: [], |
| 108 | }, |
| 109 | }); |
| 110 | |
| 111 | await expect(component.locator(".llm-indicator")).toHaveAttribute( |
| 112 | "title", |
| 113 | "2 LLM calls in progress", |
| 114 | ); |
| 115 | }); |
| 116 | |
| 117 | test("has correct tooltip text for tool calls", async ({ mount }) => { |
| 118 | // Test with singular |
| 119 | let component = await mount(SketchCallStatus, { |
| 120 | props: { |
| 121 | llmCalls: 0, |
| 122 | toolCalls: ["bash"], |
| 123 | }, |
| 124 | }); |
| 125 | |
| 126 | await expect(component.locator(".tool-indicator")).toHaveAttribute( |
| 127 | "title", |
| 128 | "1 tool call in progress: bash", |
| 129 | ); |
| 130 | |
| 131 | await component.unmount(); |
| 132 | |
| 133 | // Test with plural |
| 134 | component = await mount(SketchCallStatus, { |
| 135 | props: { |
| 136 | llmCalls: 0, |
| 137 | toolCalls: ["bash", "think"], |
| 138 | }, |
| 139 | }); |
| 140 | |
| 141 | await expect(component.locator(".tool-indicator")).toHaveAttribute( |
| 142 | "title", |
| 143 | "2 tool calls in progress: bash, think", |
| 144 | ); |
| 145 | }); |