-
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.
UIREQ-1190 - Add "Retrieval service point" filter (#1244)
* UIREQ-1190 - initial commit * UIREQ-1190 - Add "Retrieval service point" filter * fix failed tests * fix test * refine and fix tests * UIREQ-1190 - remove unnecessary mock * UIREQ-1190 - duplicate existing Request filters in deprecated folder so that 'Retrieval service point" filter is not available from deprecated folder path * update translation id * Update src/hooks/useRetrievalServicePoints/useRetrievalServicePoints.js Co-authored-by: Mariia Aloshyna <[email protected]> * move RequestFilters to components and remove unnecessary code from deprecated folder * fix tests * fix test failures and review comments --------- Co-authored-by: Mariia Aloshyna <[email protected]>
- Loading branch information
1 parent
039a9ea
commit dac2d58
Showing
22 changed files
with
1,121 additions
and
2 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
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
62 changes: 62 additions & 0 deletions
62
src/components/RequestsFilters/RetrievalServicePointFilter/RetrievalServicePointFilter.js
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,62 @@ | ||
import { useCallback } from 'react'; | ||
import { FormattedMessage } from 'react-intl'; | ||
import { isEmpty } from 'lodash'; | ||
import PropTypes from 'prop-types'; | ||
|
||
import { | ||
Accordion, | ||
FilterAccordionHeader, | ||
} from '@folio/stripes/components'; | ||
import { | ||
MultiSelectionFilter, | ||
} from '@folio/stripes/smart-components'; | ||
|
||
import { | ||
requestFilterTypes, | ||
} from '../../../constants'; | ||
|
||
import { useRetrievalServicePoints } from '../../../hooks'; | ||
|
||
const RetrievalServicePointFilter = ({ | ||
activeValues, | ||
onChange, | ||
onClear, | ||
}) => { | ||
const name = requestFilterTypes.RETRIEVAL_SERVICE_POINT; | ||
const clearFilter = useCallback(() => { | ||
onClear(name); | ||
}, [name, onClear]); | ||
|
||
const { retrievalSPsOptions } = useRetrievalServicePoints(); | ||
|
||
return ( | ||
<div> | ||
<Accordion | ||
data-testid="retrievalServicePointAccordion" | ||
displayClearButton={!isEmpty(activeValues)} | ||
id={name} | ||
header={FilterAccordionHeader} | ||
label={<FormattedMessage id="ui-requests.requests.retrievalServicePoint" />} | ||
name={name} | ||
separator={false} | ||
onClearFilter={clearFilter} | ||
> | ||
<MultiSelectionFilter | ||
ariaLabelledBy={`accordion-toggle-button-${name}`} | ||
dataOptions={retrievalSPsOptions} | ||
id="req-retrieval-service-point-filter" | ||
name={name} | ||
onChange={onChange} | ||
selectedValues={activeValues} | ||
/> | ||
</Accordion> | ||
</div> | ||
); | ||
}; | ||
|
||
RetrievalServicePointFilter.propTypes = { | ||
activeValues: PropTypes.arrayOf(PropTypes.string), | ||
onChange: PropTypes.func.isRequired, | ||
onClear: PropTypes.func.isRequired, | ||
}; | ||
export default RetrievalServicePointFilter; |
86 changes: 86 additions & 0 deletions
86
...omponents/RequestsFilters/RetrievalServicePointFilter/RetrievalServicePointFilter.test.js
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,86 @@ | ||
import { | ||
render, | ||
screen, | ||
} from '@folio/jest-config-stripes/testing-library/react'; | ||
import userEvent from '@folio/jest-config-stripes/testing-library/user-event'; | ||
|
||
import { | ||
Accordion, | ||
FilterAccordionHeader, | ||
} from '@folio/stripes/components'; | ||
|
||
import RetrievalServicePointFilter from './RetrievalServicePointFilter'; | ||
import { requestFilterTypes } from '../../../constants'; | ||
|
||
jest.mock('../../../hooks', () => ({ | ||
...jest.requireActual('../../../hooks'), | ||
useRetrievalServicePoints: jest.fn().mockReturnValue([ | ||
{ | ||
value: '3a40852d-49fd-4df2-a1f9-6e2641a6e91f', | ||
label: 'Circ desk 1', | ||
}, | ||
{ | ||
value: '9d1b77e8-f02e-4b7f-b296-3f2042ddac54', | ||
label: 'Circ desk 2', | ||
}, | ||
]), | ||
})); | ||
|
||
const activeValues = ['test', 'test2']; | ||
const onChange = jest.fn(); | ||
const onClear = jest.fn(); | ||
const testIds = { | ||
retrievalServicePointAccordionButton: 'retrievalServicePointAccordionButton', | ||
}; | ||
|
||
describe('RetrievalServicePointFilter', () => { | ||
beforeEach(() => { | ||
onChange.mockClear(); | ||
onClear.mockClear(); | ||
render( | ||
<RetrievalServicePointFilter | ||
activeValues={activeValues} | ||
onChange={onChange} | ||
onClear={onClear} | ||
/> | ||
); | ||
}); | ||
|
||
it('should render "Accordion" with correct props', () => { | ||
const expectedProps = { | ||
id: requestFilterTypes.RETRIEVAL_SERVICE_POINT, | ||
name: requestFilterTypes.RETRIEVAL_SERVICE_POINT, | ||
header: FilterAccordionHeader, | ||
separator: false, | ||
onClearFilter: expect.any(Function), | ||
}; | ||
|
||
expect(Accordion).toHaveBeenCalledWith(expect.objectContaining(expectedProps), {}); | ||
}); | ||
|
||
it('should render MultiSelectionFilter', () => { | ||
const MultiSelectionFilter = screen.getByText('MultiSelectionFilter'); | ||
|
||
expect(MultiSelectionFilter).toBeInTheDocument(); | ||
}); | ||
|
||
it('should perform onClear event', async () => { | ||
const retrievalServicePointsButton = screen.getByTestId(testIds.retrievalServicePointAccordionButton); | ||
|
||
await userEvent.click(retrievalServicePointsButton); | ||
|
||
expect(onClear).toHaveBeenCalledWith(requestFilterTypes.RETRIEVAL_SERVICE_POINT); | ||
}); | ||
|
||
describe('MultiSelectionFilter activeValues', () => { | ||
activeValues.forEach(value => { | ||
it(`should render "${value}"`, () => { | ||
const activeValue = screen.getByText(value, { | ||
exact: false, | ||
}); | ||
|
||
expect(activeValue).toBeInTheDocument(); | ||
}); | ||
}); | ||
}); | ||
}); |
1 change: 1 addition & 0 deletions
1
src/components/RequestsFilters/RetrievalServicePointFilter/index.js
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 @@ | ||
export { default as RetrievalServicePointFilter } from './RetrievalServicePointFilter'; |
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.