| 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 | |
| Philip Zeyliger | c2b6bdf | 2025-04-29 11:17:47 -0700 | [diff] [blame] | 20 | // Check that indicators are not active |
| 21 | await expect(component.locator(".llm-indicator")).not.toHaveClass(/active/); |
| 22 | await expect(component.locator(".tool-indicator")).not.toHaveClass(/active/); |
| Philip Zeyliger | 99a9a02 | 2025-04-27 15:15:25 +0000 | [diff] [blame] | 23 | }); |
| 24 | |
| 25 | test("displays the correct state for active LLM calls", async ({ mount }) => { |
| 26 | const component = await mount(SketchCallStatus, { |
| 27 | props: { |
| 28 | llmCalls: 3, |
| 29 | toolCalls: [], |
| 30 | }, |
| 31 | }); |
| 32 | |
| 33 | // Check that LLM indicator is active |
| 34 | await expect(component.locator(".llm-indicator")).toHaveClass(/active/); |
| Autoformatter | 570c3f8 | 2025-04-29 18:26:50 +0000 | [diff] [blame] | 35 | |
| Philip Zeyliger | c2b6bdf | 2025-04-29 11:17:47 -0700 | [diff] [blame] | 36 | // Check that LLM indicator has the correct background and color |
| 37 | await expect(component.locator(".llm-indicator.active")).toBeVisible(); |
| Philip Zeyliger | 99a9a02 | 2025-04-27 15:15:25 +0000 | [diff] [blame] | 38 | |
| 39 | // Check that tool indicator is not active |
| 40 | await expect(component.locator(".tool-indicator")).not.toHaveClass(/active/); |
| 41 | }); |
| 42 | |
| 43 | test("displays the correct state for active tool calls", async ({ mount }) => { |
| 44 | const component = await mount(SketchCallStatus, { |
| 45 | props: { |
| 46 | llmCalls: 0, |
| 47 | toolCalls: ["bash", "think"], |
| 48 | }, |
| 49 | }); |
| 50 | |
| 51 | // Check that tool indicator is active |
| 52 | await expect(component.locator(".tool-indicator")).toHaveClass(/active/); |
| Autoformatter | 570c3f8 | 2025-04-29 18:26:50 +0000 | [diff] [blame] | 53 | |
| Philip Zeyliger | c2b6bdf | 2025-04-29 11:17:47 -0700 | [diff] [blame] | 54 | // Check that tool indicator has the correct background and color |
| 55 | await expect(component.locator(".tool-indicator.active")).toBeVisible(); |
| Philip Zeyliger | 99a9a02 | 2025-04-27 15:15:25 +0000 | [diff] [blame] | 56 | |
| 57 | // Check that LLM indicator is not active |
| 58 | await expect(component.locator(".llm-indicator")).not.toHaveClass(/active/); |
| 59 | }); |
| 60 | |
| 61 | test("displays both indicators when both call types are active", async ({ |
| 62 | mount, |
| 63 | }) => { |
| 64 | const component = await mount(SketchCallStatus, { |
| 65 | props: { |
| 66 | llmCalls: 1, |
| 67 | toolCalls: ["patch"], |
| 68 | }, |
| 69 | }); |
| 70 | |
| 71 | // Check that both indicators are active |
| 72 | await expect(component.locator(".llm-indicator")).toHaveClass(/active/); |
| 73 | await expect(component.locator(".tool-indicator")).toHaveClass(/active/); |
| Autoformatter | 570c3f8 | 2025-04-29 18:26:50 +0000 | [diff] [blame] | 74 | |
| Philip Zeyliger | c2b6bdf | 2025-04-29 11:17:47 -0700 | [diff] [blame] | 75 | // Check that both active indicators are visible with their respective styles |
| 76 | await expect(component.locator(".llm-indicator.active")).toBeVisible(); |
| 77 | await expect(component.locator(".tool-indicator.active")).toBeVisible(); |
| Philip Zeyliger | 99a9a02 | 2025-04-27 15:15:25 +0000 | [diff] [blame] | 78 | }); |
| 79 | |
| 80 | test("has correct tooltip text for LLM calls", async ({ mount }) => { |
| 81 | // Test with singular |
| 82 | let component = await mount(SketchCallStatus, { |
| 83 | props: { |
| 84 | llmCalls: 1, |
| 85 | toolCalls: [], |
| 86 | }, |
| 87 | }); |
| 88 | |
| 89 | await expect(component.locator(".llm-indicator")).toHaveAttribute( |
| 90 | "title", |
| 91 | "1 LLM call in progress", |
| 92 | ); |
| 93 | |
| 94 | await component.unmount(); |
| 95 | |
| 96 | // Test with plural |
| 97 | component = await mount(SketchCallStatus, { |
| 98 | props: { |
| 99 | llmCalls: 2, |
| 100 | toolCalls: [], |
| 101 | }, |
| 102 | }); |
| 103 | |
| 104 | await expect(component.locator(".llm-indicator")).toHaveAttribute( |
| 105 | "title", |
| 106 | "2 LLM calls in progress", |
| 107 | ); |
| 108 | }); |
| 109 | |
| 110 | test("has correct tooltip text for tool calls", async ({ mount }) => { |
| 111 | // Test with singular |
| 112 | let component = await mount(SketchCallStatus, { |
| 113 | props: { |
| 114 | llmCalls: 0, |
| 115 | toolCalls: ["bash"], |
| 116 | }, |
| 117 | }); |
| 118 | |
| 119 | await expect(component.locator(".tool-indicator")).toHaveAttribute( |
| 120 | "title", |
| 121 | "1 tool call in progress: bash", |
| 122 | ); |
| 123 | |
| 124 | await component.unmount(); |
| 125 | |
| 126 | // Test with plural |
| 127 | component = await mount(SketchCallStatus, { |
| 128 | props: { |
| 129 | llmCalls: 0, |
| 130 | toolCalls: ["bash", "think"], |
| 131 | }, |
| 132 | }); |
| 133 | |
| 134 | await expect(component.locator(".tool-indicator")).toHaveAttribute( |
| 135 | "title", |
| 136 | "2 tool calls in progress: bash, think", |
| 137 | ); |
| 138 | }); |
| Philip Zeyliger | 5e35702 | 2025-05-16 04:50:34 +0000 | [diff] [blame] | 139 | |
| Autoformatter | 8c46362 | 2025-05-16 21:54:17 +0000 | [diff] [blame] | 140 | test("displays IDLE status when isIdle is true and not disconnected", async ({ |
| 141 | mount, |
| 142 | }) => { |
| Philip Zeyliger | 5e35702 | 2025-05-16 04:50:34 +0000 | [diff] [blame] | 143 | const component = await mount(SketchCallStatus, { |
| 144 | props: { |
| 145 | isIdle: true, |
| 146 | isDisconnected: false, |
| 147 | llmCalls: 0, |
| 148 | toolCalls: [], |
| 149 | }, |
| 150 | }); |
| 151 | |
| 152 | // Check that the status banner has the correct class and text |
| 153 | await expect(component.locator(".status-banner")).toHaveClass(/status-idle/); |
| 154 | await expect(component.locator(".status-banner")).toHaveText("IDLE"); |
| 155 | }); |
| 156 | |
| Autoformatter | 8c46362 | 2025-05-16 21:54:17 +0000 | [diff] [blame] | 157 | test("displays WORKING status when isIdle is false and not disconnected", async ({ |
| 158 | mount, |
| 159 | }) => { |
| Philip Zeyliger | 5e35702 | 2025-05-16 04:50:34 +0000 | [diff] [blame] | 160 | const component = await mount(SketchCallStatus, { |
| 161 | props: { |
| 162 | isIdle: false, |
| 163 | isDisconnected: false, |
| 164 | llmCalls: 1, |
| 165 | toolCalls: [], |
| 166 | }, |
| 167 | }); |
| 168 | |
| 169 | // Check that the status banner has the correct class and text |
| Autoformatter | 8c46362 | 2025-05-16 21:54:17 +0000 | [diff] [blame] | 170 | await expect(component.locator(".status-banner")).toHaveClass( |
| 171 | /status-working/, |
| 172 | ); |
| Philip Zeyliger | 5e35702 | 2025-05-16 04:50:34 +0000 | [diff] [blame] | 173 | await expect(component.locator(".status-banner")).toHaveText("WORKING"); |
| 174 | }); |
| 175 | |
| Autoformatter | 8c46362 | 2025-05-16 21:54:17 +0000 | [diff] [blame] | 176 | test("displays DISCONNECTED status when isDisconnected is true regardless of isIdle", async ({ |
| 177 | mount, |
| 178 | }) => { |
| Philip Zeyliger | 5e35702 | 2025-05-16 04:50:34 +0000 | [diff] [blame] | 179 | const component = await mount(SketchCallStatus, { |
| 180 | props: { |
| 181 | isIdle: true, // Even when idle |
| 182 | isDisconnected: true, |
| 183 | llmCalls: 0, |
| 184 | toolCalls: [], |
| 185 | }, |
| 186 | }); |
| 187 | |
| 188 | // Check that the status banner has the correct class and text |
| Autoformatter | 8c46362 | 2025-05-16 21:54:17 +0000 | [diff] [blame] | 189 | await expect(component.locator(".status-banner")).toHaveClass( |
| 190 | /status-disconnected/, |
| 191 | ); |
| Philip Zeyliger | 5e35702 | 2025-05-16 04:50:34 +0000 | [diff] [blame] | 192 | await expect(component.locator(".status-banner")).toHaveText("DISCONNECTED"); |
| 193 | }); |