From 95f91f4f2b8323185b82f82f3a7b45b1ff85b534 Mon Sep 17 00:00:00 2001 From: MonireRasouli Date: Fri, 20 Dec 2024 16:13:44 +0000 Subject: [PATCH] add test for DocumentFilterArray --- .../DocumentFilterArray.test.js | 124 ++++++++++++++++++ 1 file changed, 124 insertions(+) create mode 100644 lib/DocumentFilter/DocumentFilterArray.test.js diff --git a/lib/DocumentFilter/DocumentFilterArray.test.js b/lib/DocumentFilter/DocumentFilterArray.test.js new file mode 100644 index 00000000..ba1b4d4e --- /dev/null +++ b/lib/DocumentFilter/DocumentFilterArray.test.js @@ -0,0 +1,124 @@ +import { MemoryRouter } from 'react-router-dom'; +import { screen } from'@testing-library/react'; +import { waitFor } from '@folio/jest-config-stripes/testing-library/react'; +import { renderWithIntl, Button, TestForm, Dropdown} from '@folio/stripes-erm-testing'; + +import { translationsProperties } from '../../test/jest/helpers'; + +import DocumentFilterArray from './DocumentFilterArray'; +const handleSubmit = jest.fn(); +const translatedContentOptions = [ + { + "value": "alternateNames", + "label": "Alternative names" + }, + { + "value": "agreementContentTypes", + "label": "Content types" + }, + { + "value": "contacts", + "label": "Internal contacts" + }, + { + "value": "orgs", + "label": "Organizations" + }, + { + "value": "items", + "label": "Agreement lines" + }, + { + "value": "linkedLicenses", + "label": "Linked licenses" + }, + { + "value": "externalLicenseDocs", + "label": "External licenses" + }, + { + "value": "supplementaryDocs", + "label": "Supplementary documents" + }, + { + "value": "usageDataProviders", + "label": "Usage data" + }, + { + "value": "relatedAgreements", + "label": "Related agreements" + }, + { + "value": "tags", + "label": "Tags" + } +]; +const onSubmit = jest.fn(); +jest.mock('./DocumentFilterField', () => () =>
DocumentFilterField
); + +let renderComponent; +describe('DocumentFilterArray', () => { + beforeEach(() => { + renderComponent = renderWithIntl( + + + + , + , + translationsProperties + ); + }); + + test('renders the And/Or dropdown button', async () => { + await Dropdown('Add filter').exists(); + }); + + describe('clicking \'Add filter\' button', () => { + beforeEach(async () => { + await waitFor(async () => { + await Button('Add filter').click(); + }); + }); + + it('should render the \'AND\' and \'OR\' dropdown buttons', async () => { + await Button('AND').exists(); + await Button('OR').exists(); + }); + }); + + describe('clicking \'OR\' button', () => { + beforeEach(async () => { + await waitFor(async () => { + await Button('Add filter').click(); + await Button('OR').click(); + }); + }); + + it('should display the OR label', async () => { + const { getAllByText } = renderComponent; + await waitFor(async () => { + expect(getAllByText('OR').length).toEqual(2); + }); + }); + }); + + describe('clicking \'AND\' button', () => { + beforeEach(async () => { + await waitFor(async () => { + await Button('Add filter').click(); + await Button('AND').click(); + }); + }); + + it('should display the AND label', async () => { + const { getAllByText } = renderComponent; + await waitFor(async () => { + expect(getAllByText('AND').length).toEqual(2); + }); + }); + }); +});