-
Notifications
You must be signed in to change notification settings - Fork 286
[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
Open
sharma-anushka
wants to merge
7
commits into
learningequality:unstable
Choose a base branch
from
sharma-anushka:fix-issue-5649
base: unstable
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+76
−47
Open
[Remove Vuetify from Studio] Convert content library filter bar unit tests to Vue Testing Library #5653
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
53dd04d
changed catalogFIlterBar.spec.js to use VTL instead of VTU
sharma-anushka b2ee899
[pre-commit.ci lite] apply automatic fixes
pre-commit-ci-lite[bot] 2cf5184
refactor CatalogFilterBar tests to remove Vuetify implementation
sharma-anushka 988b3e5
refactor CatalogFilterBar tests to remove Vuetify coupling
sharma-anushka 7294eca
[pre-commit.ci lite] apply automatic fixes
pre-commit-ci-lite[bot] 5f379f2
changed according to the feedback
sharma-anushka 1a72cdd
[pre-commit.ci lite] apply automatic fixes
pre-commit-ci-lite[bot] File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 |
|---|---|---|
| @@ -1,13 +1,10 @@ | ||
| import { mount } from '@vue/test-utils'; | ||
| import { render, screen, waitFor } from '@testing-library/vue'; | ||
| import userEvent from '@testing-library/user-event'; | ||
| import { factory } from '../../../store'; | ||
| import router from '../../../router'; | ||
| import CatalogFilterBar from '../CatalogFilterBar'; | ||
|
|
||
| const store = factory(); | ||
|
|
||
| const collection = { | ||
| id: 'test-collection', | ||
| }; | ||
| const collection = { id: 'test-collection' }; | ||
|
|
||
| const query = { | ||
| keywords: 'testing', | ||
|
|
@@ -16,11 +13,21 @@ 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('.v-chip__close'); | ||
|
|
||
| await user.click(closeButton); | ||
| } | ||
|
|
||
| function makeWrapper() { | ||
| return mount(CatalogFilterBar, { | ||
| sync: false, | ||
| router, | ||
| const store = factory(); | ||
|
|
||
| return render(CatalogFilterBar, { | ||
| // localVue, | ||
| store, | ||
| router, | ||
| computed: { | ||
| collections() { | ||
| return [collection]; | ||
|
|
@@ -30,52 +37,73 @@ function makeWrapper() { | |
| } | ||
|
|
||
| describe('catalogFilterBar', () => { | ||
| let wrapper; | ||
| beforeEach(() => { | ||
| wrapper = makeWrapper(); | ||
| router | ||
| .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(); | ||
| }); | ||
| }); | ||
| }); | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Router is set up in both
makeWrapper()andbeforeEach()is there a specific reason for this?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.
Hi, No. Thankyou for catching it, I have removed it now.