From 0fad4fc1c31c19a0c24ae232a11751b985de2f59 Mon Sep 17 00:00:00 2001 From: Priyanka Date: Tue, 21 Nov 2023 16:14:41 +0530 Subject: [PATCH] UIU-2987 - add unit tests and update changelog --- CHANGELOG.md | 1 + .../PatronBlock/PatronBlock.test.js | 39 +++++++++++++------ .../UserAccounts/UserAccounts.test.js | 35 +++++++++++++++++ .../UserRequests/UserRequests.test.js | 16 ++++++++ src/views/UserDetail/UserDetail.test.js | 7 ++++ 5 files changed, 87 insertions(+), 11 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 899e9156f..afa987668 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,7 @@ * Also support `feesfines` interface version `19.0`. Refs UIU-2960. * Disable validation for shadow user. Refs UIU-3000. * Disable open loan actions for virtual patron. Refs UIU-2964. +* Hide all actionalble buttons on user details pane for DCB Virtual user. Refs UIU-2987. ## [10.0.4](https://github.com/folio-org/ui-users/tree/v10.0.4) (2023-11-10) [Full Changelog](https://github.com/folio-org/ui-users/compare/v10.0.3...v10.0.4) diff --git a/src/components/UserDetailSections/PatronBlock/PatronBlock.test.js b/src/components/UserDetailSections/PatronBlock/PatronBlock.test.js index 3dc3da4f2..b0a81cb88 100644 --- a/src/components/UserDetailSections/PatronBlock/PatronBlock.test.js +++ b/src/components/UserDetailSections/PatronBlock/PatronBlock.test.js @@ -1,4 +1,4 @@ -import { screen } from '@folio/jest-config-stripes/testing-library/react'; +import { act, screen } from '@folio/jest-config-stripes/testing-library/react'; import userEvent from '@folio/jest-config-stripes/testing-library/user-event'; import renderWithRouter from 'helpers/renderWithRouter'; @@ -52,20 +52,37 @@ const props = { }; describe('render ProxyPermissions component', () => { - beforeEach(() => { - renderPatronBlock(props); - }); it('Component must be rendered', () => { + renderPatronBlock(props); expect(screen.getByText('ui-users.settings.patronBlocks')).toBeInTheDocument(); }); it('Clicking the patron row should redirect via history.push', async () => { - await userEvent.click(document.querySelector('[data-row-inner="0"]')); + renderPatronBlock(props); + await act(async () => userEvent.click(document.querySelector('[data-row-inner="0"]'))); expect(mockRedirect).toHaveBeenCalled(); }); - /* Need to fix the bug UIU-2538 for the sorting to work so that this test case can be uncommented */ - - // it('checking for sort order', () => { - // userEvent.click(document.querySelector('[id="clickable-list-column-blockedactions"]')); - // expect(screen.getByText('Sample')).toBeInTheDocument(); - // }); + it('checking for sort order', () => { + renderPatronBlock(props); + userEvent.click(document.querySelector('[id="clickable-list-column-blockedactions"]')); + expect(screen.getByText('Sample')).toBeInTheDocument(); + }); + describe('when user is of type "dcb"', () => { + it('should not display "Create block" button', () => { + const alteredProps = { + ...props, + resources: { + selUser: { + records: [ + { + personal: { lastName: 'DcbSystem' }, + type: 'dcb' + } + ] + } + } + }; + renderPatronBlock(alteredProps); + expect(screen.queryByText('Create block')).toBeNull(); + }); + }); }); diff --git a/src/components/UserDetailSections/UserAccounts/UserAccounts.test.js b/src/components/UserDetailSections/UserAccounts/UserAccounts.test.js index fc3ae5a8c..c8466458d 100644 --- a/src/components/UserDetailSections/UserAccounts/UserAccounts.test.js +++ b/src/components/UserDetailSections/UserAccounts/UserAccounts.test.js @@ -60,4 +60,39 @@ describe('Render UserAccounts component', () => { renderUserAccounts(props(false)); expect(document.querySelector('[id="numOpenAccounts"]')).toBeNull(); }); + describe('when user is of type dcb', () => { + it('should not display "Create fee/fine" button', () => { + const alteredProps = { + accounts : { + records: [accounts], + isPending: false, + }, + accordionId: 'UserAccounts', + expanded: true, + onToggle: onToggleMock, + location: { + search: '', + path: '/userAccounts' + }, + match: { + params: { + id: '' + } + }, + resources: { + ...resources, + selUser: { + records: [ + { + personal: { lastName: 'DcbSystem' }, + type: 'dcb' + } + ] + }, + }, + }; + renderUserAccounts(alteredProps); + expect(screen.queryByText('Create fee/fine')).toBeNull(); + }); + }); }); diff --git a/src/components/UserDetailSections/UserRequests/UserRequests.test.js b/src/components/UserDetailSections/UserRequests/UserRequests.test.js index 62783fa91..132904ceb 100644 --- a/src/components/UserDetailSections/UserRequests/UserRequests.test.js +++ b/src/components/UserDetailSections/UserRequests/UserRequests.test.js @@ -126,4 +126,20 @@ describe('Render User Requests component', () => { renderUserRequests(props(false)); expect(screen.getByText('List Component')).toBeInTheDocument(); }); + + describe('when user is of type dcb', () => { + it('should not display "Create Request" button', () => { + const alteredProps = (perm) => { + return { + ...props(perm), + user: { + personal: { lastName: 'DcbSystem' }, + type: 'dcb' + }, + }; + }; + renderUserRequests(alteredProps(true)); + expect(screen.queryByText('Create Request')).toBeNull(); + }); + }); }); diff --git a/src/views/UserDetail/UserDetail.test.js b/src/views/UserDetail/UserDetail.test.js index e6b568c34..5a5d46c24 100644 --- a/src/views/UserDetail/UserDetail.test.js +++ b/src/views/UserDetail/UserDetail.test.js @@ -332,4 +332,11 @@ describe('UserDetail', () => { expect(screen.queryByText('ui-users.patronBlocks')).toBeNull(); }); }); + + describe('when user type is dcb', () => { + it('should not render action menu', () => { + renderUserDetail(stripes, { resources: { ...resources, selUser: { records: [{ ...resources.selUser.records[0], type: 'dcb', personal: { lastName: 'DcbSystem' } }] } } }); + expect(screen.queryByText('Actions')).toBeNull(); + }); + }); });