Skip to content

Commit

Permalink
Update unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ryandberger committed Jan 4, 2025
1 parent ee61c8f commit a35a39b
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions src/components/EditSections/EditUserRoles/EditUserRoles.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@ import { cleanup, waitFor } from '@folio/jest-config-stripes/testing-library/rea
import userEvent from '@folio/jest-config-stripes/testing-library/user-event';
import renderWithRouter from 'helpers/renderWithRouter';
import {
IfPermission,
useStripes,
} from '@folio/stripes/core';
import '__mock__/stripesCore.mock';
import { Form } from 'react-final-form';
import EditUserRoles from './EditUserRoles';

Expand All @@ -19,6 +21,7 @@ jest.mock('../../../hooks', () => ({
jest.mock('@folio/stripes/core', () => ({
...jest.requireActual('@folio/stripes/core'),
useStripes: jest.fn(),
IfPermission: jest.fn()
}));

jest.unmock('@folio/stripes/components');
Expand Down Expand Up @@ -95,6 +98,7 @@ describe('EditUserRoles Component', () => {
beforeEach(() => {
useStripes.mockClear().mockReturnValue(STRIPES);
useAllRolesData.mockClear().mockReturnValue(mockAllRolesData);
IfPermission.mockImplementation(({ children }) => children);
});
afterEach(cleanup);

Expand All @@ -106,6 +110,22 @@ describe('EditUserRoles Component', () => {
expect(queryByText('simple role')).not.toBeInTheDocument();
});

it('hides the roles accordion when user doesn\'t have view roles permission', () => {
IfPermission.mockImplementation(({ perm, children }) => (perm !== 'ui-authorization-roles.users.settings.view' ? children : null));
const { queryByText } = renderEditRolesAccordion(propsData);

expect(queryByText('ui-users.roles.userRoles')).not.toBeInTheDocument();
});

it('hides the add role button when user doesn\'t have manage roles permission', () => {
IfPermission.mockImplementation(({ perm, children }) => (perm !== 'ui-authorization-roles.users.settings.manage' ? children : null));
const { getByText, queryByText } = renderEditRolesAccordion(propsData);

expect(getByText('test role')).toBeInTheDocument();
expect(getByText('admin role')).toBeInTheDocument();
expect(queryByText('ui-users.roles.addRoles')).not.toBeInTheDocument();
});

it('calls delete user role function', async () => {
const id = `clickable-remove-user-role-${mockAllRolesData.data.roles[0].id}`;
renderEditRolesAccordion(propsData);
Expand Down

0 comments on commit a35a39b

Please sign in to comment.