-
Notifications
You must be signed in to change notification settings - Fork 284
[Remove Vuetify from Studio] Convert content library filter bar unit tests to Vue Testing Library #5653
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
base: unstable
Are you sure you want to change the base?
[Remove Vuetify from Studio] Convert content library filter bar unit tests to Vue Testing Library #5653
Changes from all commits
53dd04d
b2ee899
2cf5184
988b3e5
7294eca
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 |
|---|---|---|
| @@ -1,13 +1,16 @@ | ||
| import { mount } from '@vue/test-utils'; | ||
| import { render, screen, waitFor } from '@testing-library/vue'; | ||
| import userEvent from '@testing-library/user-event'; | ||
| import Vuex from 'vuex'; | ||
| import VueRouter from 'vue-router'; | ||
| import Vue from 'vue'; | ||
| import { factory } from '../../../store'; | ||
| import router from '../../../router'; | ||
| import CatalogFilterBar from '../CatalogFilterBar'; | ||
|
|
||
| const store = factory(); | ||
| Vue.use(Vuex); | ||
|
Member
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. This might be redundant we already import this in |
||
| Vue.use(VueRouter); | ||
|
|
||
| const collection = { | ||
| id: 'test-collection', | ||
| }; | ||
| const collection = { id: 'test-collection' }; | ||
|
|
||
| const query = { | ||
| keywords: 'testing', | ||
|
|
@@ -16,11 +19,28 @@ const query = { | |
| collection: 'some-collection', | ||
| }; | ||
|
|
||
| async function closeChipByText(user, text) { | ||
| const chip = await screen.findByText(text); | ||
|
|
||
| const closeButton = chip.closest('[data-test^="filter-chip"]').querySelector('i'); | ||
|
Member
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. Should we rely on better semantic tag than |
||
|
|
||
| await user.click(closeButton); | ||
| } | ||
|
|
||
| function makeWrapper() { | ||
| return mount(CatalogFilterBar, { | ||
| sync: false, | ||
| router, | ||
| const store = factory(); | ||
|
|
||
| router | ||
| .push({ | ||
| name: 'CHANNELS_EDITABLE', | ||
| query, | ||
| }) | ||
| .catch(() => {}); | ||
|
|
||
| return render(CatalogFilterBar, { | ||
| // localVue, | ||
| store, | ||
| router, | ||
| computed: { | ||
| collections() { | ||
| return [collection]; | ||
|
|
@@ -30,52 +50,73 @@ function makeWrapper() { | |
| } | ||
|
|
||
| describe('catalogFilterBar', () => { | ||
| let wrapper; | ||
| beforeEach(() => { | ||
| wrapper = makeWrapper(); | ||
| router | ||
|
Member
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. Router is set up in both |
||
| .push({ | ||
| name: 'CHANNELS_EDITABLE', | ||
| query: { ...query }, | ||
| }) | ||
| .catch(() => {}); | ||
| }); | ||
|
|
||
| describe('removing filters', () => { | ||
| beforeEach(() => { | ||
| Object.entries(query).forEach(([key, val]) => { | ||
| wrapper.vm[key] = val; | ||
| }); | ||
| router.replace({ query }); | ||
| it('clear all button should remove all filters', async () => { | ||
| const user = userEvent.setup(); | ||
| makeWrapper(); | ||
|
|
||
| await user.click(screen.getByTestId('clear')); | ||
|
|
||
| await waitFor(() => { | ||
| expect(router.currentRoute.query.keywords).toBeUndefined(); | ||
| expect(router.currentRoute.query.coach).toBeUndefined(); | ||
| expect(router.currentRoute.query.collection).toBeUndefined(); | ||
| expect(router.currentRoute.query.languages).toBeUndefined(); | ||
| }); | ||
| it('clear all button should remove all filters', () => { | ||
| wrapper.find('[data-test="clear"]').trigger('click'); | ||
| expect(wrapper.keywords).toBeUndefined(); | ||
| expect(wrapper.vm.currentFilters).toHaveLength(0); | ||
| }); | ||
|
|
||
| it('removing text-based filter should remove it from the query', async () => { | ||
| const user = userEvent.setup(); | ||
| makeWrapper(); | ||
|
|
||
| await closeChipByText(user, '"testing"'); | ||
|
|
||
| await waitFor(() => { | ||
| expect(router.currentRoute.query.keywords).toBeUndefined(); | ||
| expect(router.currentRoute.query.coach).toBeTruthy(); | ||
|
Member
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. Instead of |
||
| expect(router.currentRoute.query.collection).toBeTruthy(); | ||
| expect(router.currentRoute.query.languages).toBeTruthy(); | ||
| }); | ||
| it('removing text-based filter should remove it from the query', () => { | ||
| wrapper.vm.resetKeywords(); | ||
| expect(wrapper.vm.$route.query.keywords).toBeUndefined(); | ||
|
|
||
| // Make sure other queries weren't affected | ||
| expect(wrapper.vm.$route.query.coach).toBeTruthy(); | ||
| expect(wrapper.vm.$route.query.collection).toBeTruthy(); | ||
| expect(wrapper.vm.$route.query.languages).toBeTruthy(); | ||
| }); | ||
|
|
||
| it('removing boolean-based filter should remove it from the query', async () => { | ||
| const user = userEvent.setup(); | ||
| makeWrapper(); | ||
|
|
||
| await closeChipByText(user, 'Coach content'); | ||
|
|
||
| await waitFor(() => { | ||
| expect(router.currentRoute.query.coach).toBeUndefined(); | ||
| expect(router.currentRoute.query.collection).toBeTruthy(); | ||
| expect(router.currentRoute.query.languages).toBeTruthy(); | ||
| expect(router.currentRoute.query.keywords).toBeTruthy(); | ||
| }); | ||
| it('removing boolean-based filter should remove it from the query', () => { | ||
| wrapper.vm.resetCoach(); | ||
| expect(wrapper.vm.$route.query.coach).toBeUndefined(); | ||
|
|
||
| // Make sure other queries weren't affected | ||
| expect(wrapper.vm.$route.query.collection).toBeTruthy(); | ||
| expect(wrapper.vm.$route.query.languages).toBeTruthy(); | ||
| expect(wrapper.vm.$route.query.keywords).toBeTruthy(); | ||
| }); | ||
|
|
||
| it('removing list-based filter should only remove that item from the query', async () => { | ||
| const user = userEvent.setup(); | ||
| makeWrapper(); | ||
| await closeChipByText(user, 'English'); | ||
|
|
||
| await waitFor(() => { | ||
| expect(router.currentRoute.query.languages).toBe('es'); | ||
| }); | ||
| it('removing list-based filter should only remove that item from the query', () => { | ||
| wrapper.vm.removeLanguage('en'); | ||
| expect(wrapper.vm.$route.query.languages).toBe('es'); | ||
|
|
||
| wrapper.vm.removeLanguage('es'); | ||
| expect(wrapper.vm.$route.query.languages).toBeUndefined(); | ||
| await closeChipByText(user, 'Español'); | ||
|
|
||
| // Make sure other queries weren't affected | ||
| expect(wrapper.vm.$route.query.coach).toBeTruthy(); | ||
| expect(wrapper.vm.$route.query.collection).toBeTruthy(); | ||
| expect(wrapper.vm.$route.query.keywords).toBeTruthy(); | ||
| await waitFor(() => { | ||
| expect(router.currentRoute.query.languages).toBeUndefined(); | ||
| expect(router.currentRoute.query.coach).toBeTruthy(); | ||
| expect(router.currentRoute.query.collection).toBeTruthy(); | ||
| expect(router.currentRoute.query.keywords).toBeTruthy(); | ||
| }); | ||
| }); | ||
| }); | ||
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 is redundant as we already have it registered in
jest_config/setup.js.