forked from openedx/frontend-app-admin-console
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathLibrariesUserManager.test.tsx
More file actions
92 lines (81 loc) · 2.61 KB
/
LibrariesUserManager.test.tsx
File metadata and controls
92 lines (81 loc) · 2.61 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
import { useParams } from 'react-router-dom';
import { screen } from '@testing-library/react';
import { renderWrapper } from '@src/setupTest';
import LibrariesUserManager from './LibrariesUserManager';
import { useLibraryAuthZ } from './context';
import { useLibrary, useTeamMembers } from '../data/hooks';
jest.mock('react-router-dom', () => ({
...jest.requireActual('react-router-dom'),
useParams: jest.fn(),
}));
jest.mock('./context', () => ({
useLibraryAuthZ: jest.fn(),
}));
jest.mock('../data/hooks', () => ({
useLibrary: jest.fn(),
useTeamMembers: jest.fn(),
}));
jest.mock('../components/RoleCard', () => ({
__esModule: true,
default: ({ title, description }: { title: string, description: string }) => (
<div data-testid="role-card">
<div>{title}</div>
<div>{description}</div>
</div>
),
}));
describe('LibrariesUserManager', () => {
beforeEach(() => {
jest.clearAllMocks();
// Mock route params
(useParams as jest.Mock).mockReturnValue({ username: 'testuser' });
// Mock library authz context
(useLibraryAuthZ as jest.Mock).mockReturnValue({
libraryId: 'lib:123',
permissions: [{ key: 'view' }, { key: 'reuse' }],
roles: [
{
role: 'admin',
name: 'Admin',
description: 'Administrator Role',
permissions: ['view', 'reuse'],
},
],
resources: [
{ key: 'library', label: 'Library', description: '' },
],
});
// Mock library data
(useLibrary as jest.Mock).mockReturnValue({
data: {
title: 'Test Library',
org: 'Test Org',
},
});
// Mock team members
(useTeamMembers as jest.Mock).mockReturnValue({
data: {
results: [
{
username: 'testuser',
email: '[email protected]',
roles: ['admin'],
},
],
},
});
});
it('renders the user roles correctly', () => {
renderWrapper(<LibrariesUserManager />);
// Breadcrumb check
expect(screen.getByText('Manage Access')).toBeInTheDocument();
expect(screen.getByText('Library Team Management')).toBeInTheDocument();
expect(screen.getByRole('listitem', { current: 'page' })).toHaveTextContent('testuser');
// Page title and subtitle
expect(screen.getByRole('heading', { level: 1 })).toHaveTextContent('testuser');
expect(screen.getByRole('paragraph')).toHaveTextContent('[email protected]');
// RoleCard rendering
expect(screen.getByTestId('role-card')).toHaveTextContent('Admin');
expect(screen.getByTestId('role-card')).toHaveTextContent('Administrator Role');
});
});