From 4aee2af0282f29837b4fee335d663b86c937ae3d Mon Sep 17 00:00:00 2001 From: Priyanka Terala Date: Fri, 27 Dec 2024 17:02:36 +0530 Subject: [PATCH] fix test --- src/UserSearchModal.test.js | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/src/UserSearchModal.test.js b/src/UserSearchModal.test.js index 0e2d7fd..a238b25 100644 --- a/src/UserSearchModal.test.js +++ b/src/UserSearchModal.test.js @@ -1,8 +1,11 @@ -import { screen, render } from '@folio/jest-config-stripes/testing-library/react'; -import { useRef } from 'react'; +import { screen, render, waitFor } from '@folio/jest-config-stripes/testing-library/react'; +import userEvent from '@folio/jest-config-stripes/testing-library/user-event'; +import { createRef } from 'react'; import UserSearchModal from './UserSearchModal'; +jest.unmock('@folio/stripes/components'); + jest.mock('./UserSearchContainer', () => { return jest.fn(() =>
UserSearchContainer
); }); @@ -20,30 +23,30 @@ const props = { onCloseModal: jest.fn(), openWhen: true, restoreFocus: true, - initialSelectedUsers, + initialSelectedUsers: undefined, tenantId: 'diku', -}; +}; describe('UserSearchModal', () => { beforeEach(() => { - const modalRef = useRef(); + const modalRef = createRef(); - render(); + render(); }); it('should display search label', () => { - expect(screen.getByText('ui-plugin-find-user.searchFieldLabel')).toBeInTheDocument(); + expect(screen.getByText('ui-plugin-find-user.modal.label')).toBeInTheDocument(); }); it('should render "UserSearchContainer"', () => { expect(screen.getByText('UserSearchContainer')).toBeInTheDocument(); }); - it('close modal on clicking close button', () => { - const button = screen.getByRole('button', { name: 'Dismiss modal' }); + it('close modal on clicking close button', async () => { + const button = screen.getByRole('button', { name: 'stripes-components.dismissModal' }); expect(button).toBeInTheDocument(); - button.click(); - expect(screen.getByText('UserSearchContainer')).not.toBeInTheDocument(); + userEvent.click(button); + await waitFor(() => expect(props.closeCB).toHaveBeenCalled()); }); });