-
Notifications
You must be signed in to change notification settings - Fork 6
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
UIREQ-937 create JEST/RTL test cases for RequestsFilters.js #1044
Conversation
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.
Could you add changes to changelog file?
Could you check that RequestLevelFilter
is rendered/not rendered?
Could you check that all necessary MultiSelectionFilter
rendered?
@@ -0,0 +1,74 @@ | |||
import React from 'react'; |
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.
It is not necessary to import.
jest.mock('@folio/stripes/components', () => ({ | ||
AccordionSet: jest.fn(({ children }) => <div>{children}</div>), | ||
Accordion: jest.fn(({ displayClearButton, name, children, onClearFilter }) => ( | ||
<div> | ||
<div>{displayClearButton ? <button type="button" onClick={() => onClearFilter()} data-testid={`clear-${name}`}>Clear</button> : null}</div> | ||
<div data-testid={`accordion-${name}`}>{children}</div> | ||
</div> | ||
)), | ||
FilterAccordionHeader: jest.fn(() => <div>FilterAccordionHeader</div>), | ||
})); | ||
|
||
jest.mock('@folio/stripes/smart-components', () => ({ | ||
CheckboxFilter: jest.fn(() => <div>CheckboxFilter</div>), | ||
MultiSelectionFilter: jest.fn(() => <div>MultiSelectionFilter</div>), | ||
})); |
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.
We have separate files with mocks - test/jest/__mock__
.
You can add your mocks there if those mocks do not exist yet.
const { getByTestId } = render(<RequestsFilters {...props} />); | ||
const requestTypeButton = getByTestId('clear-requestType'); | ||
expect(requestTypeButton).toBeInTheDocument(); | ||
userEvent.click(requestTypeButton); |
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.
What is the reason to trigger click
event here?
Is it necessary only for increasing code coverage?
const { getByTestId } = render(<RequestsFilters {...props} />); | ||
const requestStatusButton = getByTestId('clear-requestStatus'); | ||
expect(requestStatusButton).toBeInTheDocument(); | ||
userEvent.click(requestStatusButton); |
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.
What is the reason to trigger click
event here?
Is it necessary only for increasing code coverage?
const { getByTestId } = render(<RequestsFilters {...props} />); | ||
const tagsButton = getByTestId('clear-tags'); | ||
expect(tagsButton).toBeInTheDocument(); | ||
userEvent.click(tagsButton); |
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.
What is the reason to trigger click
event here?
Is it necessary only for increasing code coverage?
it('renders the request type filter', () => { | ||
const { getByTestId } = render(<RequestsFilters {...props} />); | ||
const requestTypeButton = getByTestId('clear-requestType'); | ||
expect(requestTypeButton).toBeInTheDocument(); | ||
userEvent.click(requestTypeButton); | ||
}); | ||
it('renders the request status filter', () => { | ||
const { getByTestId } = render(<RequestsFilters {...props} />); | ||
const requestStatusButton = getByTestId('clear-requestStatus'); | ||
expect(requestStatusButton).toBeInTheDocument(); | ||
userEvent.click(requestStatusButton); | ||
}); | ||
it('renders the tags filter', () => { | ||
const { getByTestId } = render(<RequestsFilters {...props} />); | ||
const tagsButton = getByTestId('clear-tags'); | ||
expect(tagsButton).toBeInTheDocument(); | ||
userEvent.click(tagsButton); | ||
}); |
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.
I see that the first three tests have the same render approach.
Could you add beforeEach
statement and call render(<RequestsFilters {...props} />)
inside?
expect(tagsButton).toBeInTheDocument(); | ||
userEvent.click(tagsButton); | ||
}); | ||
it('render the accordion pickup service points', () => { |
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.
Could you mock PickupServicePointFilter
and check that it is rendered. There is no sence to check rendering of inner components of PickupServicePointFilter
. PickupServicePointFilter
has or will have in future its own tests.
Kudos, SonarCloud Quality Gate passed! |
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.
Could you check the rendering of CheckboxFilter
?
From the code perspective, I see that CheckboxFilter
rendered twice. Would be great to check each render.
it('should click the onClear filters', () => { | ||
userEvent.click(screen.getByTestId('clear-requestType')); | ||
userEvent.click(screen.getByTestId('clear-requestStatus')); | ||
userEvent.click(screen.getByTestId('clear-tags')); | ||
expect(props.onClear).toHaveBeenCalled(); | ||
}); |
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.
Could you create 3 separate tests (1 for each "click" action) and check that onClear
was called with correct argument?
it('should render the PickupServicePointFilter', () => { | ||
expect(screen.getByText(/PickupServicePointFilter/i)).toBeInTheDocument(); | ||
}); | ||
describe('MultiSelectionFilter and RequestLevelFilter', () => { |
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.
I think this describe
is redundant.
Or at least if you want to have describe
it makes sense to have one describe
for each filter.
); | ||
expect(getAllByText('MultiSelectionFilter')).toBeTruthy(); | ||
}); | ||
it('should render RequestLevelFilter', () => { |
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.
Could you add a case when titleLevelRequestsFeatureEnabled
is false and check that RequestLevelFilter
is not rendered?
<div> | ||
{label} | ||
{children} | ||
{/* <div>{<button type="button" onClick={() => onClearFilter()} data-testid={`clear-${name}`}>Clear</button> : null}</div> */} |
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.
do we need that comment?
@@ -8,4 +8,6 @@ jest.mock('@folio/stripes/smart-components', () => ({ | |||
SearchAndSort: jest.fn(() => null), | |||
ViewMetaData: jest.fn(() => null), | |||
withTags: jest.fn((WrappedComponent) => (props) => <WrappedComponent {...props} />), | |||
// CheckboxFilter: jest.fn(() => <div>CheckboxFilter</div>), |
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.
Do we need that comment?
beforeEach(() => { | ||
render(<RequestsFilters {...props} />); | ||
}); |
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.
Line 51 and 65 have their own renders. But here on the line 36 you will have one more render. I think it is not the best approach.
I would suggest wrapping your first two tests in describe
and executing beforeEach
inside describe
.
<div> | ||
<button | ||
type="button" | ||
onClick={() => onClearFilter()} |
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.
onClick={() => onClearFilter()} | |
onClick={onClearFilter} |
@@ -2,14 +2,30 @@ import React from 'react'; | |||
|
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.
Could you please revert your changes that don't need for current pull request (mock for AccordionSet, ConfirmationModal, ErrorModal, Select)?
CC: @artem-blazhko
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.
Could you please fix feedbacks?
Could you please fix feedbacks? |
Accordion: jest.fn(({ children, label, name, onClearFilter }) => ( | ||
<div> | ||
{label} | ||
{children} | ||
<div> | ||
<button | ||
type="button" | ||
onClick={onClearFilter} | ||
data-testid={`clear-${name}`} | ||
>Clear | ||
</button> | ||
</div> | ||
<div data-testid={`accordion-${name}`} /> | ||
</div> |
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.
Accordion: jest.fn(({ children, label, name, onClearFilter }) => ( | |
<div> | |
{label} | |
{children} | |
<div> | |
<button | |
type="button" | |
onClick={onClearFilter} | |
data-testid={`clear-${name}`} | |
>Clear | |
</button> | |
</div> | |
<div data-testid={`accordion-${name}`} /> | |
</div> | |
Accordion: jest.fn(({ children, label, name, onClearFilter }) => ( | |
<div data-testid={`accordion-${name}`} > | |
{label} | |
{children} | |
<div> | |
<button | |
type="button" | |
onClick={onClearFilter} | |
data-testid={`clear-${name}`} | |
>Clear | |
</button> | |
</div> | |
</div> |
{...props} | ||
/> | ||
)), | ||
Checkbox: jest.fn(() => <div>Checkbox</div>), |
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.
I do not see the usage of that component. Do we really need to mock it?
Col: jest.fn(({ children }) => ( | ||
<div data-test-col> | ||
{children} | ||
</div> | ||
)), | ||
ConfirmationModal: jest.fn(() => <div>ConfirmationModal</div>), | ||
ConfirmationModal: jest.fn(({ heading, confirmLabel, cancelLabel, onConfirm, onCancel }) => ( |
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.
I do not see the usage of that component. Do we really need to change the mock?
Datepicker: jest.fn(() => <div>Datepicker</div>), | ||
ErrorModal: jest.fn(() => <div>ErrorModal</div>), | ||
ErrorModal: jest.fn(({ label, content, buttonLabel, onClose }) => ( |
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.
I do not see the usage of that component. Do we really need to change the mock?
@@ -75,7 +99,6 @@ jest.mock('@folio/stripes-components', () => ({ | |||
)), | |||
MultiColumnList: jest.fn(({ children }) => ( | |||
<div> | |||
<div>MultiColumnList</div> |
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.
I do not see the usage of that component. Do we really need to change the mock?
TextField: jest.fn(({ | ||
label, | ||
onChange, | ||
validate = jest.fn(), | ||
...rest | ||
}) => { |
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.
Could you clarify why do we need to change that mock?
onChange(e); | ||
}; | ||
|
||
Select: ({ name, label, onChange, required, children, value }) => { |
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.
Could you clarify why we need to change that mock?
</div> | ||
); | ||
}), | ||
}, | ||
TextArea: jest.fn(() => <div>TextArea</div>), |
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.
Could you clarify why we need to change that mock?
}), | ||
}, | ||
TextArea: jest.fn(() => <div>TextArea</div>), | ||
TextField: jest.fn(() => <div>TextField</div>), |
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.
Could you clarify why we need to change that mock?
expect(screen.getByText(/PickupServicePointFilter/i)).toBeInTheDocument(); | ||
}); | ||
it('should render the MultiSelectionFilter', () => { | ||
screen.debug(); |
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.
Do we really need it here?
Included in RequestFilters.test.js
CHANGELOG.md
Outdated
@@ -37,6 +37,7 @@ | |||
* Cover ItemInformation by jest/RTL tests. Refs UIREQ-949. | |||
* Cover InstanceInformation by jest/RTL tests. Refs UIREQ-950. | |||
* Fix inconsistency in RTL/Jest tests. Refs UIREQ-979. | |||
* Create Jest/RTL test for RequestsFilters.js Refs UIREQ-937. |
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.
Could you move it to the bottom of the list?
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.
Updated in Changelog.md
Accordion.mockImplementation(jest.fn(({ children, label, name, onClearFilter }) => ( | ||
<div> | ||
{label} | ||
{children} | ||
<div> | ||
<button | ||
type="button" | ||
onClick={onClearFilter} | ||
data-testid={`clear-${name}`} | ||
> | ||
Clear | ||
</button> | ||
</div> | ||
<div data-testid={`accordion-${name}`} /> | ||
</div> | ||
))); | ||
|
||
AccordionSet.mockImplementation(jest.fn(({ children, onToggle }) => ( | ||
<div> | ||
<button type="button" onClick={() => onToggle({ id: 'fulfillment-in-progress' })}> | ||
Toggle in Progress | ||
</button> | ||
<button type="button" onClick={() => onToggle({ id: 'not-yet-filled' })}> | ||
Toggle Not Yet Filled | ||
</button> | ||
{children} | ||
</div> | ||
))); |
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.
Could you add your changes to test/__mock__stripesComponents.mock.js
file?
That file store all popular mock from components library.
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.
@artem-blazhko - We have added the mock functions to the test file because other test cases in this module will fail if added test/__mock__stripesComponents.mock.js
Kudos, SonarCloud Quality Gate passed! |
Thank you for yours pull request. We will use it for increase code coverage. |
UIREQ-937 create JEST/RTL test cases for RequestsFilters.js
URL: https://issues.folio.org/browse/UIREQ-937