Skip to content

Commit 5c8085c

Browse files
committed
Fixes sharebutton behavior and updates associated tests
1 parent 1fa8129 commit 5c8085c

File tree

3 files changed

+40
-54
lines changed

3 files changed

+40
-54
lines changed

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

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ interface ShareButtonProps {
3030
export const ShareButton = ({ item, disabled = false, showLabel = false }: ShareButtonProps) => {
3131
const [shareDropdownOpen, setShareDropdownOpen] = useState(false)
3232
const [shareSuccess, setShareSuccess] = useState<{ visibility: ShareVisibility; url: string } | null>(null)
33+
const [wasConnectInitiatedFromShare, setWasConnectInitiatedFromShare] = useState(false)
3334
const { t } = useTranslation()
3435
const { cloudUserInfo } = useExtensionState()
3536

@@ -45,10 +46,18 @@ export const ShareButton = ({ item, disabled = false, showLabel = false }: Share
4546
onAuthSuccess: () => {
4647
// Auto-open share dropdown after successful authentication
4748
setShareDropdownOpen(true)
49+
setWasConnectInitiatedFromShare(false)
4850
},
49-
autoOpenOnAuth: true,
5051
})
5152

53+
// Auto-open popover when user becomes authenticated after clicking Connect from share button
54+
useEffect(() => {
55+
if (wasConnectInitiatedFromShare && cloudIsAuthenticated) {
56+
setShareDropdownOpen(true)
57+
setWasConnectInitiatedFromShare(false)
58+
}
59+
}, [wasConnectInitiatedFromShare, cloudIsAuthenticated])
60+
5261
// Listen for share success messages from the extension
5362
useEffect(() => {
5463
const handleMessage = (event: MessageEvent) => {
@@ -89,6 +98,7 @@ export const ShareButton = ({ item, disabled = false, showLabel = false }: Share
8998
}
9099

91100
const handleConnectToCloud = () => {
101+
setWasConnectInitiatedFromShare(true)
92102
handleConnect()
93103
setShareDropdownOpen(false)
94104
}

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

Lines changed: 26 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -82,16 +82,10 @@ vi.mock("../Announcement", () => ({
8282
},
8383
}))
8484

85-
// Mock RooCloudCTA component
86-
vi.mock("@src/components/welcome/RooCloudCTA", () => ({
87-
default: function MockRooCloudCTA() {
88-
return (
89-
<div data-testid="roo-cloud-cta">
90-
<div>rooCloudCTA.title</div>
91-
<div>rooCloudCTA.description</div>
92-
<div>rooCloudCTA.joinWaitlist</div>
93-
</div>
94-
)
85+
// Mock DismissibleUpsell component
86+
vi.mock("@/components/common/DismissibleUpsell", () => ({
87+
default: function MockDismissibleUpsell({ children }: { children: React.ReactNode }) {
88+
return <div data-testid="dismissible-upsell">{children}</div>
9589
},
9690
}))
9791

@@ -1274,10 +1268,10 @@ describe("ChatView - Version Indicator Tests", () => {
12741268
})
12751269
})
12761270

1277-
describe("ChatView - RooCloudCTA Display Tests", () => {
1271+
describe("ChatView - DismissibleUpsell Display Tests", () => {
12781272
beforeEach(() => vi.clearAllMocks())
12791273

1280-
it("does not show RooCloudCTA when user is authenticated to Cloud", () => {
1274+
it("does not show DismissibleUpsell when user is authenticated to Cloud", () => {
12811275
const { queryByTestId } = renderChatView()
12821276

12831277
// Hydrate state with user authenticated to cloud
@@ -1292,11 +1286,11 @@ describe("ChatView - RooCloudCTA Display Tests", () => {
12921286
clineMessages: [], // No active task
12931287
})
12941288

1295-
// Should not show RooCloudCTA when authenticated
1296-
expect(queryByTestId("roo-cloud-cta")).not.toBeInTheDocument()
1289+
// Should not show DismissibleUpsell when authenticated
1290+
expect(queryByTestId("dismissible-upsell")).not.toBeInTheDocument()
12971291
})
12981292

1299-
it("does not show RooCloudCTA when user has only run 3 tasks in their history", () => {
1293+
it("does not show DismissibleUpsell when user has only run 3 tasks in their history", () => {
13001294
const { queryByTestId } = renderChatView()
13011295

13021296
// Hydrate state with user not authenticated but only 3 tasks
@@ -1310,11 +1304,11 @@ describe("ChatView - RooCloudCTA Display Tests", () => {
13101304
clineMessages: [], // No active task
13111305
})
13121306

1313-
// Should not show RooCloudCTA with less than 4 tasks
1314-
expect(queryByTestId("roo-cloud-cta")).not.toBeInTheDocument()
1307+
// Should not show DismissibleUpsell with less than 4 tasks
1308+
expect(queryByTestId("dismissible-upsell")).not.toBeInTheDocument()
13151309
})
13161310

1317-
it("shows RooCloudCTA when user is not authenticated and has run 4 or more tasks", async () => {
1311+
it("shows DismissibleUpsell when user is not authenticated and has run 4 or more tasks", async () => {
13181312
const { getByTestId } = renderChatView()
13191313

13201314
// Hydrate state with user not authenticated and 4 tasks
@@ -1329,13 +1323,13 @@ describe("ChatView - RooCloudCTA Display Tests", () => {
13291323
clineMessages: [], // No active task
13301324
})
13311325

1332-
// Wait for component to render and show RooCloudCTA
1326+
// Wait for component to render and show DismissibleUpsell
13331327
await waitFor(() => {
1334-
expect(getByTestId("roo-cloud-cta")).toBeInTheDocument()
1328+
expect(getByTestId("dismissible-upsell")).toBeInTheDocument()
13351329
})
13361330
})
13371331

1338-
it("shows RooCloudCTA when user is not authenticated and has run 5 tasks", async () => {
1332+
it("shows DismissibleUpsell when user is not authenticated and has run 5 tasks", async () => {
13391333
const { getByTestId } = renderChatView()
13401334

13411335
// Hydrate state with user not authenticated and 5 tasks
@@ -1351,13 +1345,13 @@ describe("ChatView - RooCloudCTA Display Tests", () => {
13511345
clineMessages: [], // No active task
13521346
})
13531347

1354-
// Wait for component to render and show RooCloudCTA
1348+
// Wait for component to render and show DismissibleUpsell
13551349
await waitFor(() => {
1356-
expect(getByTestId("roo-cloud-cta")).toBeInTheDocument()
1350+
expect(getByTestId("dismissible-upsell")).toBeInTheDocument()
13571351
})
13581352
})
13591353

1360-
it("does not show RooCloudCTA when there is an active task (regardless of auth status)", async () => {
1354+
it("does not show DismissibleUpsell when there is an active task (regardless of auth status)", async () => {
13611355
const { queryByTestId } = renderChatView()
13621356

13631357
// Hydrate state with active task
@@ -1381,16 +1375,16 @@ describe("ChatView - RooCloudCTA Display Tests", () => {
13811375

13821376
// Wait for component to render with active task
13831377
await waitFor(() => {
1384-
// Should not show RooCloudCTA during active task
1385-
expect(queryByTestId("roo-cloud-cta")).not.toBeInTheDocument()
1378+
// Should not show DismissibleUpsell during active task
1379+
expect(queryByTestId("dismissible-upsell")).not.toBeInTheDocument()
13861380
// Should not show RooTips either since the entire welcome screen is hidden during active tasks
13871381
expect(queryByTestId("roo-tips")).not.toBeInTheDocument()
13881382
// Should not show RooHero either since the entire welcome screen is hidden during active tasks
13891383
expect(queryByTestId("roo-hero")).not.toBeInTheDocument()
13901384
})
13911385
})
13921386

1393-
it("shows RooTips when user is authenticated (instead of RooCloudCTA)", () => {
1387+
it("shows RooTips when user is authenticated (instead of DismissibleUpsell)", () => {
13941388
const { queryByTestId, getByTestId } = renderChatView()
13951389

13961390
// Hydrate state with user authenticated to cloud
@@ -1405,12 +1399,12 @@ describe("ChatView - RooCloudCTA Display Tests", () => {
14051399
clineMessages: [], // No active task
14061400
})
14071401

1408-
// Should not show RooCloudCTA but should show RooTips
1409-
expect(queryByTestId("roo-cloud-cta")).not.toBeInTheDocument()
1402+
// Should not show DismissibleUpsell but should show RooTips
1403+
expect(queryByTestId("dismissible-upsell")).not.toBeInTheDocument()
14101404
expect(getByTestId("roo-tips")).toBeInTheDocument()
14111405
})
14121406

1413-
it("shows RooTips when user has fewer than 4 tasks (instead of RooCloudCTA)", () => {
1407+
it("shows RooTips when user has fewer than 4 tasks (instead of DismissibleUpsell)", () => {
14141408
const { queryByTestId, getByTestId } = renderChatView()
14151409

14161410
// Hydrate state with user not authenticated but fewer than 4 tasks
@@ -1424,8 +1418,8 @@ describe("ChatView - RooCloudCTA Display Tests", () => {
14241418
clineMessages: [], // No active task
14251419
})
14261420

1427-
// Should not show RooCloudCTA but should show RooTips
1428-
expect(queryByTestId("roo-cloud-cta")).not.toBeInTheDocument()
1421+
// Should not show DismissibleUpsell but should show RooTips
1422+
expect(queryByTestId("dismissible-upsell")).not.toBeInTheDocument()
14291423
expect(getByTestId("roo-tips")).toBeInTheDocument()
14301424
})
14311425
})

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

Lines changed: 3 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -43,11 +43,11 @@ vi.mock("react-i18next", () => ({
4343
"chat:task.connectToCloudDescription": "Sign in to Roo Code Cloud to share tasks",
4444
"chat:task.sharingDisabledByOrganization": "Sharing disabled by organization",
4545
"cloud:cloudBenefitsTitle": "Connect to Roo Code Cloud",
46-
"cloud:cloudBenefitsSubtitle": "Sign in to Roo Code Cloud to share tasks",
4746
"cloud:cloudBenefitHistory": "Access your task history from anywhere",
4847
"cloud:cloudBenefitSharing": "Share tasks with your team",
4948
"cloud:cloudBenefitMetrics": "Track usage and costs",
5049
"cloud:connect": "Connect",
50+
"history:copyPrompt": "Copy",
5151
}
5252
return translations[key] || key
5353
},
@@ -197,7 +197,6 @@ describe("TaskActions", () => {
197197
fireEvent.click(shareButton)
198198

199199
expect(screen.getByText("Connect to Roo Code Cloud")).toBeInTheDocument()
200-
expect(screen.getByText("Sign in to Roo Code Cloud to share tasks")).toBeInTheDocument()
201200
expect(screen.getByText("Connect")).toBeInTheDocument()
202201
})
203202

@@ -351,30 +350,13 @@ describe("TaskActions", () => {
351350
})
352351

353352
describe("Button States", () => {
354-
it("keeps share, export, and copy buttons enabled but disables delete button when buttonsDisabled is true", () => {
355-
render(<TaskActions item={mockItem} buttonsDisabled={true} />)
356-
357-
// Find buttons by their labels/test IDs
358-
const shareButton = screen.getByTestId("share-button")
359-
const exportButton = screen.getByLabelText("Export task history")
360-
const copyButton = screen.getByLabelText("history:copyPrompt")
361-
const deleteButton = screen.getByLabelText("Delete Task (Shift + Click to skip confirmation)")
362-
363-
// Share, export, and copy buttons should be enabled regardless of buttonsDisabled
364-
expect(shareButton).not.toBeDisabled()
365-
expect(exportButton).not.toBeDisabled()
366-
expect(copyButton).not.toBeDisabled()
367-
// Delete button should respect buttonsDisabled
368-
expect(deleteButton).toBeDisabled()
369-
})
370-
371353
it("share, export, and copy buttons are always enabled while delete button respects buttonsDisabled state", () => {
372354
// Test with buttonsDisabled = false
373355
const { rerender } = render(<TaskActions item={mockItem} buttonsDisabled={false} />)
374356

375357
let shareButton = screen.getByTestId("share-button")
376358
let exportButton = screen.getByLabelText("Export task history")
377-
let copyButton = screen.getByLabelText("history:copyPrompt")
359+
let copyButton = screen.getByLabelText("Copy")
378360
let deleteButton = screen.getByLabelText("Delete Task (Shift + Click to skip confirmation)")
379361

380362
expect(shareButton).not.toBeDisabled()
@@ -387,7 +369,7 @@ describe("TaskActions", () => {
387369

388370
shareButton = screen.getByTestId("share-button")
389371
exportButton = screen.getByLabelText("Export task history")
390-
copyButton = screen.getByLabelText("history:copyPrompt")
372+
copyButton = screen.getByLabelText("Copy")
391373
deleteButton = screen.getByLabelText("Delete Task (Shift + Click to skip confirmation)")
392374

393375
// Share, export, and copy remain enabled

0 commit comments

Comments
 (0)