Skip to content

Commit a05b6eb

Browse files
committed
✨(frontend) conditionally hide preferences link for Keycloak backend
Hide the "My preferences" link in the dashboard sidebar when using the Keycloak authentication backend, as preferences are not supported in this context.
1 parent 6385e01 commit a05b6eb

File tree

3 files changed

+35
-9
lines changed

3 files changed

+35
-9
lines changed

src/frontend/js/api/auth/keycloak.spec.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,8 @@ describe('Keycloak API', () => {
4242
client_id: 'richie-client',
4343
realm: 'richie-realm',
4444
auth_url: 'https://keycloak.test/auth/realms/richie-realm/protocol/openid-connect/auth',
45-
registration_url: 'https://keycloak.test/auth/realms/richie-realm/protocol/openid-connect/registrations',
45+
registration_url:
46+
'https://keycloak.test/auth/realms/richie-realm/protocol/openid-connect/registrations',
4647
};
4748

4849
let keycloakApi: ReturnType<typeof API>;

src/frontend/js/widgets/Dashboard/components/LearnerDashboardSidebar/index.tsx

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ import {
77
DashboardSidebarProps,
88
} from 'widgets/Dashboard/components/DashboardSidebar';
99
import { useSession } from 'contexts/SessionContext';
10+
import { APIBackend } from 'types/api';
11+
import context from 'utils/context';
1012
import { UserHelper } from 'utils/UserHelper';
1113

1214
import { LearnerDashboardPaths } from 'widgets/Dashboard/utils/learnerRoutesPaths';
@@ -30,15 +32,18 @@ export const LearnerDashboardSidebar = (props: Partial<DashboardSidebarProps>) =
3032

3133
const getRouteLabel = getDashboardRouteLabel(intl);
3234

35+
const dashboardPaths = [
36+
LearnerDashboardPaths.COURSES,
37+
LearnerDashboardPaths.CERTIFICATES,
38+
LearnerDashboardPaths.CONTRACTS,
39+
LearnerDashboardPaths.BATCH_ORDERS,
40+
];
41+
if (context?.authentication.backend !== APIBackend.KEYCLOAK) {
42+
dashboardPaths.push(LearnerDashboardPaths.PREFERENCES);
43+
}
3344
const links = useMemo(
3445
() =>
35-
[
36-
LearnerDashboardPaths.COURSES,
37-
LearnerDashboardPaths.CERTIFICATES,
38-
LearnerDashboardPaths.CONTRACTS,
39-
LearnerDashboardPaths.PREFERENCES,
40-
LearnerDashboardPaths.BATCH_ORDERS,
41-
].map((path) => ({
46+
dashboardPaths.map((path) => ({
4247
to: generatePath(path),
4348
label: getRouteLabel(path),
4449
activePaths:

src/frontend/js/widgets/Dashboard/index.spec.tsx

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { getByText, screen } from '@testing-library/react';
1+
import { getByText, queryByText, screen } from '@testing-library/react';
22
import fetchMock from 'fetch-mock';
33
import userEvent from '@testing-library/user-event';
44
import {
@@ -17,6 +17,7 @@ import { createTestQueryClient } from 'utils/test/createTestQueryClient';
1717
import { BaseJoanieAppWrapper } from 'utils/test/wrappers/BaseJoanieAppWrapper';
1818
import { expectNoSpinner } from 'utils/test/expectSpinner';
1919
import { LearnerDashboardPaths } from 'widgets/Dashboard/utils/learnerRoutesPaths';
20+
import context from 'utils/context';
2021
import { DashboardTest } from './components/DashboardTest';
2122

2223
jest.mock('utils/context', () => ({
@@ -210,4 +211,23 @@ describe('<Dashboard />', () => {
210211
expectUrlMatchLocationDisplayed('/dummy/route');
211212
expect(screen.getByRole('heading', { name: /Page not found/ }));
212213
});
214+
215+
it('should not show preferences link when using keycloak backend', async () => {
216+
// Temporarily change the authentication backend to keycloak
217+
const originalBackend = context.authentication.backend;
218+
context.authentication.backend = 'keycloak';
219+
220+
render(<DashboardTest initialRoute={LearnerDashboardPaths.COURSES} />, {
221+
wrapper: BaseJoanieAppWrapper,
222+
});
223+
await expectNoSpinner('Loading orders and enrollments...');
224+
225+
const sidebar = screen.getByTestId('dashboard__sidebar');
226+
227+
// Verify that "My preferences" link is NOT present in the sidebar
228+
expect(queryByText(sidebar, 'My preferences')).toBeNull();
229+
230+
// Restore original backend
231+
context.authentication.backend = originalBackend;
232+
});
213233
});

0 commit comments

Comments
 (0)