Skip to content

Commit

Permalink
UIU-3114 - add unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
Terala-Priyanka committed May 7, 2024
1 parent 6922891 commit 34f956c
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,8 @@ const ReadingRoomAccess = (props) => {
metadata={rra.metadata}
>
{
(updater) => lastUpdatedDetails(updater?.lastUpdatedBy, rra.metadata.updatedDate)
}
(updater) => lastUpdatedDetails(updater?.lastUpdatedBy, rra.metadata.updatedDate)
}
</ViewMetaData>
) :
<NoValue />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ import { screen, render, fireEvent, waitFor } from '@folio/jest-config-stripes/t
import ReadingRoomAccess from './ReadingRoomAccess';

jest.unmock('@folio/stripes/components');
jest.unmock('@folio/stripes/smart-components');

jest.mock('@folio/stripes/components', () => ({
...jest.requireActual('@folio/stripes/components'),
SearchField: jest.fn((props) => (
Expand All @@ -11,6 +13,23 @@ jest.mock('@folio/stripes/components', () => ({
/>
)),
}));
jest.mock('@folio/stripes/smart-components', () => ({
...jest.requireActual('@folio/stripes/smart-components'),
ViewMetaData: (props) => {
if (props.children) {
return props.children({
lastUpdatedBy: {
personal: {
lastName: 'lastName',
firstName: 'firstName'
}
}
});
}
return <div>ViewMetaData</div>;
}

}));

const mockedRRAData = [
{
Expand All @@ -20,15 +39,16 @@ const mockedRRAData = [
'access': 'NOT_ALLOWED'
},
{
'id': '2205005b-ca51-4a04-87fd-938eefaf86de',
'id': '2205005b-ca51-4a04-87fd-938eefa8f6de',
'userId': '2205005b-ca51-4a04-87fd-938eefa8f6de',
'readingRoomId': 'ef1b8f7f-afb3-4454-bc3a-4c9989fcf977',
'readingRoomName': 'reading room2',
'access': 'NOT_ALLOWED',
'readingRoomId': '4f711485-4408-4bc9-8f67-9a9f37bce2f8',
'readingRoomName': 'reading room 1',
'access': 'ALLOWED',
'notes': 'In Review',
'metadata': {
'createdDate': '2024-05-03T09:18:16.221500',
'createdDate': '2024-05-07T06:15:17.005013',
'createdByUserId': '21457ab5-4635-4e56-906a-908f05e9233b',
'updatedDate': '2024-05-03T09:18:52.016583',
'updatedDate': '2024-05-07T06:15:38.838042',
'updatedByUserId': '21457ab5-4635-4e56-906a-908f05e9233b'
}
},
Expand Down Expand Up @@ -64,9 +84,13 @@ describe('ReadingRoomAccess', () => {
it('should filter MCL records "Name" column, based on the string entered in search box', async () => {
render(<ReadingRoomAccess {...alteredProps} />);
const inputEl = screen.getByPlaceholderText('ui-users.readingRoom.filter');
fireEvent.change(inputEl, { target: { value: '1' } });
fireEvent.change(inputEl, { target: { value: 'room1' } });
const numOfRows = document.querySelectorAll('[class^="mclRowFormatterContainer"]').length;
console.log('numOfRows ', numOfRows);
await waitFor(() => expect(numOfRows).toBe(1));
});

it('should render updated date', () => {
render(<ReadingRoomAccess {...alteredProps} />);
expect(screen.getByText('ui-users.reading-room-access.metaSection.lastUpdatedDetails')).toBeDefined();
});
});

0 comments on commit 34f956c

Please sign in to comment.