@@ -265,7 +265,7 @@ describe("TaskActions", () => {
265265 expect ( screen . queryByText ( "Connect to Cloud" ) ) . not . toBeInTheDocument ( )
266266 } )
267267
268- it ( "automatically opens popover when user becomes authenticated" , ( ) => {
268+ it ( "does not automatically open popover when user becomes authenticated from elsewhere " , ( ) => {
269269 // Start with unauthenticated state
270270 mockUseExtensionState . mockReturnValue ( {
271271 sharingEnabled : false ,
@@ -277,7 +277,7 @@ describe("TaskActions", () => {
277277 // Verify popover is not open initially
278278 expect ( screen . queryByText ( "Share with Organization" ) ) . not . toBeInTheDocument ( )
279279
280- // Simulate user becoming authenticated
280+ // Simulate user becoming authenticated (e.g., from AccountView)
281281 mockUseExtensionState . mockReturnValue ( {
282282 sharingEnabled : true ,
283283 cloudIsAuthenticated : true ,
@@ -288,7 +288,47 @@ describe("TaskActions", () => {
288288
289289 rerender ( < TaskActions item = { mockItem } buttonsDisabled = { false } /> )
290290
291- // Verify popover automatically opens and shows sharing options
291+ // Verify popover does NOT automatically open when auth happens from elsewhere
292+ expect ( screen . queryByText ( "Share with Organization" ) ) . not . toBeInTheDocument ( )
293+ expect ( screen . queryByText ( "Share Publicly" ) ) . not . toBeInTheDocument ( )
294+ } )
295+
296+ it ( "automatically opens popover when user authenticates from share button" , ( ) => {
297+ // Start with unauthenticated state
298+ mockUseExtensionState . mockReturnValue ( {
299+ sharingEnabled : false ,
300+ cloudIsAuthenticated : false ,
301+ } as any )
302+
303+ const { rerender } = render ( < TaskActions item = { mockItem } buttonsDisabled = { false } /> )
304+
305+ // 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 ! )
310+
311+ // Click connect button to initiate authentication
312+ const connectButton = screen . getByText ( "Connect" )
313+ fireEvent . click ( connectButton )
314+
315+ // Verify rooCloudSignIn message was sent
316+ expect ( mockPostMessage ) . toHaveBeenCalledWith ( {
317+ type : "rooCloudSignIn" ,
318+ } )
319+
320+ // Simulate user becoming authenticated after clicking connect from share button
321+ mockUseExtensionState . mockReturnValue ( {
322+ sharingEnabled : true ,
323+ cloudIsAuthenticated : true ,
324+ cloudUserInfo : {
325+ organizationName : "Test Organization" ,
326+ } ,
327+ } as any )
328+
329+ rerender ( < TaskActions item = { mockItem } buttonsDisabled = { false } /> )
330+
331+ // Verify popover automatically opens when auth was initiated from share button
292332 expect ( screen . getByText ( "Share with Organization" ) ) . toBeInTheDocument ( )
293333 expect ( screen . getByText ( "Share Publicly" ) ) . toBeInTheDocument ( )
294334 } )
0 commit comments