-
Notifications
You must be signed in to change notification settings - Fork 116
test: categorynavbar component #952
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
test: categorynavbar component #952
Conversation
bartoszherba
left a comment
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.
@Diegoalbag Please, fix also the PR name so it align with the rules (remove the dot ;) )
| expect(uiStateMock.toggleFilterSidebar).toHaveBeenCalledTimes(1); | ||
| }); | ||
|
|
||
| it('Should render "sort by" select and change selection', async() => { |
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.
Can we also verify that select has all expected options based on its data?
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.
@Diegoalbag What about this one?
|
|
||
| expect(uiStateMock.changeToCategoryGridView).toHaveBeenCalledTimes(1); | ||
| }); | ||
| }); No newline at end of file |
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 that we can also add the following tests:
- Check if the items count is rendered properly with the expected value
- Check if the component is in loading state all skeletons are rendered as expected
- change sorting action emits 'reloadProducts' event
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.
@Diegoalbag What about this one?
| import { render } from '~/test-utils'; | ||
| import CategoryNavbar from '../CategoryNavbar.vue'; | ||
| import { paginationData, sortByData} from '~/test-utils/mocks/categoryNavbarMock'; | ||
| import { expect } from '@jest/globals'; |
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.
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.
@Diegoalbag What about this one?
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.
@bartoszherba Assertion is not being imported anymore.
7a24ac9 to
8a4312c
Compare
8a4312c to
10315fe
Compare
|
I recently added a GitHub action step that runs ESLint and fails if there are any ESLint errors.
|
| const { getByRole, getByText, getAllByRole, emitted } = render(CategoryNavbar, categoryNavbarProps); | ||
| const sortSelect = getByRole('combobox'); | ||
| const options = getAllByRole('option'); | ||
| expect(options.length).toBe(categoryNavbarProps.props.sortBy.options.length); |
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.
@bartoszherba here I verify that select has all expected options based on its data
|
|
||
| await userEvent.selectOptions(sortSelect, ['name_ASC']); | ||
| expect(getByText('Sort: Name A-Z').value).toBe(sortSelect.value); | ||
| expect(emitted().reloadProducts).toHaveProperty('length', 1); |
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.
@bartoszherba Here I check that changing sorting action emits 'reloadProducts' event
10315fe to
3e617f8
Compare
| const loadingCategoryNavbarProps = { props: { pagination: paginationData, sortBy: sortByData, isLoading: true } }; | ||
|
|
||
| describe('CategoryNavbar.vue', () => { | ||
| it('Should render Skeleton when loading is true', () => { |
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.
@bartoszherba Check if the component is in loading state all skeletons are rendered as expected
f292994 to
350baaa
Compare
350baaa to
42107a3
Compare

Description
Added unit tests for packages/theme/modules/catalog/category/components/navbar/CategoryNavbar.vue
Related Issue
Motivation and Context
How Has This Been Tested?
Screenshots (if appropriate):
Types of changes
Checklist: