| 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, |
| Philip Zeyliger | 64f6046 | 2025-06-16 13:57:10 -0700 | [diff] [blame] | 30 | diff_lines_added: 15, |
| 31 | diff_lines_removed: 3, |
| Sean McCullough | b29f891 | 2025-04-20 15:39:11 -0700 | [diff] [blame] | 32 | }; |
| 33 | |
| 34 | test("render props", async ({ mount }) => { |
| 35 | const component = await mount(SketchContainerStatus, { |
| 36 | props: { |
| 37 | state: mockCompleteState, |
| 38 | }, |
| 39 | }); |
| 40 | await expect(component.locator("#hostname")).toContainText( |
| 41 | mockCompleteState.hostname, |
| 42 | ); |
| 43 | // Check that all expected elements exist |
| 44 | await expect(component.locator("#workingDir")).toContainText( |
| 45 | mockCompleteState.working_dir, |
| 46 | ); |
| Autoformatter | 3d040bd | 2025-06-06 02:35:19 +0000 | [diff] [blame] | 47 | |
| Josh Bleecher Snyder | 44f847a | 2025-06-05 14:33:50 -0700 | [diff] [blame] | 48 | // Show details to access the popup elements |
| philip.zeyliger | 6d3de48 | 2025-06-10 19:38:14 -0700 | [diff] [blame] | 49 | await component.locator(".info-toggle").click(); |
| Autoformatter | 3d040bd | 2025-06-06 02:35:19 +0000 | [diff] [blame] | 50 | |
| Sean McCullough | b29f891 | 2025-04-20 15:39:11 -0700 | [diff] [blame] | 51 | await expect(component.locator("#initialCommit")).toContainText( |
| 52 | mockCompleteState.initial_commit.substring(0, 8), |
| 53 | ); |
| 54 | |
| Autoformatter | 5c70bfe | 2025-04-25 21:28:00 +0000 | [diff] [blame] | 55 | await expect(component.locator("#messageCount")).toContainText( |
| Sean McCullough | b29f891 | 2025-04-20 15:39:11 -0700 | [diff] [blame] | 56 | mockCompleteState.message_count + "", |
| 57 | ); |
| Josh Bleecher Snyder | 3588997 | 2025-04-24 20:48:16 +0000 | [diff] [blame] | 58 | const expectedTotalInputTokens = |
| 59 | mockCompleteState.total_usage.input_tokens + |
| 60 | mockCompleteState.total_usage.cache_read_input_tokens + |
| 61 | mockCompleteState.total_usage.cache_creation_input_tokens; |
| Sean McCullough | b29f891 | 2025-04-20 15:39:11 -0700 | [diff] [blame] | 62 | await expect(component.locator("#inputTokens")).toContainText( |
| Josh Bleecher Snyder | a0801ad | 2025-04-25 19:34:53 +0000 | [diff] [blame] | 63 | expectedTotalInputTokens.toLocaleString(), |
| Sean McCullough | b29f891 | 2025-04-20 15:39:11 -0700 | [diff] [blame] | 64 | ); |
| 65 | await expect(component.locator("#outputTokens")).toContainText( |
| Josh Bleecher Snyder | a0801ad | 2025-04-25 19:34:53 +0000 | [diff] [blame] | 66 | mockCompleteState.total_usage.output_tokens.toLocaleString(), |
| Sean McCullough | b29f891 | 2025-04-20 15:39:11 -0700 | [diff] [blame] | 67 | ); |
| Sean McCullough | b29f891 | 2025-04-20 15:39:11 -0700 | [diff] [blame] | 68 | await expect(component.locator("#totalCost")).toContainText( |
| 69 | "$" + mockCompleteState.total_usage.total_cost_usd.toFixed(2), |
| 70 | ); |
| 71 | }); |
| 72 | |
| Sean McCullough | b29f891 | 2025-04-20 15:39:11 -0700 | [diff] [blame] | 73 | test("renders with partial state data", async ({ mount }) => { |
| 74 | const partialState: Partial<State> = { |
| Philip Zeyliger | d03318d | 2025-05-08 13:09:12 -0700 | [diff] [blame] | 75 | state_version: 2, |
| Sean McCullough | b29f891 | 2025-04-20 15:39:11 -0700 | [diff] [blame] | 76 | hostname: "partial-host", |
| 77 | message_count: 10, |
| Sean McCullough | 86b5686 | 2025-04-18 13:04:03 -0700 | [diff] [blame] | 78 | os: "linux", |
| Josh Bleecher Snyder | 19969a9 | 2025-06-05 14:34:02 -0700 | [diff] [blame] | 79 | slug: "partial-test", |
| Philip Zeyliger | c72fff5 | 2025-04-29 20:17:54 +0000 | [diff] [blame] | 80 | session_id: "partial-session", |
| 81 | ssh_available: false, |
| Sean McCullough | 86b5686 | 2025-04-18 13:04:03 -0700 | [diff] [blame] | 82 | total_usage: { |
| Sean McCullough | b29f891 | 2025-04-20 15:39:11 -0700 | [diff] [blame] | 83 | input_tokens: 500, |
| Sean McCullough | d9f1337 | 2025-04-21 15:08:49 -0700 | [diff] [blame] | 84 | start_time: "", |
| 85 | messages: 0, |
| 86 | output_tokens: 0, |
| 87 | cache_read_input_tokens: 0, |
| 88 | cache_creation_input_tokens: 0, |
| 89 | total_cost_usd: 0, |
| 90 | tool_uses: {}, |
| Sean McCullough | 71941bd | 2025-04-18 13:31:48 -0700 | [diff] [blame] | 91 | }, |
| Sean McCullough | 86b5686 | 2025-04-18 13:04:03 -0700 | [diff] [blame] | 92 | }; |
| 93 | |
| Sean McCullough | b29f891 | 2025-04-20 15:39:11 -0700 | [diff] [blame] | 94 | const component = await mount(SketchContainerStatus, { |
| 95 | props: { |
| 96 | state: partialState as State, |
| 97 | }, |
| Sean McCullough | 86b5686 | 2025-04-18 13:04:03 -0700 | [diff] [blame] | 98 | }); |
| 99 | |
| Sean McCullough | b29f891 | 2025-04-20 15:39:11 -0700 | [diff] [blame] | 100 | // Check that elements with data are properly populated |
| 101 | await expect(component.locator("#hostname")).toContainText("partial-host"); |
| Autoformatter | 3d040bd | 2025-06-06 02:35:19 +0000 | [diff] [blame] | 102 | |
| Josh Bleecher Snyder | 44f847a | 2025-06-05 14:33:50 -0700 | [diff] [blame] | 103 | // Show details to access the popup elements |
| philip.zeyliger | 6d3de48 | 2025-06-10 19:38:14 -0700 | [diff] [blame] | 104 | await component.locator(".info-toggle").click(); |
| Sean McCullough | b29f891 | 2025-04-20 15:39:11 -0700 | [diff] [blame] | 105 | await expect(component.locator("#messageCount")).toContainText("10"); |
| Josh Bleecher Snyder | 3588997 | 2025-04-24 20:48:16 +0000 | [diff] [blame] | 106 | |
| 107 | const expectedTotalInputTokens = |
| 108 | partialState.total_usage.input_tokens + |
| 109 | partialState.total_usage.cache_read_input_tokens + |
| 110 | partialState.total_usage.cache_creation_input_tokens; |
| 111 | await expect(component.locator("#inputTokens")).toContainText( |
| Josh Bleecher Snyder | a0801ad | 2025-04-25 19:34:53 +0000 | [diff] [blame] | 112 | expectedTotalInputTokens.toLocaleString(), |
| Josh Bleecher Snyder | 3588997 | 2025-04-24 20:48:16 +0000 | [diff] [blame] | 113 | ); |
| Sean McCullough | 86b5686 | 2025-04-18 13:04:03 -0700 | [diff] [blame] | 114 | |
| Sean McCullough | b29f891 | 2025-04-20 15:39:11 -0700 | [diff] [blame] | 115 | // Check that elements without data are empty |
| 116 | await expect(component.locator("#workingDir")).toContainText(""); |
| 117 | await expect(component.locator("#initialCommit")).toContainText(""); |
| Josh Bleecher Snyder | 3588997 | 2025-04-24 20:48:16 +0000 | [diff] [blame] | 118 | await expect(component.locator("#outputTokens")).toContainText("0"); |
| Josh Bleecher Snyder | 44f847a | 2025-06-05 14:33:50 -0700 | [diff] [blame] | 119 | // totalCost element should not exist when cost is 0 |
| 120 | await expect(component.locator("#totalCost")).toHaveCount(0); |
| Sean McCullough | b29f891 | 2025-04-20 15:39:11 -0700 | [diff] [blame] | 121 | }); |
| Sean McCullough | c7c2cc1 | 2025-06-13 03:21:18 +0000 | [diff] [blame] | 122 | |
| 123 | test("formatGitHubRepo handles repository names with dots correctly", async ({ |
| 124 | mount, |
| 125 | }) => { |
| 126 | // Test repository with dots in name |
| 127 | const component = await mount(SketchContainerStatus, { |
| 128 | props: { |
| 129 | state: { |
| 130 | ...mockCompleteState, |
| 131 | git_origin: "git@github.com:user/repo.with.dots.git", |
| 132 | link_to_github: true, |
| 133 | }, |
| 134 | }, |
| 135 | }); |
| 136 | |
| 137 | // Check that the GitHub link is displayed correctly with dots preserved |
| 138 | const githubLink = component.locator("a.github-link"); |
| 139 | await expect(githubLink).toContainText("user/repo.with.dots"); |
| 140 | await expect(githubLink).toHaveAttribute( |
| 141 | "href", |
| 142 | "https://github.com/user/repo.with.dots", |
| 143 | ); |
| 144 | await expect(githubLink).toHaveAttribute( |
| 145 | "title", |
| 146 | "git@github.com:user/repo.with.dots.git", |
| 147 | ); |
| 148 | }); |
| 149 | |
| 150 | test("formatGitHubRepo handles boldsoftware/sketch.git correctly", async ({ |
| 151 | mount, |
| 152 | }) => { |
| 153 | // Test the specific case mentioned in the issue |
| 154 | const component = await mount(SketchContainerStatus, { |
| 155 | props: { |
| 156 | state: { |
| 157 | ...mockCompleteState, |
| 158 | git_origin: "git@github.com:boldsoftware/sketch.git", |
| 159 | link_to_github: true, |
| 160 | }, |
| 161 | }, |
| 162 | }); |
| 163 | |
| 164 | // Check that the GitHub link is displayed correctly |
| 165 | const githubLink = component.locator("a.github-link"); |
| 166 | await expect(githubLink).toContainText("boldsoftware/sketch"); |
| 167 | await expect(githubLink).toHaveAttribute( |
| 168 | "href", |
| 169 | "https://github.com/boldsoftware/sketch", |
| 170 | ); |
| 171 | await expect(githubLink).toHaveAttribute( |
| 172 | "title", |
| 173 | "git@github.com:boldsoftware/sketch.git", |
| 174 | ); |
| 175 | }); |