Skip to content

Commit 43d847a

Browse files
author
Eric Wheeler
committed
test: update history component tests to match implementation
Update data-testid attributes in HistoryView and TaskItem tests to match the actual implementation in TaskItemFooter component. The tests were looking for generic "tokens-in" and "tokens-out" attributes, but the implementation uses variant-specific attributes like "tokens-in-footer-full". Also added mocks for CopyButton and ExportButton components to resolve "Element type is invalid" errors during test rendering. Signed-off-by: Eric Wheeler <[email protected]>
1 parent c2bbae9 commit 43d847a

File tree

2 files changed

+15
-8
lines changed

2 files changed

+15
-8
lines changed

webview-ui/src/components/history/__tests__/HistoryView.test.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -300,9 +300,9 @@ describe("HistoryView", () => {
300300
// Find first task container
301301
const taskContainer = screen.getByTestId("virtuoso-item-1")
302302

303-
// Find token counts within the task container (TaskItem -> TaskItemHeader)
304-
expect(within(taskContainer).getByTestId("tokens-in")).toHaveTextContent("100")
305-
expect(within(taskContainer).getByTestId("tokens-out")).toHaveTextContent("50")
303+
// Find token counts within the task container (TaskItem -> TaskItemFooter)
304+
expect(within(taskContainer).getByTestId("tokens-in-footer-full")).toHaveTextContent("100")
305+
expect(within(taskContainer).getByTestId("tokens-out-footer-full")).toHaveTextContent("50")
306306
})
307307

308308
it("displays cache information when available", () => {

webview-ui/src/components/history/__tests__/TaskItem.test.tsx

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,13 @@ jest.mock("@src/utils/vscode")
77
jest.mock("@src/i18n/TranslationContext")
88
jest.mock("lucide-react", () => ({
99
DollarSign: () => <span data-testid="dollar-sign">$</span>,
10+
Coins: () => <span data-testid="coins-icon" />, // Mock for Coins icon used in TaskItemFooter compact
11+
}))
12+
jest.mock("../CopyButton", () => ({
13+
CopyButton: jest.fn(() => <button data-testid="mock-copy-button">Copy</button>),
14+
}))
15+
jest.mock("../ExportButton", () => ({
16+
ExportButton: jest.fn(() => <button data-testid="mock-export-button">Export</button>),
1017
}))
1118

1219
const mockTask: HistoryItem = {
@@ -30,18 +37,18 @@ describe("TaskItem", () => {
3037

3138
expect(screen.getByText("Test task content")).toBeInTheDocument()
3239
// Check for tokens display
33-
expect(screen.getByTestId("tokens-in")).toHaveTextContent("100")
34-
expect(screen.getByTestId("tokens-out")).toHaveTextContent("50")
35-
expect(screen.getByText("0.00")).toBeInTheDocument() // Cost
40+
expect(screen.getByTestId("tokens-in-footer-compact")).toHaveTextContent("100")
41+
expect(screen.getByTestId("tokens-out-footer-compact")).toHaveTextContent("50")
42+
expect(screen.getByTestId("cost-footer-compact")).toHaveTextContent("$0.00") // Cost
3643
})
3744

3845
it("renders full variant correctly", () => {
3946
render(<TaskItem item={mockTask} variant="full" />)
4047

4148
expect(screen.getByTestId("task-item-test-task-1")).toBeInTheDocument()
4249
expect(screen.getByTestId("task-content")).toBeInTheDocument()
43-
expect(screen.getByTestId("tokens-in")).toHaveTextContent("100")
44-
expect(screen.getByTestId("tokens-out")).toHaveTextContent("50")
50+
expect(screen.getByTestId("tokens-in-footer-full")).toHaveTextContent("100")
51+
expect(screen.getByTestId("tokens-out-footer-full")).toHaveTextContent("50")
4552
})
4653

4754
it("shows workspace when showWorkspace is true", () => {

0 commit comments

Comments
 (0)