Skip to content

Commit

Permalink
add unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
usavkov-epam committed Oct 17, 2023
1 parent 32eecc7 commit 299b416
Showing 1 changed file with 52 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ import { screen } from '@folio/jest-config-stripes/testing-library/react';
import { Form } from 'react-final-form';
import PropTypes from 'prop-types';

import buildStripes from '__mock__/stripes.mock';
import renderWithRouter from 'helpers/renderWithRouter';
import { USER_TYPES } from '../../../constants';
import EditExtendedInfo from './EditExtendedInfo';

jest.unmock('@folio/stripes/components');
Expand All @@ -22,7 +24,7 @@ const arrayMutators = {
update: jest.fn()
};

const renderEditExtendedInfo = (props) => {
const renderEditExtendedInfo = (props, initialValues) => {
const component = () => (
<>
<EditExtendedInfo {...props} />
Expand All @@ -35,6 +37,7 @@ const renderEditExtendedInfo = (props) => {
mutators={{
...arrayMutators
}}
initialValues={initialValues}
onSubmit={onSubmit}
render={component}
/>
Expand Down Expand Up @@ -67,6 +70,7 @@ const props = {
}],
values: {},
uniquenessValidator: {},
stripes: buildStripes(),
};
const DepartmentsName = ({ departments }) => {
return departments.map((dep) => {
Expand Down Expand Up @@ -125,4 +129,51 @@ describe('Render Extended User Information component', () => {
renderEditExtendedInfo({ ...props, disabled: true });
expect(screen.getAllByRole('textbox')[0]).toBeDisabled();
});

describe('Username field', () => {
it('should be required for users with the \'staff\' type in ECS mode', () => {
renderEditExtendedInfo(
{
...props,
stripes: {
...props.stripes,
hasInterface: () => true,
},
},
{ type: USER_TYPES.STAFF }
);

expect(screen.getByRole('textbox', { name: 'ui-users.information.username' })).toBeRequired();
});

it('should NOT be required if user type is other than \'staff\' in ECS mode', () => {
renderEditExtendedInfo(
{
...props,
stripes: {
...props.stripes,
hasInterface: () => true,
},
},
{ type: USER_TYPES.PATRON }
);

expect(screen.getByRole('textbox', { name: 'ui-users.information.username' })).not.toBeRequired();
});

it('should NOT be required in default mode (non ECS)', () => {
renderEditExtendedInfo(
{
...props,
stripes: {
...props.stripes,
hasInterface: (i) => i !== 'consortia',
},
},
{ type: USER_TYPES.STAFF }
);

expect(screen.getByRole('textbox', { name: 'ui-users.information.username' })).not.toBeRequired();
});
});
});

0 comments on commit 299b416

Please sign in to comment.