-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ERM-3395, Complete absent test cases for stripes-erm-components docum…
…ent filter (#709) * extend DocumentFilter tests * extend tests * extend tests for DocumentFilterFieldArray * extend tests for DocumentFilterRule * tweak * fix tests * fix tests for DocumentFilterFieldArray * test: DocumentFilterField test tweaks * ci: Update centralised workflow to 1.6 * test: DocumentFilterFieldArray test tweaks * test: Monireh's changes (not pushed originally) * test: DocumentFilterForm test tweaks * test: stripes-erm-testing testSelect Make use of new testSelect feature in stripes-erm-testing (Bump major version of stripes-erm-testing) * test: DocumentFilterRule test Tweaked test case for DocumentFilterRule to align with describe-action, test-outcome paradigm ERM-3395 * chore: Javascript-ify some JSON --------- Co-authored-by: Ethan Freestone <[email protected]>
- Loading branch information
1 parent
241dc35
commit accf810
Showing
11 changed files
with
323 additions
and
221 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,96 +1,112 @@ | ||
import { MemoryRouter } from 'react-router-dom'; | ||
import { FieldArray } from 'react-final-form-arrays'; | ||
|
||
import { renderWithIntl, Button, TestForm } from '@folio/stripes-erm-testing'; | ||
import { screen, waitFor } from '@folio/jest-config-stripes/testing-library/react'; | ||
import { renderWithIntl, TestForm, Button } from '@folio/stripes-erm-testing'; | ||
|
||
import { translationsProperties } from '../../test/jest/helpers'; | ||
import { categoryValues } from '../../test/jest/resources'; | ||
|
||
import DocumentFilterField from './DocumentFilterField'; | ||
import { documentFilterParsing } from './testResources'; | ||
|
||
const onSubmit = jest.fn(); | ||
|
||
// These should be centralised | ||
const categoryValues = [ | ||
{ | ||
'id': '2c9180a09262108601926219be050022', | ||
'value': 'consortium_negotiation_document', | ||
'label': 'Consortium negotiation document', | ||
}, | ||
{ | ||
'id': '2c9180a09262108601926219bdfc0020', | ||
'value': 'license', | ||
'label': 'License', | ||
}, | ||
{ | ||
'id': '2c9180a09262108601926219be010021', | ||
'value': 'misc', | ||
'label': 'Misc', | ||
}, | ||
]; | ||
jest.mock('./DocumentFilterRule', () => () => <div>DocumentFilterRule</div>); | ||
|
||
let renderComponent; | ||
describe('DocumentFilterField', () => { | ||
describe.each([ | ||
{ | ||
initalFilters: documentFilterParsing.find(dfp => dfp.name === 'complex').parsed, | ||
expectedFields: 2 | ||
initialFilters: [], | ||
expectedFields: 0, | ||
expectedRules: 0, | ||
}, | ||
{ | ||
initalFilters: documentFilterParsing.find(dfp => dfp.name === 'simple').parsed, | ||
expectedFields: 1 | ||
initialFilters: documentFilterParsing.find((dfp) => dfp.name === 'simple') | ||
.parsed, | ||
expectedFields: 1, | ||
expectedRules: 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} | ||
filterName="docs" | ||
index={index} | ||
name={name} | ||
/> | ||
))} | ||
</FieldArray> | ||
</TestForm> | ||
, | ||
</MemoryRouter>, | ||
translationsProperties | ||
); | ||
}); | ||
initialFilters: documentFilterParsing.find((dfp) => dfp.name === 'complex') | ||
.parsed, | ||
expectedFields: 2, | ||
expectedRules: 3, | ||
}, | ||
])( | ||
'Render $expectedFields DocumentFilterField component(s)', | ||
({ initialFilters, expectedFields, expectedRules }) => { | ||
beforeEach(() => { | ||
renderComponent = renderWithIntl( | ||
<MemoryRouter> | ||
<TestForm | ||
initialValues={{ | ||
filters: initialFilters, | ||
}} | ||
onSubmit={onSubmit} | ||
> | ||
<FieldArray name="filters"> | ||
{({ fields }) => fields.map((name, index) => ( | ||
<DocumentFilterField | ||
key={`${name}[${index}]`} | ||
categoryValues={categoryValues} | ||
filterName="docs" | ||
index={index} | ||
name={name} | ||
/> | ||
)) | ||
} | ||
</FieldArray> | ||
</TestForm> | ||
, | ||
</MemoryRouter>, | ||
translationsProperties | ||
); | ||
}); | ||
|
||
it('displays attibute label(s)', () => { | ||
const { queryAllByText } = renderComponent; | ||
expect(queryAllByText('Attribute')).toHaveLength(expectedFields); | ||
}); | ||
it('displays attribute label(s)', () => { | ||
const { queryAllByText } = renderComponent; | ||
expect(queryAllByText('Attribute')).toHaveLength(expectedFields); | ||
}); | ||
|
||
it('displays operator label(s)', () => { | ||
const { queryAllByText } = renderComponent; | ||
expect(queryAllByText('Operator')).toHaveLength(expectedFields); | ||
}); | ||
|
||
it('displays value label(s)', () => { | ||
const { queryAllByText } = renderComponent; | ||
expect(queryAllByText('Value')).toHaveLength(expectedFields); | ||
}); | ||
|
||
it('displays operator label(s)', () => { | ||
const { queryAllByText } = renderComponent; | ||
expect(queryAllByText('Operator')).toHaveLength(expectedFields); | ||
}); | ||
describe('DocumentFilterRule interactions', () => { | ||
it(`renders ${expectedRules} DocumentFilterRule component${expectedRules !== 1 ? 's' : ''}`, () => { | ||
const { queryAllByText } = renderComponent; | ||
expect(queryAllByText('DocumentFilterRule')).toHaveLength(expectedRules); | ||
}); | ||
|
||
it('displays value label(s)', () => { | ||
const { queryAllByText } = renderComponent; | ||
expect(queryAllByText('Value')).toHaveLength(expectedFields); | ||
}); | ||
if (expectedFields === 0) { | ||
it('does not render the add rule button', async () => { | ||
await Button('Add rule').absent(); | ||
}); | ||
} else { | ||
describe('clicking add rule button', () => { | ||
beforeEach(async () => { | ||
await waitFor(async () => { | ||
// There will be multiple add rules for multiple DocumentFilterFields | ||
await Button({ id: 'add-rule-button-filters[0]' }).click(); | ||
}); | ||
}); | ||
|
||
if (expectedFields > 0) { | ||
test('renders the add rule button', async () => { | ||
await Button('Add rule').exists(); | ||
test('a rule has been added', async () => { | ||
const { queryAllByText } = renderComponent; | ||
await waitFor(() => { | ||
expect(queryAllByText('DocumentFilterRule')).toHaveLength(expectedRules + 1); | ||
}); | ||
}); | ||
}); | ||
} | ||
}); | ||
// TODO Mock DocumentFilterRule and check that you can add rules, that the right number show up and that they're separated by ANDs | ||
} | ||
}); | ||
); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.