| Sean McCullough | b29f891 | 2025-04-20 15:39:11 -0700 | [diff] [blame] | 1 | import { test, expect } from "@sand4rt/experimental-ct-web"; |
| 2 | import { SketchContainerStatus } from "./sketch-container-status"; |
| Sean McCullough | 86b5686 | 2025-04-18 13:04:03 -0700 | [diff] [blame] | 3 | import { State } from "../types"; |
| 4 | |
| Sean McCullough | b29f891 | 2025-04-20 15:39:11 -0700 | [diff] [blame] | 5 | // Mock complete state for testing |
| 6 | const mockCompleteState: State = { |
| Philip Zeyliger | d03318d | 2025-05-08 13:09:12 -0700 | [diff] [blame] | 7 | state_version: 2, |
| Sean McCullough | b29f891 | 2025-04-20 15:39:11 -0700 | [diff] [blame] | 8 | hostname: "test-host", |
| 9 | working_dir: "/test/dir", |
| 10 | initial_commit: "abcdef1234567890", |
| 11 | message_count: 42, |
| 12 | os: "linux", |
| Josh Bleecher Snyder | 19969a9 | 2025-06-05 14:34:02 -0700 | [diff] [blame] | 13 | slug: "test-session", |
| Sean McCullough | b29f891 | 2025-04-20 15:39:11 -0700 | [diff] [blame] | 14 | total_usage: { |
| 15 | input_tokens: 1000, |
| 16 | output_tokens: 2000, |
| 17 | cache_read_input_tokens: 300, |
| 18 | cache_creation_input_tokens: 400, |
| 19 | total_cost_usd: 0.25, |
| Sean McCullough | d9f1337 | 2025-04-21 15:08:49 -0700 | [diff] [blame] | 20 | start_time: "", |
| 21 | messages: 0, |
| 22 | tool_uses: {}, |
| Sean McCullough | b29f891 | 2025-04-20 15:39:11 -0700 | [diff] [blame] | 23 | }, |
| Philip Zeyliger | 99a9a02 | 2025-04-27 15:15:25 +0000 | [diff] [blame] | 24 | outstanding_llm_calls: 0, |
| 25 | outstanding_tool_calls: [], |
| Philip Zeyliger | c72fff5 | 2025-04-29 20:17:54 +0000 | [diff] [blame] | 26 | session_id: "test-session-id", |
| 27 | ssh_available: false, |
| Philip Zeyliger | 2c4db09 | 2025-04-28 16:57:50 -0700 | [diff] [blame] | 28 | in_container: true, |
| 29 | first_message_index: 0, |
| Sean McCullough | b29f891 | 2025-04-20 15:39:11 -0700 | [diff] [blame] | 30 | }; |
| 31 | |
| 32 | test("render props", async ({ mount }) => { |
| 33 | const component = await mount(SketchContainerStatus, { |
| 34 | props: { |
| 35 | state: mockCompleteState, |
| 36 | }, |
| 37 | }); |
| 38 | await expect(component.locator("#hostname")).toContainText( |
| 39 | mockCompleteState.hostname, |
| 40 | ); |
| 41 | // Check that all expected elements exist |
| 42 | await expect(component.locator("#workingDir")).toContainText( |
| 43 | mockCompleteState.working_dir, |
| 44 | ); |
| Autoformatter | 3d040bd | 2025-06-06 02:35:19 +0000 | [diff] [blame] | 45 | |
| Josh Bleecher Snyder | 44f847a | 2025-06-05 14:33:50 -0700 | [diff] [blame] | 46 | // Show details to access the popup elements |
| philip.zeyliger | 6d3de48 | 2025-06-10 19:38:14 -0700 | [diff] [blame] | 47 | await component.locator(".info-toggle").click(); |
| Autoformatter | 3d040bd | 2025-06-06 02:35:19 +0000 | [diff] [blame] | 48 | |
| Sean McCullough | b29f891 | 2025-04-20 15:39:11 -0700 | [diff] [blame] | 49 | await expect(component.locator("#initialCommit")).toContainText( |
| 50 | mockCompleteState.initial_commit.substring(0, 8), |
| 51 | ); |
| 52 | |
| Autoformatter | 5c70bfe | 2025-04-25 21:28:00 +0000 | [diff] [blame] | 53 | await expect(component.locator("#messageCount")).toContainText( |
| Sean McCullough | b29f891 | 2025-04-20 15:39:11 -0700 | [diff] [blame] | 54 | mockCompleteState.message_count + "", |
| 55 | ); |
| Josh Bleecher Snyder | 3588997 | 2025-04-24 20:48:16 +0000 | [diff] [blame] | 56 | const expectedTotalInputTokens = |
| 57 | mockCompleteState.total_usage.input_tokens + |
| 58 | mockCompleteState.total_usage.cache_read_input_tokens + |
| 59 | mockCompleteState.total_usage.cache_creation_input_tokens; |
| Sean McCullough | b29f891 | 2025-04-20 15:39:11 -0700 | [diff] [blame] | 60 | await expect(component.locator("#inputTokens")).toContainText( |
| Josh Bleecher Snyder | a0801ad | 2025-04-25 19:34:53 +0000 | [diff] [blame] | 61 | expectedTotalInputTokens.toLocaleString(), |
| Sean McCullough | b29f891 | 2025-04-20 15:39:11 -0700 | [diff] [blame] | 62 | ); |
| 63 | await expect(component.locator("#outputTokens")).toContainText( |
| Josh Bleecher Snyder | a0801ad | 2025-04-25 19:34:53 +0000 | [diff] [blame] | 64 | mockCompleteState.total_usage.output_tokens.toLocaleString(), |
| Sean McCullough | b29f891 | 2025-04-20 15:39:11 -0700 | [diff] [blame] | 65 | ); |
| Sean McCullough | b29f891 | 2025-04-20 15:39:11 -0700 | [diff] [blame] | 66 | await expect(component.locator("#totalCost")).toContainText( |
| 67 | "$" + mockCompleteState.total_usage.total_cost_usd.toFixed(2), |
| 68 | ); |
| 69 | }); |
| 70 | |
| Sean McCullough | b29f891 | 2025-04-20 15:39:11 -0700 | [diff] [blame] | 71 | test("renders with partial state data", async ({ mount }) => { |
| 72 | const partialState: Partial<State> = { |
| Philip Zeyliger | d03318d | 2025-05-08 13:09:12 -0700 | [diff] [blame] | 73 | state_version: 2, |
| Sean McCullough | b29f891 | 2025-04-20 15:39:11 -0700 | [diff] [blame] | 74 | hostname: "partial-host", |
| 75 | message_count: 10, |
| Sean McCullough | 86b5686 | 2025-04-18 13:04:03 -0700 | [diff] [blame] | 76 | os: "linux", |
| Josh Bleecher Snyder | 19969a9 | 2025-06-05 14:34:02 -0700 | [diff] [blame] | 77 | slug: "partial-test", |
| Philip Zeyliger | c72fff5 | 2025-04-29 20:17:54 +0000 | [diff] [blame] | 78 | session_id: "partial-session", |
| 79 | ssh_available: false, |
| Sean McCullough | 86b5686 | 2025-04-18 13:04:03 -0700 | [diff] [blame] | 80 | total_usage: { |
| Sean McCullough | b29f891 | 2025-04-20 15:39:11 -0700 | [diff] [blame] | 81 | input_tokens: 500, |
| Sean McCullough | d9f1337 | 2025-04-21 15:08:49 -0700 | [diff] [blame] | 82 | start_time: "", |
| 83 | messages: 0, |
| 84 | output_tokens: 0, |
| 85 | cache_read_input_tokens: 0, |
| 86 | cache_creation_input_tokens: 0, |
| 87 | total_cost_usd: 0, |
| 88 | tool_uses: {}, |
| Sean McCullough | 71941bd | 2025-04-18 13:31:48 -0700 | [diff] [blame] | 89 | }, |
| Sean McCullough | 86b5686 | 2025-04-18 13:04:03 -0700 | [diff] [blame] | 90 | }; |
| 91 | |
| Sean McCullough | b29f891 | 2025-04-20 15:39:11 -0700 | [diff] [blame] | 92 | const component = await mount(SketchContainerStatus, { |
| 93 | props: { |
| 94 | state: partialState as State, |
| 95 | }, |
| Sean McCullough | 86b5686 | 2025-04-18 13:04:03 -0700 | [diff] [blame] | 96 | }); |
| 97 | |
| Sean McCullough | b29f891 | 2025-04-20 15:39:11 -0700 | [diff] [blame] | 98 | // Check that elements with data are properly populated |
| 99 | await expect(component.locator("#hostname")).toContainText("partial-host"); |
| Autoformatter | 3d040bd | 2025-06-06 02:35:19 +0000 | [diff] [blame] | 100 | |
| Josh Bleecher Snyder | 44f847a | 2025-06-05 14:33:50 -0700 | [diff] [blame] | 101 | // Show details to access the popup elements |
| philip.zeyliger | 6d3de48 | 2025-06-10 19:38:14 -0700 | [diff] [blame] | 102 | await component.locator(".info-toggle").click(); |
| Sean McCullough | b29f891 | 2025-04-20 15:39:11 -0700 | [diff] [blame] | 103 | await expect(component.locator("#messageCount")).toContainText("10"); |
| Josh Bleecher Snyder | 3588997 | 2025-04-24 20:48:16 +0000 | [diff] [blame] | 104 | |
| 105 | const expectedTotalInputTokens = |
| 106 | partialState.total_usage.input_tokens + |
| 107 | partialState.total_usage.cache_read_input_tokens + |
| 108 | partialState.total_usage.cache_creation_input_tokens; |
| 109 | await expect(component.locator("#inputTokens")).toContainText( |
| Josh Bleecher Snyder | a0801ad | 2025-04-25 19:34:53 +0000 | [diff] [blame] | 110 | expectedTotalInputTokens.toLocaleString(), |
| Josh Bleecher Snyder | 3588997 | 2025-04-24 20:48:16 +0000 | [diff] [blame] | 111 | ); |
| Sean McCullough | 86b5686 | 2025-04-18 13:04:03 -0700 | [diff] [blame] | 112 | |
| Sean McCullough | b29f891 | 2025-04-20 15:39:11 -0700 | [diff] [blame] | 113 | // Check that elements without data are empty |
| 114 | await expect(component.locator("#workingDir")).toContainText(""); |
| 115 | await expect(component.locator("#initialCommit")).toContainText(""); |
| Josh Bleecher Snyder | 3588997 | 2025-04-24 20:48:16 +0000 | [diff] [blame] | 116 | await expect(component.locator("#outputTokens")).toContainText("0"); |
| Josh Bleecher Snyder | 44f847a | 2025-06-05 14:33:50 -0700 | [diff] [blame] | 117 | // totalCost element should not exist when cost is 0 |
| 118 | await expect(component.locator("#totalCost")).toHaveCount(0); |
| Sean McCullough | b29f891 | 2025-04-20 15:39:11 -0700 | [diff] [blame] | 119 | }); |