-
Notifications
You must be signed in to change notification settings - Fork 3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
UIPFU-81 - Add jest tests to Filters.js #274
Changes from 11 commits
55bbc56
4a609c8
6ce37b0
d430407
46d1e8e
17e23df
32e621a
3fa040a
b98ca26
39fa303
e1be762
8356f60
70cc3c4
bc15aab
8b29fb0
cfbeb0b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
import { screen } from '@folio/jest-config-stripes/testing-library/react'; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please re-order imports so that first we import third-party modules, then stripes modules, and last is imports from current module. Please also check other files in this PR There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hey @BogdanDenis |
||
import userEvent from '@folio/jest-config-stripes/testing-library/user-event'; | ||
import { FormattedMessage } from 'react-intl'; | ||
|
||
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 = document.querySelector('[ id = "clickable-filter-active-inactive"]'); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. is it possible to find the checkbox using |
||
await userEvent.click(inActiveCheckbox); | ||
|
||
expect(props.onChangeHandlers.checkbox).toHaveBeenCalled(); | ||
}); | ||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
jest.mock('currency-codes/data', () => ({ filter: () => [] })); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
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; | ||
|
||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. remove an extra blank line, please |
||
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; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey @Terala-Priyanka, could you change the
history
to v4?react-router@5
doesn't supporthistory@5
and it may cause test failuresThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey @BogdanDenis
Thank you for bringing this up.
I have noticed that
history
v5 is used withreact-router@5
withinui-users
.It works seamlessly in the workflows too.
Could you please share if there is anything specific about this incompatibility?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Terala-Priyanka we've had some test errors because
history.listen
was called with a slightly differentlocation
argument structure in tests versus in real application. It was a difficult issue to debug because I also assumed thathistory@5
is supposed to be used withreact-router@5