-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
UIPFU-81 - Add jest tests to Filters.js (#274)
* temporarily revert some code * UIPFU-81 - Add jest tests to Filters.js * UIPFU-81 - revert previous temp change * UIPFU-81 - cleanup * UIPFU-81 - updated yarn lock file * UIPFU-81 - update change log md file * UIPFU-81 - update CI workflow to pick jest tests * UIPFU-81 - update test script * UIPFU-81 - include both jest and big test in test scripts * UIPFU-81 - remove big test in test scripts * UIPFU-81 - address review comments * UIPFU-81 - reorder imports * UIPFU-81 - upgrade actions/upload-artifact to v3 for Jest * UIPFU-81 - upgrade actions/upload-artifact to v3 for Bigtest * UIPFU-81 - downgrade history package from v4 to v5
- Loading branch information
1 parent
0138142
commit 615bbb5
Showing
9 changed files
with
122 additions
and
8 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
import { FormattedMessage } from 'react-intl'; | ||
|
||
import { screen } from '@folio/jest-config-stripes/testing-library/react'; | ||
import userEvent from '@folio/jest-config-stripes/testing-library/user-event'; | ||
|
||
import renderWithRouter from 'helpers/renderWithRouter'; | ||
import Filters from './Filters'; | ||
|
||
jest.unmock('@folio/stripes/components'); | ||
|
||
const renderFilters = (props) => renderWithRouter( | ||
<Filters {...props} /> | ||
); | ||
|
||
const props = { | ||
onChangeHandlers : { | ||
checkbox: jest.fn(), | ||
}, | ||
activeFilters: { | ||
state: {}, | ||
string: '', | ||
}, | ||
resultOffset: { | ||
replace: jest.fn(), | ||
update: jest.fn(), | ||
}, | ||
config:[ | ||
{ | ||
label: <FormattedMessage id="ui-plugin-find-user.status" />, | ||
name: 'active', | ||
cql: 'active', | ||
values: [ | ||
{ | ||
name: 'inactive', | ||
cql: 'false', | ||
displayName: <FormattedMessage id="ui-plugin-find-user.inactive" />, | ||
}, | ||
{ | ||
name: 'active', | ||
cql: 'true', | ||
displayName: <FormattedMessage id="ui-plugin-find-user.active" />, | ||
}, | ||
], | ||
}, | ||
{ | ||
label: <FormattedMessage id="ui-plugin-find-user.information.patronGroup" />, | ||
name: 'pg', | ||
cql: 'patronGroup', | ||
values: [], | ||
}, | ||
], | ||
}; | ||
|
||
describe('Filters', () => { | ||
beforeEach(() => { | ||
renderFilters(props); | ||
}); | ||
|
||
it('should render status filter groups', () => { | ||
expect(screen.queryByText('ui-plugin-find-user.status')).toBeInTheDocument(); | ||
}); | ||
|
||
it('should render patronGroup filter groups', () => { | ||
expect(screen.queryByText('ui-plugin-find-user.information.patronGroup')).toBeInTheDocument(); | ||
}); | ||
|
||
it('should render active status filter', () => { | ||
expect(screen.queryByText('ui-plugin-find-user.active')).toBeInTheDocument(); | ||
}); | ||
|
||
it('should render inactive status filter', () => { | ||
expect(screen.getByText('ui-plugin-find-user.inactive')).toBeInTheDocument(); | ||
}); | ||
|
||
it('should call changeHandler on clicking inactive checkbox', async () => { | ||
const inActiveCheckbox = screen.getByRole('checkbox', { name: 'ui-plugin-find-user.inactive' }); | ||
await userEvent.click(inActiveCheckbox); | ||
|
||
expect(props.onChangeHandlers.checkbox).toHaveBeenCalled(); | ||
}); | ||
}); |
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 @@ | ||
jest.mock('currency-codes/data', () => ({ filter: () => [] })); |
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,28 @@ | ||
import React from 'react'; | ||
import { IntlProvider } from 'react-intl'; | ||
import { CalloutContext } from '@folio/stripes/core'; | ||
import { Router } from 'react-router-dom'; | ||
import { render } from '@folio/jest-config-stripes/testing-library/react'; | ||
import { createMemoryHistory } from 'history'; | ||
|
||
let rtlApi; | ||
|
||
const renderWithRouter = (children, options = {}) => { | ||
const history = createMemoryHistory(); | ||
const renderFn = options.rerender ? rtlApi.rerender : render; | ||
rtlApi = renderFn( | ||
<Router history={history}> | ||
<CalloutContext.Provider value={{ sendCallout: () => { } }}> | ||
<IntlProvider | ||
locale="en" | ||
messages={{}} | ||
> | ||
{children} | ||
</IntlProvider> | ||
</CalloutContext.Provider> | ||
</Router> | ||
); | ||
return { ...rtlApi, history }; | ||
}; | ||
|
||
export default renderWithRouter; |
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