Skip to content

Commit

Permalink
test: DocumentFilterField test (Leaving rules testing to M)
Browse files Browse the repository at this point in the history
  • Loading branch information
EthanFreestone committed Oct 29, 2024
1 parent 50697df commit 6b0e747
Showing 1 changed file with 57 additions and 31 deletions.
88 changes: 57 additions & 31 deletions lib/DocumentFilter/DocumentFilterField.test.js
Original file line number Diff line number Diff line change
@@ -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',
Expand All @@ -27,44 +30,67 @@ const categoryValues = [

let renderComponent;
describe('DocumentFilterField', () => {
beforeEach(() => {
renderComponent = renderWithIntl(
<MemoryRouter>
<TestForm initialValues={{}} onSubmit={onSubmit}>
<FieldArray name="filters">
[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(
<MemoryRouter>
<TestForm
initialValues={{
filters: initalFilters
}}
onSubmit={onSubmit}
>
<FieldArray name="filters">
{({ fields }) => fields.map((name, index) => (
<DocumentFilterField
key={`${name}[${index}]`}
categoryValues={categoryValues}
name={name}
filterName="docs"
index={index}
name={name}
/>
}
]
</FieldArray>
</TestForm>
,
</MemoryRouter>,
translationsProperties
);
});
))}
</FieldArray>
</TestForm>
,
</MemoryRouter>,
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
}
});
});

0 comments on commit 6b0e747

Please sign in to comment.