-
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-3332, Add documents filter to agreement line search (#704)
* Add translations * ERM-3332 * feat: DocumentFilter labelling Allow for default and custom labelling of DocumentFilters. Also added centralised "core documents" and "supplementary documents" labels as we use those terms in multiple modules ERM-3332 * feat: Pass filterName (defaulted to docs) all the way down Ensure that we're passing down filterName so that supplementary vs core vs docs can all be set up in the generic component * style: Rename atTypeValues to categoryValues Deprecated atTypeValues (but still in place anyway. Use categoryValues instead * Refactor change orders of props and imports * fix: Category value field not shifting to Select No longer relying on "supplementary docs" to be the name of the field. Instead have `ifCategory` decide whether or not to render the field, then use the passed filterName to work out whether to diplsay value as TextField or Select * lint * Add test coverage to DocumentFilters * lint * fix: Render OrganizationSelection placeholder (Was never rendering when no option selected) * fix render Internal contacts placeholder, tweak tests * test: WIP! Broken the tests to demonstrate a progression of jest testing for the heirachy * refactor: Move a bunch of logic down a level to avoid weird component boundaries * test: Fixed FocumentFilter test (Leaving some for cleanup later) * test: Added documentFilterParsing to combined testResource file, so that both tests can make use. Improved DocumentForm test * test: Add test comments for DocumentFilterFieldArray * test: DocumentFilterField test (Leaving rules testing to M) * test: Testing DocumentFilterRule (With comments to expand on this later * chore: Linting * chore: Prop validation --------- Co-authored-by: Ethan Freestone <[email protected]>
- Loading branch information
1 parent
dc404b6
commit 7879c28
Showing
19 changed files
with
854 additions
and
142 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,143 @@ | ||
import { MemoryRouter } from 'react-router-dom'; | ||
import { | ||
Button, | ||
Accordion, | ||
renderWithIntl, | ||
} from '@folio/stripes-erm-testing'; | ||
|
||
import { Button as MockStripesButton } from '@folio/stripes/components'; | ||
|
||
import { waitFor } from '@folio/jest-config-stripes/testing-library/react'; | ||
import { translationsProperties } from '../../test/jest/helpers'; | ||
import DocumentFilter from './DocumentFilter'; | ||
|
||
import { documentFilterParsing } from './testResources'; | ||
|
||
const mockPFD = jest.fn(); | ||
|
||
jest.mock('./DocumentFilterForm', () => ({ | ||
filters, | ||
}) => { | ||
return ( | ||
<div> | ||
<MockStripesButton onClick={() => mockPFD(filters)}> | ||
Test parsed filter data | ||
</MockStripesButton> | ||
DocumentFilterForm | ||
</div> | ||
); | ||
}); | ||
|
||
const stateMock = jest.fn(); | ||
const filterHandlers = { | ||
state: stateMock, | ||
checkbox: () => {}, | ||
clear: () => {}, | ||
clearGroup: () => {}, | ||
reset: () => {}, | ||
}; | ||
|
||
|
||
// Todo 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', | ||
}, | ||
]; | ||
|
||
|
||
let renderComponent; | ||
|
||
describe('DocumentFilter', () => { | ||
describe.each([ | ||
[ | ||
'with active filters', | ||
documentFilterParsing.find(dfp => dfp.name === 'simple').deparsed, | ||
'1 document filters applied', | ||
documentFilterParsing.find(dfp => dfp.name === 'simple').parsed, | ||
], | ||
[ | ||
'without active filters', | ||
{ docs: [] }, | ||
null, | ||
[] | ||
], | ||
[ | ||
'with multiple active filters', | ||
documentFilterParsing.find(dfp => dfp.name === 'complex').deparsed, | ||
'2 document filters applied', | ||
documentFilterParsing.find(dfp => dfp.name === 'complex').parsed, | ||
], | ||
])('ActiveFilter tests', ( | ||
activeFilterTitle, | ||
activeFilterState, | ||
expectedLayoutText, | ||
expectedParsedFilterData | ||
) => { | ||
describe(activeFilterTitle, () => { | ||
beforeEach(() => { | ||
renderComponent = renderWithIntl( | ||
<MemoryRouter> | ||
<DocumentFilter | ||
activeFilters={activeFilterState} | ||
categoryValues={categoryValues} | ||
filterHandlers={filterHandlers} | ||
/>, | ||
</MemoryRouter>, | ||
translationsProperties | ||
); | ||
}); | ||
|
||
test('renders the document filters accordion', async () => { | ||
await Accordion('Documents').exists(); | ||
}); | ||
|
||
test('renders expected filters text', async () => { | ||
const baseLayoutText = /document filters applied/; | ||
const { queryByText } = renderComponent; | ||
if (expectedLayoutText != null) { | ||
expect(queryByText(expectedLayoutText)).toBeInTheDocument(); | ||
} else { | ||
expect(queryByText(baseLayoutText)).not.toBeInTheDocument(); | ||
} | ||
}); | ||
|
||
it('renders DocumentFilterForm component', () => { | ||
const { getByText } = renderComponent; | ||
expect(getByText('DocumentFilterForm')).toBeInTheDocument(); | ||
}); | ||
|
||
// TODO | ||
// Add test for clearing accordion, whether clear button exists etc (mock filterHandlers.state) | ||
// and check the right value are passed when it's clicked | ||
|
||
describe('testing parsedFilterData', () => { | ||
beforeEach(async () => { | ||
mockPFD.mockClear(); | ||
await waitFor(async () => { | ||
await Button('Test parsed filter data').click(); | ||
}); | ||
}); | ||
|
||
test('parsed filter data is as expected', () => { | ||
expect(mockPFD.mock.calls[0][0]).toEqual(expectedParsedFilterData); | ||
}); | ||
}); | ||
}); | ||
}); | ||
|
||
// TODO | ||
// Add test for passing in/not passing in labels | ||
}); |
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.