From 6b0e7471867fa67cf045094972cf971509f42e5a Mon Sep 17 00:00:00 2001 From: Ethan Freestone Date: Tue, 29 Oct 2024 17:28:43 +0000 Subject: [PATCH] test: DocumentFilterField test (Leaving rules testing to M) --- .../DocumentFilterField.test.js | 88 ++++++++++++------- 1 file changed, 57 insertions(+), 31 deletions(-) diff --git a/lib/DocumentFilter/DocumentFilterField.test.js b/lib/DocumentFilter/DocumentFilterField.test.js index 5843272f..c4314393 100644 --- a/lib/DocumentFilter/DocumentFilterField.test.js +++ b/lib/DocumentFilter/DocumentFilterField.test.js @@ -1,12 +1,15 @@ import { MemoryRouter } from 'react-router-dom'; +import { FieldArray } from 'react-final-form-arrays'; import { renderWithIntl, Button, TestForm } from '@folio/stripes-erm-testing'; import { translationsProperties } from '../../test/jest/helpers'; import DocumentFilterField from './DocumentFilterField'; +import { documentFilterParsing } from './testResources'; const onSubmit = jest.fn(); +// These should be centralised const categoryValues = [ { 'id': '2c9180a09262108601926219be050022', @@ -27,44 +30,67 @@ const categoryValues = [ let renderComponent; describe('DocumentFilterField', () => { - beforeEach(() => { - renderComponent = renderWithIntl( - - - - [fields.map({ name, index}) - { + describe.each([ + { + initalFilters: documentFilterParsing.find(dfp => dfp.name === 'complex').parsed, + expectedFields: 2 + }, + { + initalFilters: documentFilterParsing.find(dfp => dfp.name === 'simple').parsed, + expectedFields: 1 + }, + { + initalFilters: [], + expectedFields: 0 + } + ])('Render DocumentFilterField with $expectedFields in the array', ({ initalFilters, expectedFields }) => { + beforeEach(() => { + renderComponent = renderWithIntl( + + + + {({ fields }) => fields.map((name, index) => ( - } - ] - - - , - , - translationsProperties - ); - }); + ))} + + + , + , + translationsProperties + ); + }); - it('display attibute label', () => { - const { getByText } = renderComponent; - expect(getByText('Attribute')).toBeInTheDocument(); - }); + it('displays attibute label(s)', () => { + const { queryAllByText } = renderComponent; + expect(queryAllByText('Attribute')).toHaveLength(expectedFields); + }); - it('display operator label', () => { - const { getByText } = renderComponent; - expect(getByText('Operator')).toBeInTheDocument(); - }); + it('displays operator label(s)', () => { + const { queryAllByText } = renderComponent; + expect(queryAllByText('Operator')).toHaveLength(expectedFields); + }); - it('display value label', () => { - const { getByText } = renderComponent; - expect(getByText('Value')).toBeInTheDocument(); - }); + it('displays value label(s)', () => { + const { queryAllByText } = renderComponent; + expect(queryAllByText('Value')).toHaveLength(expectedFields); + }); - test('renders the add rule button', async () => { - await Button('Add rule').exists(); + if (expectedFields > 0) { + test('renders the add rule button', async () => { + await Button('Add rule').exists(); + }); + // TODO Mock DocumentFilterRule and check that you can add rules, that the right number show up and that they're separated by ANDs + } }); });