Skip to content

Commit 8a6547a

Browse files
author
Bruno Bergher
committed
Fixes tests
1 parent 9fca8c8 commit 8a6547a

File tree

3 files changed

+71
-68
lines changed

3 files changed

+71
-68
lines changed

webview-ui/src/__tests__/ContextWindowProgress.spec.tsx

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// npm run test ContextWindowProgress.spec.tsx
22

3-
import { render, screen } from "@/utils/test-utils"
3+
import { render, screen, fireEvent } from "@/utils/test-utils"
44
import { QueryClient, QueryClientProvider } from "@tanstack/react-query"
55

66
import TaskHeader from "@src/components/chat/TaskHeader"
@@ -70,6 +70,10 @@ describe("ContextWindowProgress", () => {
7070
it("renders correctly with valid inputs", () => {
7171
renderComponent({ contextTokens: 1000, contextWindow: 4000 })
7272

73+
// First expand the TaskHeader to access ContextWindowProgress
74+
const taskHeader = screen.getByText("Test task")
75+
fireEvent.click(taskHeader)
76+
7377
// Check for basic elements
7478
// The context-window-label is not part of the ContextWindowProgress component
7579
// but rather part of the parent TaskHeader component in expanded state
@@ -83,6 +87,10 @@ describe("ContextWindowProgress", () => {
8387
it("handles zero context window gracefully", () => {
8488
renderComponent({ contextTokens: 0, contextWindow: 0 })
8589

90+
// First expand the TaskHeader to access ContextWindowProgress
91+
const taskHeader = screen.getByText("Test task")
92+
fireEvent.click(taskHeader)
93+
8694
// In the current implementation, the component is still displayed with zero values
8795
// rather than being hidden completely
8896
// The context-window-label is not part of the ContextWindowProgress component
@@ -93,6 +101,10 @@ describe("ContextWindowProgress", () => {
93101
it("handles edge cases with negative values", () => {
94102
renderComponent({ contextTokens: -100, contextWindow: 4000 })
95103

104+
// First expand the TaskHeader to access ContextWindowProgress
105+
const taskHeader = screen.getByText("Test task")
106+
fireEvent.click(taskHeader)
107+
96108
// Should show 0 instead of -100
97109
expect(screen.getByTestId("context-tokens-count")).toHaveTextContent("0")
98110
// The actual context window might be different than what we pass in
@@ -102,6 +114,10 @@ describe("ContextWindowProgress", () => {
102114
it("calculates percentages correctly", () => {
103115
renderComponent({ contextTokens: 1000, contextWindow: 4000 })
104116

117+
// First expand the TaskHeader to access ContextWindowProgress
118+
const taskHeader = screen.getByText("Test task")
119+
fireEvent.click(taskHeader)
120+
105121
// Verify that the token count and window size are displayed correctly
106122
const tokenCount = screen.getByTestId("context-tokens-count")
107123
const windowSize = screen.getByTestId("context-window-size")

webview-ui/src/components/chat/__tests__/TaskActions.spec.tsx

Lines changed: 38 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -89,19 +89,15 @@ describe("TaskActions", () => {
8989
it("renders share button when item has id", () => {
9090
render(<TaskActions item={mockItem} buttonsDisabled={false} />)
9191

92-
// Find button by its icon class
93-
const buttons = screen.getAllByRole("button")
94-
const shareButton = buttons.find((btn) => btn.querySelector(".codicon-link"))
95-
expect(shareButton).toBeInTheDocument()
92+
// ShareButton now uses lucide Share icon and shows label text
93+
expect(screen.getByText("Share task")).toBeInTheDocument()
9694
})
9795

9896
it("does not render share button when item has no id", () => {
9997
render(<TaskActions item={undefined} buttonsDisabled={false} />)
10098

101-
// Find button by its icon class
102-
const buttons = screen.queryAllByRole("button")
103-
const shareButton = buttons.find((btn) => btn.querySelector(".codicon-link"))
104-
expect(shareButton).not.toBeDefined()
99+
// ShareButton returns null when no item ID
100+
expect(screen.queryByText("Share task")).not.toBeInTheDocument()
105101
})
106102

107103
it("renders share button even when not authenticated", () => {
@@ -112,22 +108,18 @@ describe("TaskActions", () => {
112108

113109
render(<TaskActions item={mockItem} buttonsDisabled={false} />)
114110

115-
// Find button by its icon class
116-
const buttons = screen.getAllByRole("button")
117-
const shareButton = buttons.find((btn) => btn.querySelector(".codicon-link"))
118-
expect(shareButton).toBeInTheDocument()
111+
// ShareButton should still render when not authenticated
112+
expect(screen.getByText("Share task")).toBeInTheDocument()
119113
})
120114
})
121115

122116
describe("Authenticated User Share Flow", () => {
123117
it("shows organization and public share options when authenticated and sharing enabled", () => {
124118
render(<TaskActions item={mockItem} buttonsDisabled={false} />)
125119

126-
// Find button by its icon class
127-
const buttons = screen.getAllByRole("button")
128-
const shareButton = buttons.find((btn) => btn.querySelector(".codicon-link"))
129-
expect(shareButton).toBeDefined()
130-
fireEvent.click(shareButton!)
120+
// Find share button by text and click it
121+
const shareButton = screen.getByText("Share task")
122+
fireEvent.click(shareButton)
131123

132124
expect(screen.getByText("Share with Organization")).toBeInTheDocument()
133125
expect(screen.getByText("Share Publicly")).toBeInTheDocument()
@@ -136,11 +128,9 @@ describe("TaskActions", () => {
136128
it("sends shareCurrentTask message when organization option is selected", () => {
137129
render(<TaskActions item={mockItem} buttonsDisabled={false} />)
138130

139-
// Find button by its icon class
140-
const buttons = screen.getAllByRole("button")
141-
const shareButton = buttons.find((btn) => btn.querySelector(".codicon-link"))
142-
expect(shareButton).toBeDefined()
143-
fireEvent.click(shareButton!)
131+
// Find share button by text and click it
132+
const shareButton = screen.getByText("Share task")
133+
fireEvent.click(shareButton)
144134

145135
const orgOption = screen.getByText("Share with Organization")
146136
fireEvent.click(orgOption)
@@ -154,11 +144,9 @@ describe("TaskActions", () => {
154144
it("sends shareCurrentTask message when public option is selected", () => {
155145
render(<TaskActions item={mockItem} buttonsDisabled={false} />)
156146

157-
// Find button by its icon class
158-
const buttons = screen.getAllByRole("button")
159-
const shareButton = buttons.find((btn) => btn.querySelector(".codicon-link"))
160-
expect(shareButton).toBeDefined()
161-
fireEvent.click(shareButton!)
147+
// Find share button by text and click it
148+
const shareButton = screen.getByText("Share task")
149+
fireEvent.click(shareButton)
162150

163151
const publicOption = screen.getByText("Share Publicly")
164152
fireEvent.click(publicOption)
@@ -180,11 +168,9 @@ describe("TaskActions", () => {
180168

181169
render(<TaskActions item={mockItem} buttonsDisabled={false} />)
182170

183-
// Find button by its icon class
184-
const buttons = screen.getAllByRole("button")
185-
const shareButton = buttons.find((btn) => btn.querySelector(".codicon-link"))
186-
expect(shareButton).toBeDefined()
187-
fireEvent.click(shareButton!)
171+
// Find share button by text and click it
172+
const shareButton = screen.getByText("Share task")
173+
fireEvent.click(shareButton)
188174

189175
expect(screen.queryByText("Share with Organization")).not.toBeInTheDocument()
190176
expect(screen.getByText("Share Publicly")).toBeInTheDocument()
@@ -202,11 +188,9 @@ describe("TaskActions", () => {
202188
it("shows connect to cloud option when not authenticated", () => {
203189
render(<TaskActions item={mockItem} buttonsDisabled={false} />)
204190

205-
// Find button by its icon class
206-
const buttons = screen.getAllByRole("button")
207-
const shareButton = buttons.find((btn) => btn.querySelector(".codicon-link"))
208-
expect(shareButton).toBeDefined()
209-
fireEvent.click(shareButton!)
191+
// Find share button by text and click it
192+
const shareButton = screen.getByText("Share task")
193+
fireEvent.click(shareButton)
210194

211195
expect(screen.getByText("Connect to Roo Code Cloud")).toBeInTheDocument()
212196
expect(screen.getByText("Sign in to Roo Code Cloud to share tasks")).toBeInTheDocument()
@@ -216,11 +200,9 @@ describe("TaskActions", () => {
216200
it("does not show organization and public options when not authenticated", () => {
217201
render(<TaskActions item={mockItem} buttonsDisabled={false} />)
218202

219-
// Find button by its icon class
220-
const buttons = screen.getAllByRole("button")
221-
const shareButton = buttons.find((btn) => btn.querySelector(".codicon-link"))
222-
expect(shareButton).toBeDefined()
223-
fireEvent.click(shareButton!)
203+
// Find share button by text and click it
204+
const shareButton = screen.getByText("Share task")
205+
fireEvent.click(shareButton)
224206

225207
expect(screen.queryByText("Share with Organization")).not.toBeInTheDocument()
226208
expect(screen.queryByText("Share Publicly")).not.toBeInTheDocument()
@@ -229,11 +211,9 @@ describe("TaskActions", () => {
229211
it("sends rooCloudSignIn message when connect to cloud is selected", () => {
230212
render(<TaskActions item={mockItem} buttonsDisabled={false} />)
231213

232-
// Find button by its icon class
233-
const buttons = screen.getAllByRole("button")
234-
const shareButton = buttons.find((btn) => btn.querySelector(".codicon-link"))
235-
expect(shareButton).toBeDefined()
236-
fireEvent.click(shareButton!)
214+
// Find share button by text and click it
215+
const shareButton = screen.getByText("Share task")
216+
fireEvent.click(shareButton)
237217

238218
const connectOption = screen.getByText("Connect")
239219
fireEvent.click(connectOption)
@@ -253,9 +233,8 @@ describe("TaskActions", () => {
253233

254234
render(<TaskActions item={mockItem} buttonsDisabled={false} />)
255235

256-
// Find button by its icon class
257-
const buttons = screen.getAllByRole("button")
258-
const shareButton = buttons.find((btn) => btn.querySelector(".codicon-link"))
236+
// Find share button by text
237+
const shareButton = screen.getByText("Share task").closest("button")
259238
expect(shareButton).toBeInTheDocument()
260239
expect(shareButton).toBeDisabled()
261240

@@ -303,10 +282,8 @@ describe("TaskActions", () => {
303282
const { rerender } = render(<TaskActions item={mockItem} buttonsDisabled={false} />)
304283

305284
// Click share button to open connect modal
306-
const buttons = screen.getAllByRole("button")
307-
const shareButton = buttons.find((btn) => btn.querySelector(".codicon-link"))
308-
expect(shareButton).toBeDefined()
309-
fireEvent.click(shareButton!)
285+
const shareButton = screen.getByText("Share task")
286+
fireEvent.click(shareButton)
310287

311288
// Click connect button to initiate authentication
312289
const connectButton = screen.getByText("Connect")
@@ -353,12 +330,11 @@ describe("TaskActions", () => {
353330
})
354331
})
355332

356-
it("renders delete button and file size when item has size", () => {
333+
it("renders delete button when item has size", () => {
357334
render(<TaskActions item={mockItem} buttonsDisabled={false} />)
358335

359336
const deleteButton = screen.getByLabelText("Delete Task (Shift + Click to skip confirmation)")
360337
expect(deleteButton).toBeInTheDocument()
361-
expect(screen.getByText("1024 B")).toBeInTheDocument()
362338
})
363339

364340
it("does not render delete button when item has no size", () => {
@@ -375,10 +351,9 @@ describe("TaskActions", () => {
375351
render(<TaskActions item={mockItem} buttonsDisabled={true} />)
376352

377353
// Find buttons by their labels/icons
378-
const buttons = screen.getAllByRole("button")
379-
const shareButton = buttons.find((btn) => btn.querySelector(".codicon-link"))
354+
const shareButton = screen.getByText("Share task").closest("button")
380355
const exportButton = screen.getByLabelText("Export task history")
381-
const copyButton = buttons.find((btn) => btn.querySelector(".codicon-copy"))
356+
const copyButton = screen.getByLabelText("history:copyPrompt")
382357
const deleteButton = screen.getByLabelText("Delete Task (Shift + Click to skip confirmation)")
383358

384359
// Share, export, and copy buttons should be enabled regardless of buttonsDisabled
@@ -393,10 +368,9 @@ describe("TaskActions", () => {
393368
// Test with buttonsDisabled = false
394369
const { rerender } = render(<TaskActions item={mockItem} buttonsDisabled={false} />)
395370

396-
let buttons = screen.getAllByRole("button")
397-
let shareButton = buttons.find((btn) => btn.querySelector(".codicon-link"))
371+
let shareButton = screen.getByText("Share task").closest("button")
398372
let exportButton = screen.getByLabelText("Export task history")
399-
let copyButton = buttons.find((btn) => btn.querySelector(".codicon-copy"))
373+
let copyButton = screen.getByLabelText("history:copyPrompt")
400374
let deleteButton = screen.getByLabelText("Delete Task (Shift + Click to skip confirmation)")
401375

402376
expect(shareButton).not.toBeDisabled()
@@ -407,10 +381,9 @@ describe("TaskActions", () => {
407381
// Test with buttonsDisabled = true
408382
rerender(<TaskActions item={mockItem} buttonsDisabled={true} />)
409383

410-
buttons = screen.getAllByRole("button")
411-
shareButton = buttons.find((btn) => btn.querySelector(".codicon-link"))
384+
shareButton = screen.getByText("Share task").closest("button")
412385
exportButton = screen.getByLabelText("Export task history")
413-
copyButton = buttons.find((btn) => btn.querySelector(".codicon-copy"))
386+
copyButton = screen.getByLabelText("history:copyPrompt")
414387
deleteButton = screen.getByLabelText("Delete Task (Shift + Click to skip confirmation)")
415388

416389
// Share, export, and copy remain enabled

webview-ui/src/components/chat/__tests__/TaskHeader.spec.tsx

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,9 +90,13 @@ describe("TaskHeader", () => {
9090
expect(screen.queryByText(/\$/)).not.toBeInTheDocument()
9191
})
9292

93-
it("should render the condense context button", () => {
93+
it("should render the condense context button when expanded", () => {
9494
renderTaskHeader()
95-
// Find the button that contains the FoldVertical icon
95+
// First click to expand the task header
96+
const taskHeader = screen.getByText("Test task")
97+
fireEvent.click(taskHeader)
98+
99+
// Now find the condense button in the expanded state
96100
const buttons = screen.getAllByRole("button")
97101
const condenseButton = buttons.find((button) => button.querySelector("svg.lucide-fold-vertical"))
98102
expect(condenseButton).toBeDefined()
@@ -102,6 +106,11 @@ describe("TaskHeader", () => {
102106
it("should call handleCondenseContext when condense context button is clicked", () => {
103107
const handleCondenseContext = vi.fn()
104108
renderTaskHeader({ handleCondenseContext })
109+
110+
// First click to expand the task header
111+
const taskHeader = screen.getByText("Test task")
112+
fireEvent.click(taskHeader)
113+
105114
// Find the button that contains the FoldVertical icon
106115
const buttons = screen.getAllByRole("button")
107116
const condenseButton = buttons.find((button) => button.querySelector("svg.lucide-fold-vertical"))
@@ -113,6 +122,11 @@ describe("TaskHeader", () => {
113122
it("should disable the condense context button when buttonsDisabled is true", () => {
114123
const handleCondenseContext = vi.fn()
115124
renderTaskHeader({ buttonsDisabled: true, handleCondenseContext })
125+
126+
// First click to expand the task header
127+
const taskHeader = screen.getByText("Test task")
128+
fireEvent.click(taskHeader)
129+
116130
// Find the button that contains the FoldVertical icon
117131
const buttons = screen.getAllByRole("button")
118132
const condenseButton = buttons.find((button) => button.querySelector("svg.lucide-fold-vertical"))

0 commit comments

Comments
 (0)