@@ -6,18 +6,14 @@ import { createRoot, type Root } from 'react-dom/client'
66import { renderToString } from 'react-dom/server'
77import { afterEach , beforeEach , describe , expect , it , vi } from 'vitest'
88
9- const { mockNavigateToSettings, mockWorkspacePermissions, hostContext } = vi . hoisted ( ( ) => ( {
9+ const { mockNavigateToSettings, mockWorkspacePermissions, organizationList } = vi . hoisted ( ( ) => ( {
1010 mockNavigateToSettings : vi . fn ( ) ,
11- hostContext : {
12- hostOrganizationId : null as string | null ,
13- viewer : { isHostOrganizationMember : false } ,
14- features : { organizationSearch : false as boolean | undefined } ,
15- } ,
11+ organizationList : { data : [ ] as { id : string } [ ] | undefined } ,
1612 mockWorkspacePermissions : { canAdmin : true , canEdit : true , canRead : true } ,
1713} ) )
1814
19- vi . mock ( '@/app/workspace/[workspaceId]/providers/workspace-host-provider ' , ( ) => ( {
20- useWorkspaceHostContext : ( ) => hostContext ,
15+ vi . mock ( '@/hooks/queries/organization ' , ( ) => ( {
16+ useOrganizationList : ( ) => organizationList ,
2117} ) )
2218
2319const onWorkspaceSwitch = vi . fn ( )
@@ -29,7 +25,6 @@ vi.mock('next/navigation', () => ({
2925 useRouter : ( ) => ( { push : vi . fn ( ) } ) ,
3026 usePathname : ( ) => '/workspace/ws-emir/home' ,
3127} ) )
32- vi . mock ( '@/lib/auth/auth-client' , ( ) => ( { useActiveOrganization : ( ) => ( { data : null } ) } ) )
3328vi . mock ( '@/hooks/use-settings-navigation' , ( ) => ( {
3429 useSettingsNavigation : ( ) => ( {
3530 navigateToSettings : mockNavigateToSettings ,
@@ -170,9 +165,7 @@ function typeInto(input: HTMLInputElement, value: string) {
170165
171166beforeEach ( ( ) => {
172167 vi . clearAllMocks ( )
173- hostContext . hostOrganizationId = null
174- hostContext . viewer . isHostOrganizationMember = false
175- hostContext . features . organizationSearch = false
168+ organizationList . data = [ ]
176169 Object . assign ( mockWorkspacePermissions , { canAdmin : true , canEdit : true , canRead : true } )
177170 // jsdom implements neither; the component scrolls the active row into view.
178171 Element . prototype . scrollIntoView = vi . fn ( )
@@ -187,8 +180,7 @@ describe('WorkspaceHeader workspace switcher highlight', () => {
187180 it . each ( [ null , 'organization' ] ) (
188181 'keeps access requests out of the workspace switcher (%s)' ,
189182 ( organizationId ) => {
190- hostContext . hostOrganizationId = organizationId
191- render ( )
183+ render ( { workspaces : WORKSPACES . map ( ( workspace ) => ( { ...workspace , organizationId } ) ) } )
192184 expect ( document . body ) . not . toHaveTextContent ( 'My access requests' )
193185 expect ( document . body ) . not . toHaveTextContent ( 'Review access requests' )
194186 }
@@ -414,28 +406,24 @@ describe('WorkspaceHeader workspace switcher highlight', () => {
414406} )
415407
416408describe ( 'WorkspaceHeader context navigation' , ( ) => {
417- it ( 'links to the current host organization for enrolled members ', ( ) => {
418- hostContext . hostOrganizationId = ' host-org'
419- hostContext . viewer . isHostOrganizationMember = true
420- hostContext . features . organizationSearch = true
421- render ( )
422- expect ( document . querySelector ( 'a[href="/o/host-org "]' ) ) . toHaveTextContent (
423- 'Back to organization'
424- )
425- } )
409+ it . each ( [ null , 'another- organization', 'viewer-organization' ] ) (
410+ 'links to the viewer organization landing independently of workspace host %s' ,
411+ ( organizationId ) => {
412+ organizationList . data = [ { id : 'viewer-organization' } ]
413+ render ( { workspaces : WORKSPACES . map ( ( workspace ) => ( { ... workspace , organizationId } ) ) } )
414+ expect ( document . querySelector ( 'a[href="/o"]' ) ) . toHaveTextContent ( 'Back to organization' )
415+ expect ( document . querySelector ( 'a[href^="/o/"]' ) ) . toBeNull ( )
416+ }
417+ )
426418
427- it . each ( [
428- { org : null , member : true , enabled : true } ,
429- { org : 'host-org' , member : false , enabled : true } ,
430- { org : 'host-org' , member : true , enabled : false } ,
431- { org : 'host-org' , member : true , enabled : undefined } ,
432- ] ) ( 'hides inaccessible organization navigation: %j' , ( { org, member, enabled } ) => {
433- hostContext . hostOrganizationId = org
434- hostContext . viewer . isHostOrganizationMember = member
435- hostContext . features . organizationSearch = enabled
436- render ( )
437- expect ( document . querySelector ( 'a[href^="/o/"]' ) ) . toBeNull ( )
438- } )
419+ it . each ( [ [ ] , undefined ] ) (
420+ 'hides organization navigation without loaded memberships: %j' ,
421+ ( data ) => {
422+ organizationList . data = data
423+ render ( )
424+ expect ( document . body ) . not . toHaveTextContent ( 'Back to organization' )
425+ }
426+ )
439427
440428 it ( 'keeps settings in the profile menu instead of duplicating it in the switcher' , ( ) => {
441429 render ( )
0 commit comments