forked from openedx/frontend-app-admin-console
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathindex.test.tsx
More file actions
74 lines (65 loc) · 2.91 KB
/
index.test.tsx
File metadata and controls
74 lines (65 loc) · 2.91 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
import React from 'react';
import { screen } from '@testing-library/react';
import { useAllRoleAssignments, useOrgs, useScopes } from '@src/authz-module/data/hooks';
import { renderWithAllProviders } from '@src/setupTest';
import userEvent from '@testing-library/user-event';
import { ToastManagerProvider } from '@src/components/ToastManager/ToastManagerContext';
import AuthzHome from './index';
import messages from './messages';
jest.mock('@src/authz-module/data/hooks', () => ({
useAllRoleAssignments: jest.fn(),
useOrgs: jest.fn(),
useScopes: jest.fn(),
}));
const emptyResponse = {
data: {
results: [], count: 0, next: null, previous: null,
},
error: null,
isLoading: false,
refetch: jest.fn(),
};
const renderAuthzHome = () => renderWithAllProviders(
<ToastManagerProvider>
<AuthzHome />
</ToastManagerProvider>,
);
describe('AuthzHome', () => {
beforeEach(() => {
(useAllRoleAssignments as jest.Mock).mockReturnValue(emptyResponse);
(useOrgs as jest.Mock).mockReturnValue(emptyResponse);
(useScopes as jest.Mock).mockReturnValue(emptyResponse);
});
it('renders without crashing', () => {
renderAuthzHome();
});
it('renders the main layout and tabs', () => {
renderAuthzHome();
expect(screen.getByText(messages['authz.manage.page.title'].defaultMessage)).toBeInTheDocument();
expect(screen.getByText(messages['authz.tabs.permissionsRoles'].defaultMessage)).toBeInTheDocument();
expect(screen.getByText(messages['authz.tabs.team'].defaultMessage)).toBeInTheDocument();
});
it('renders both tab panels', () => {
renderAuthzHome();
expect(screen.getByText(messages['authz.tabs.permissionsRoles'].defaultMessage)).toBeInTheDocument();
expect(screen.getByText(messages['authz.tabs.team'].defaultMessage)).toBeInTheDocument();
expect(screen.getAllByRole('tab')).toHaveLength(3); // 2 + tab invisible for more...
});
it('renders the RolesPermissions component in the permissions tab', async () => {
const user = userEvent.setup();
renderAuthzHome();
await user.click(screen.getByText(messages['authz.tabs.permissionsRoles'].defaultMessage));
expect(screen.getByRole('button', { name: 'Courses' })).toBeInTheDocument();
expect(screen.getByRole('button', { name: 'Libraries' })).toBeInTheDocument();
});
it('renders the TeamMembersTable component in the team members tab', () => {
renderAuthzHome();
expect(screen.getByText(messages['authz.manage.page.title'].defaultMessage)).toBeInTheDocument();
expect(screen.getByText('Name')).toBeInTheDocument();
expect(screen.getByText('Email')).toBeInTheDocument();
expect(screen.getAllByText('Organization').length).toBe(2); // Header and org filter;
expect(screen.getAllByText('Scope').length).toBe(2); // Header and scope filter;
expect(screen.getAllByText('Role').length).toBe(2); // Header and role filter;
expect(screen.getByText('Actions')).toBeInTheDocument();
});
});