Skip to content

Commit 49aeb2c

Browse files
committed
feat: simplify AssignRoleWizardPage tests by removing scope handling and updating navigation path
1 parent dbf60c8 commit 49aeb2c

2 files changed

Lines changed: 6 additions & 33 deletions

File tree

src/authz-module/wizard/AssignRoleWizard.test.tsx

Lines changed: 1 addition & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ const permissionsFor = ({ library = false, course = false } = {}) => [
100100
];
101101

102102
const renderWizard = (props = {}) => renderWrapper(
103-
<AssignRoleWizard onClose={jest.fn()} scope="lib:123" {...props} />,
103+
<AssignRoleWizard onClose={jest.fn()} {...props} />,
104104
);
105105

106106
describe('AssignRoleWizard — Step 1', () => {
@@ -128,27 +128,6 @@ describe('AssignRoleWizard — Step 1', () => {
128128
expect(screen.getByTestId('users-input')).toHaveValue('alice');
129129
});
130130

131-
it('shows only library roles when user only has manage_library_team permission', () => {
132-
mockUseValidateUserPermissions.mockReturnValue({ data: permissionsFor({ library: true }) });
133-
renderWizard();
134-
expect(screen.getByTestId('role-option-library_admin')).toBeInTheDocument();
135-
expect(screen.queryByTestId('role-option-course_admin')).not.toBeInTheDocument();
136-
});
137-
138-
it('shows only course roles when user only has manage_course_team permission', () => {
139-
mockUseValidateUserPermissions.mockReturnValue({ data: permissionsFor({ course: true }) });
140-
renderWizard();
141-
expect(screen.getByTestId('role-option-course_admin')).toBeInTheDocument();
142-
expect(screen.queryByTestId('role-option-library_admin')).not.toBeInTheDocument();
143-
});
144-
145-
it('shows both course and library roles when user has both permissions', () => {
146-
mockUseValidateUserPermissions.mockReturnValue({ data: permissionsFor({ library: true, course: true }) });
147-
renderWizard();
148-
expect(screen.getByTestId('role-option-library_admin')).toBeInTheDocument();
149-
expect(screen.getByTestId('role-option-course_admin')).toBeInTheDocument();
150-
});
151-
152131
it('selecting a different role replaces the previous selection', async () => {
153132
const user = userEvent.setup();
154133
mockUseValidateUserPermissions.mockReturnValue({ data: permissionsFor({ library: true, course: true }) });

src/authz-module/wizard/AssignRoleWizardPage.test.tsx

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ jest.mock('../data/hooks', () => ({
1616

1717
jest.mock('./AssignRoleWizard', () => ({
1818
__esModule: true,
19-
default: ({ scope, initialUsers, onClose }: { scope: string; initialUsers?: string; onClose: () => void }) => (
20-
<div data-testid="assign-role-wizard" data-scope={scope} data-users={initialUsers}>
19+
default: ({ initialUsers, onClose }: { initialUsers?: string; onClose: () => void }) => (
20+
<div data-testid="assign-role-wizard" data-users={initialUsers}>
2121
<button type="button" data-testid="wizard-close" onClick={onClose}>Close</button>
2222
Assign Role Wizard
2323
</div>
@@ -54,18 +54,12 @@ describe('AssignRoleWizardPage', () => {
5454
jest.clearAllMocks();
5555
});
5656

57-
it('renders the wizard when scope and library are present', () => {
57+
it('renders the wizard when library is present', () => {
5858
setupMocks();
5959
renderWrapper(<AssignRoleWizardPage />);
6060
expect(screen.getByTestId('assign-role-wizard')).toBeInTheDocument();
6161
});
6262

63-
it('passes scope to the wizard', () => {
64-
setupMocks({ scope: 'lib:456' });
65-
renderWrapper(<AssignRoleWizardPage />);
66-
expect(screen.getByTestId('assign-role-wizard')).toHaveAttribute('data-scope', 'lib:456');
67-
});
68-
6963
it('passes initialUsers from search params to the wizard', () => {
7064
setupMocks({ users: 'alice,bob' });
7165
renderWrapper(<AssignRoleWizardPage />);
@@ -78,7 +72,7 @@ describe('AssignRoleWizardPage', () => {
7872
expect(screen.getByRole('heading', { name: 'Assign Role' })).toBeInTheDocument();
7973
});
8074

81-
it('navigates to team members path when wizard onClose is triggered', async () => {
75+
it('navigates to home path when wizard onClose is triggered', async () => {
8276
setupMocks();
8377
const mockNavigate = jest.fn();
8478
const { useNavigate } = jest.requireMock('react-router-dom');
@@ -88,6 +82,6 @@ describe('AssignRoleWizardPage', () => {
8882
renderWrapper(<AssignRoleWizardPage />);
8983
await user.click(screen.getByTestId('wizard-close'));
9084

91-
expect(mockNavigate).toHaveBeenCalledWith('/authz/libraries/lib:123');
85+
expect(mockNavigate).toHaveBeenCalledWith('/authz');
9286
});
9387
});

0 commit comments

Comments
 (0)