Skip to content

Commit 5a84ca5

Browse files
author
Bruno Bergher
committed
Fixes tests
1 parent ddd9152 commit 5a84ca5

File tree

2 files changed

+32
-27
lines changed

2 files changed

+32
-27
lines changed

webview-ui/src/components/chat/ShareButton.tsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,8 @@ export const ShareButton = ({ item, disabled = false, showLabel = false }: Share
164164
? "h-7 px-2 hover:bg-vscode-toolbar-hoverBackground"
165165
: "h-7 w-7 p-1.5 hover:bg-vscode-toolbar-hoverBackground"
166166
}
167-
onClick={handleShareButtonClick}>
167+
onClick={handleShareButtonClick}
168+
data-testid="share-button">
168169
<SquareArrowOutUpRightIcon />
169170
{showLabel && <span className="ml-0">{t("chat:task.share")}</span>}
170171
</Button>
@@ -232,7 +233,8 @@ export const ShareButton = ({ item, disabled = false, showLabel = false }: Share
232233
? "h-7 px-2 hover:bg-vscode-toolbar-hoverBackground"
233234
: "h-7 w-7 p-1.5 hover:bg-vscode-toolbar-hoverBackground"
234235
}
235-
onClick={handleShareButtonClick}>
236+
onClick={handleShareButtonClick}
237+
data-testid="share-button">
236238
<SquareArrowOutUpRightIcon />
237239
{showLabel && <span className="ml-1">{t("chat:task.share")}</span>}
238240
</Button>

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

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

92-
// ShareButton now uses lucide Share icon and shows label text
93-
expect(screen.getByText("Share task")).toBeInTheDocument()
92+
// ShareButton now uses data-testid for reliable testing
93+
const shareButton = screen.getByTestId("share-button")
94+
expect(shareButton).toBeInTheDocument()
9495
})
9596

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

99100
// ShareButton returns null when no item ID
100-
expect(screen.queryByText("Share task")).not.toBeInTheDocument()
101+
const shareButton = screen.queryByTestId("share-button")
102+
expect(shareButton).toBeNull()
101103
})
102104

103105
it("renders share button even when not authenticated", () => {
@@ -109,16 +111,17 @@ describe("TaskActions", () => {
109111
render(<TaskActions item={mockItem} buttonsDisabled={false} />)
110112

111113
// ShareButton should still render when not authenticated
112-
expect(screen.getByText("Share task")).toBeInTheDocument()
114+
const shareButton = screen.getByTestId("share-button")
115+
expect(shareButton).toBeInTheDocument()
113116
})
114117
})
115118

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

120-
// Find share button by text and click it
121-
const shareButton = screen.getByText("Share task")
123+
// Find share button by its test ID and click it
124+
const shareButton = screen.getByTestId("share-button")
122125
fireEvent.click(shareButton)
123126

124127
expect(screen.getByText("Share with Organization")).toBeInTheDocument()
@@ -128,8 +131,8 @@ describe("TaskActions", () => {
128131
it("sends shareCurrentTask message when organization option is selected", () => {
129132
render(<TaskActions item={mockItem} buttonsDisabled={false} />)
130133

131-
// Find share button by text and click it
132-
const shareButton = screen.getByText("Share task")
134+
// Find share button by its test ID and click it
135+
const shareButton = screen.getByTestId("share-button")
133136
fireEvent.click(shareButton)
134137

135138
const orgOption = screen.getByText("Share with Organization")
@@ -144,8 +147,8 @@ describe("TaskActions", () => {
144147
it("sends shareCurrentTask message when public option is selected", () => {
145148
render(<TaskActions item={mockItem} buttonsDisabled={false} />)
146149

147-
// Find share button by text and click it
148-
const shareButton = screen.getByText("Share task")
150+
// Find share button by its test ID and click it
151+
const shareButton = screen.getByTestId("share-button")
149152
fireEvent.click(shareButton)
150153

151154
const publicOption = screen.getByText("Share Publicly")
@@ -168,8 +171,8 @@ describe("TaskActions", () => {
168171

169172
render(<TaskActions item={mockItem} buttonsDisabled={false} />)
170173

171-
// Find share button by text and click it
172-
const shareButton = screen.getByText("Share task")
174+
// Find share button by its test ID and click it
175+
const shareButton = screen.getByTestId("share-button")
173176
fireEvent.click(shareButton)
174177

175178
expect(screen.queryByText("Share with Organization")).not.toBeInTheDocument()
@@ -188,8 +191,8 @@ describe("TaskActions", () => {
188191
it("shows connect to cloud option when not authenticated", () => {
189192
render(<TaskActions item={mockItem} buttonsDisabled={false} />)
190193

191-
// Find share button by text and click it
192-
const shareButton = screen.getByText("Share task")
194+
// Find share button by its test ID and click it
195+
const shareButton = screen.getByTestId("share-button")
193196
fireEvent.click(shareButton)
194197

195198
expect(screen.getByText("Connect to Roo Code Cloud")).toBeInTheDocument()
@@ -200,8 +203,8 @@ describe("TaskActions", () => {
200203
it("does not show organization and public options when not authenticated", () => {
201204
render(<TaskActions item={mockItem} buttonsDisabled={false} />)
202205

203-
// Find share button by text and click it
204-
const shareButton = screen.getByText("Share task")
206+
// Find share button by its test ID and click it
207+
const shareButton = screen.getByTestId("share-button")
205208
fireEvent.click(shareButton)
206209

207210
expect(screen.queryByText("Share with Organization")).not.toBeInTheDocument()
@@ -211,8 +214,8 @@ describe("TaskActions", () => {
211214
it("sends rooCloudSignIn message when connect to cloud is selected", () => {
212215
render(<TaskActions item={mockItem} buttonsDisabled={false} />)
213216

214-
// Find share button by text and click it
215-
const shareButton = screen.getByText("Share task")
217+
// Find share button by its test ID and click it
218+
const shareButton = screen.getByTestId("share-button")
216219
fireEvent.click(shareButton)
217220

218221
const connectOption = screen.getByText("Connect")
@@ -233,8 +236,8 @@ describe("TaskActions", () => {
233236

234237
render(<TaskActions item={mockItem} buttonsDisabled={false} />)
235238

236-
// Find share button by text
237-
const shareButton = screen.getByText("Share task").closest("button")
239+
// Find share button by its test ID
240+
const shareButton = screen.getByTestId("share-button")
238241
expect(shareButton).toBeInTheDocument()
239242
expect(shareButton).toBeDisabled()
240243

@@ -282,7 +285,7 @@ describe("TaskActions", () => {
282285
const { rerender } = render(<TaskActions item={mockItem} buttonsDisabled={false} />)
283286

284287
// Click share button to open connect modal
285-
const shareButton = screen.getByText("Share task")
288+
const shareButton = screen.getByTestId("share-button")
286289
fireEvent.click(shareButton)
287290

288291
// Click connect button to initiate authentication
@@ -350,8 +353,8 @@ describe("TaskActions", () => {
350353
it("keeps share, export, and copy buttons enabled but disables delete button when buttonsDisabled is true", () => {
351354
render(<TaskActions item={mockItem} buttonsDisabled={true} />)
352355

353-
// Find buttons by their labels/icons
354-
const shareButton = screen.getByText("Share task").closest("button")
356+
// Find buttons by their labels/test IDs
357+
const shareButton = screen.getByTestId("share-button")
355358
const exportButton = screen.getByLabelText("Export task history")
356359
const copyButton = screen.getByLabelText("history:copyPrompt")
357360
const deleteButton = screen.getByLabelText("Delete Task (Shift + Click to skip confirmation)")
@@ -368,7 +371,7 @@ describe("TaskActions", () => {
368371
// Test with buttonsDisabled = false
369372
const { rerender } = render(<TaskActions item={mockItem} buttonsDisabled={false} />)
370373

371-
let shareButton = screen.getByText("Share task").closest("button")
374+
let shareButton = screen.getByTestId("share-button")
372375
let exportButton = screen.getByLabelText("Export task history")
373376
let copyButton = screen.getByLabelText("history:copyPrompt")
374377
let deleteButton = screen.getByLabelText("Delete Task (Shift + Click to skip confirmation)")
@@ -381,7 +384,7 @@ describe("TaskActions", () => {
381384
// Test with buttonsDisabled = true
382385
rerender(<TaskActions item={mockItem} buttonsDisabled={true} />)
383386

384-
shareButton = screen.getByText("Share task").closest("button")
387+
shareButton = screen.getByTestId("share-button")
385388
exportButton = screen.getByLabelText("Export task history")
386389
copyButton = screen.getByLabelText("history:copyPrompt")
387390
deleteButton = screen.getByLabelText("Delete Task (Shift + Click to skip confirmation)")

0 commit comments

Comments
 (0)