From 091f84a9477a926b3f7e8754ffc2238586fc8d90 Mon Sep 17 00:00:00 2001 From: Bartosz Kozikowski Date: Thu, 5 Nov 2026 15:37:36 +0100 Subject: [PATCH 1/2] Refresh navigation permissions when the workspace resolves --- src/app/navbar/Navbar.test.tsx | 48 ++++++++++++++++++++++++++++++++++ src/app/navbar/Navbar.tsx | 6 +++-- 2 files changed, 52 insertions(+), 2 deletions(-) create mode 100644 src/app/navbar/Navbar.test.tsx diff --git a/src/app/navbar/Navbar.test.tsx b/src/app/navbar/Navbar.test.tsx new file mode 100644 index 0000000..6a1f899 --- /dev/null +++ b/src/app/navbar/Navbar.test.tsx @@ -0,0 +1,48 @@ +import { render, screen } from '@testing-library/react'; +import { MemoryRouter } from 'react-router-dom'; +import Navbar from './Navbar'; + +const { workspace, hasAccessInOrganization } = vi.hoisted(() => ({ + workspace: { contextOrganizationId: null as string | null }, + hasAccessInOrganization: vi.fn((organizationId: string) => organizationId === 'owner-workspace'), +})); + +vi.mock('@/core/config/demo', () => ({ isDemo: true })); +vi.mock('@/modules/auth/AuthProvider', () => ({ + useAuth: () => ({ hasAccess: () => false, hasAccessInOrganization, userChosenLanguage: '' }), +})); +vi.mock('@/modules/organizations/WorkspaceProvider', () => ({ useWorkspace: () => workspace })); +vi.mock('react-i18next', () => ({ useTranslation: () => ({ t: (key: string) => key, i18n: {} }) })); +vi.mock('@/core/theme/logoImage', () => ({ default: () => null })); +vi.mock('./UserAvatarMenu', () => ({ default: () => null })); + +it('updates owner navigation when the current workspace resolves or changes', () => { + workspace.contextOrganizationId = null; + const view = ( + + + + ); + const { rerender } = render(view); + expect(screen.queryByRole('link', { name: 'common.clients' })).not.toBeInTheDocument(); + + workspace.contextOrganizationId = 'owner-workspace'; + rerender( + + + , + ); + expect(screen.getByRole('link', { name: 'common.clients' })).toHaveAttribute('href', '/clients'); + expect(screen.getByRole('link', { name: 'common.projects' })).toHaveAttribute('href', '/projects'); + expect(screen.getByRole('link', { name: 'common.reports' })).toHaveAttribute('href', '/report'); + + workspace.contextOrganizationId = 'another-workspace'; + rerender( + + + , + ); + expect(screen.queryByRole('link', { name: 'common.clients' })).not.toBeInTheDocument(); + expect(screen.queryByRole('link', { name: 'common.projects' })).not.toBeInTheDocument(); + expect(screen.queryByRole('link', { name: 'common.reports' })).not.toBeInTheDocument(); +}); diff --git a/src/app/navbar/Navbar.tsx b/src/app/navbar/Navbar.tsx index 84e0b0c..1a2267f 100644 --- a/src/app/navbar/Navbar.tsx +++ b/src/app/navbar/Navbar.tsx @@ -7,6 +7,7 @@ import MainContent from '@/core/theme/mainContent'; import { KeyBoardEventType, useKeyDown, useOnClickOutside } from '@/core/utils/hooks'; import { useAuth } from '@/modules/auth/AuthProvider'; import { clientsPaths } from '@/modules/clients/routes'; +import { useWorkspace } from '@/modules/organizations/WorkspaceProvider'; import { projectsPaths } from '@/modules/projects/routes'; import { reportPaths } from '@/modules/reports/report/routes'; import { teamSettingsPaths } from '@/modules/teamSettings/routes'; @@ -32,7 +33,8 @@ function Navbar(): JSX.Element { const params = useParams(); const auth = useAuth(); - const { hasAccess, userChosenLanguage } = auth; + const { hasAccessInOrganization, userChosenLanguage } = auth; + const { contextOrganizationId } = useWorkspace(); const [isMenuOpen, setIsMenuOpen] = useState(false); const menuRef = useRef(null); @@ -112,7 +114,7 @@ function Navbar(): JSX.Element { if (!item.requiredPermissions) return true; const requiredRoles = ROLE_PERMISSIONS[item.requiredPermissions]; - return hasAccess(requiredRoles); + return hasAccessInOrganization(contextOrganizationId ?? '', requiredRoles); }; return ( From 4dd5fb9146be95af550173586c8c1594581e276b Mon Sep 17 00:00:00 2001 From: Bartosz Kozikowski Date: Thu, 5 Nov 2026 15:45:37 +0100 Subject: [PATCH 2/2] Match navigation labels independently of SVG test placeholders --- src/app/navbar/Navbar.test.tsx | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/app/navbar/Navbar.test.tsx b/src/app/navbar/Navbar.test.tsx index 6a1f899..56791cd 100644 --- a/src/app/navbar/Navbar.test.tsx +++ b/src/app/navbar/Navbar.test.tsx @@ -24,7 +24,7 @@ it('updates owner navigation when the current workspace resolves or changes', () ); const { rerender } = render(view); - expect(screen.queryByRole('link', { name: 'common.clients' })).not.toBeInTheDocument(); + expect(screen.queryByRole('link', { name: /common\.clients/ })).not.toBeInTheDocument(); workspace.contextOrganizationId = 'owner-workspace'; rerender( @@ -32,9 +32,9 @@ it('updates owner navigation when the current workspace resolves or changes', () , ); - expect(screen.getByRole('link', { name: 'common.clients' })).toHaveAttribute('href', '/clients'); - expect(screen.getByRole('link', { name: 'common.projects' })).toHaveAttribute('href', '/projects'); - expect(screen.getByRole('link', { name: 'common.reports' })).toHaveAttribute('href', '/report'); + expect(screen.getByRole('link', { name: /common\.clients/ })).toHaveAttribute('href', '/clients'); + expect(screen.getByRole('link', { name: /common\.projects/ })).toHaveAttribute('href', '/projects'); + expect(screen.getByRole('link', { name: /common\.reports/ })).toHaveAttribute('href', '/report'); workspace.contextOrganizationId = 'another-workspace'; rerender( @@ -42,7 +42,7 @@ it('updates owner navigation when the current workspace resolves or changes', () , ); - expect(screen.queryByRole('link', { name: 'common.clients' })).not.toBeInTheDocument(); - expect(screen.queryByRole('link', { name: 'common.projects' })).not.toBeInTheDocument(); - expect(screen.queryByRole('link', { name: 'common.reports' })).not.toBeInTheDocument(); + expect(screen.queryByRole('link', { name: /common\.clients/ })).not.toBeInTheDocument(); + expect(screen.queryByRole('link', { name: /common\.projects/ })).not.toBeInTheDocument(); + expect(screen.queryByRole('link', { name: /common\.reports/ })).not.toBeInTheDocument(); });