-
-
Notifications
You must be signed in to change notification settings - Fork 301
Convert accessibility options unit tests to Vue Testing Library #5794 #5889
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
LightCreator1007
wants to merge
4
commits into
learningequality:unstable
Choose a base branch
from
LightCreator1007:convert-accessibilityOptions-unit-tests-to-vtl
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.
+107
−74
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
64a8f15
tests: Converted Accessibility Options test to VTL
LightCreator1007 f5ab93e
refactored test's over-reliance on getByTestId to follow vtl's query …
LightCreator1007 f194408
[pre-commit.ci lite] apply automatic fixes
pre-commit-ci-lite[bot] 72edd5d
fix: refine AccessibilityOptions VTL migration according to recieved …
LightCreator1007 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
181 changes: 107 additions & 74 deletions
181
...ntentcuration/frontend/channelEdit/components/edit/__tests__/accessibilityOptions.spec.js
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,101 +1,134 @@ | ||
| import { shallowMount, mount } from '@vue/test-utils'; | ||
| import { render, screen, configure } from '@testing-library/vue'; | ||
| import userEvent from '@testing-library/user-event'; | ||
| import AccessibilityOptions from '../AccessibilityOptions.vue'; | ||
| import { AccessibilityCategories } from 'shared/constants'; | ||
|
|
||
| beforeAll(() => { | ||
| configure({ testIdAttribute: 'data-test' }); | ||
| }); | ||
|
|
||
| afterAll(() => { | ||
| configure({ testIdAttribute: 'data-testid' }); | ||
| }); | ||
|
|
||
| describe('AccessibilityOptions', () => { | ||
| it('smoke test', () => { | ||
| const wrapper = shallowMount(AccessibilityOptions, { | ||
| propsData: { | ||
| const mockMetadataMixin = { | ||
| methods: { | ||
| translateMetadataString: str => str, | ||
| }, | ||
| }; | ||
|
|
||
| const renderComponent = props => { | ||
| return render(AccessibilityOptions, { | ||
| props: { | ||
| kind: 'document', | ||
| value: [], | ||
| ...props, | ||
| }, | ||
| routes: [], | ||
| mixins: [mockMetadataMixin], | ||
| mocks: { | ||
| $tr: key => key, | ||
| }, | ||
| }); | ||
| expect(wrapper.exists()).toBe(true); | ||
| }; | ||
|
|
||
| it('renders successfully', () => { | ||
| renderComponent(); | ||
| expect(screen.getAllByRole('checkbox').length).toBeGreaterThan(0); | ||
| }); | ||
|
|
||
| it('should display the correct list of accessibility options if resource is a document', () => { | ||
| const wrapper = mount(AccessibilityOptions, { | ||
| propsData: { | ||
| kind: 'document', | ||
| }, | ||
| }); | ||
| it('shows document-specific accessibility options to the user', () => { | ||
| renderComponent({ kind: 'document' }); | ||
|
|
||
| expect(wrapper.findComponent('[data-test="checkbox-altText"]').exists()).toBe(true); | ||
| expect(wrapper.findComponent('[data-test="checkbox-highContrast"]').exists()).toBe(true); | ||
| expect(wrapper.findComponent('[data-test="checkbox-taggedPdf"]').exists()).toBe(true); | ||
| expect(wrapper.findComponent('[data-test="checkbox-signLanguage"]').exists()).toBe(false); | ||
| expect(wrapper.findComponent('[data-test="checkbox-audioDescription"]').exists()).toBe(false); | ||
| const checkboxes = screen.getAllByRole('checkbox'); | ||
| expect(checkboxes).toHaveLength(3); | ||
|
|
||
| expect(screen.getByRole('checkbox', { name: /altText/i })).toBeInTheDocument(); | ||
| expect(screen.getByRole('checkbox', { name: /highContrast/i })).toBeInTheDocument(); | ||
| expect(screen.getByRole('checkbox', { name: /taggedPdf/i })).toBeInTheDocument(); | ||
| }); | ||
|
|
||
| it('should display the correct list of accessibility options if resource is a video', () => { | ||
| const wrapper = mount(AccessibilityOptions, { | ||
| propsData: { | ||
| kind: 'video', | ||
| }, | ||
| }); | ||
| it('shows video-specific accessibility options to the user', () => { | ||
| renderComponent({ kind: 'video' }); | ||
|
|
||
| const checkboxes = screen.getAllByRole('checkbox'); | ||
| expect(checkboxes).toHaveLength(3); | ||
|
|
||
| expect(wrapper.findComponent('[data-test="checkbox-altText"]').exists()).toBe(false); | ||
| expect(wrapper.findComponent('[data-test="checkbox-highContrast"]').exists()).toBe(false); | ||
| expect(wrapper.findComponent('[data-test="checkbox-taggedPdf"]').exists()).toBe(false); | ||
| expect(wrapper.findComponent('[data-test="checkbox-signLanguage"]').exists()).toBe(true); | ||
| expect(wrapper.findComponent('[data-test="checkbox-audioDescription"]').exists()).toBe(true); | ||
| expect(wrapper.findComponent('[data-test="checkbox-captionsSubtitles"]').exists()).toBe(true); | ||
| expect(wrapper.findComponent('[data-test="tooltip-captionsSubtitles"]').exists()).toBe(false); | ||
| expect(screen.getByRole('checkbox', { name: /signLanguage/i })).toBeInTheDocument(); | ||
| expect(screen.getByRole('checkbox', { name: /audioDescription/i })).toBeInTheDocument(); | ||
| expect(screen.getByRole('checkbox', { name: /captionsSubtitles/i })).toBeInTheDocument(); | ||
|
|
||
| expect(screen.queryByTestId('tooltip-captionsSubtitles')).not.toBeInTheDocument(); | ||
| }); | ||
|
|
||
| it('should display the correct list of accessibility options if resource is an exercise/practice', () => { | ||
| const wrapper = mount(AccessibilityOptions, { | ||
| propsData: { | ||
| kind: 'exercise', | ||
| }, | ||
| }); | ||
| it('shows exercise-specific accessibility options to the user', () => { | ||
| renderComponent({ kind: 'exercise' }); | ||
|
|
||
| expect(wrapper.findComponent('[data-test="checkbox-altText"]').exists()).toBe(true); | ||
| expect(wrapper.findComponent('[data-test="checkbox-highContrast"]').exists()).toBe(false); | ||
| expect(wrapper.findComponent('[data-test="checkbox-taggedPdf"]').exists()).toBe(false); | ||
| expect(wrapper.findComponent('[data-test="checkbox-signLanguage"]').exists()).toBe(false); | ||
| expect(wrapper.findComponent('[data-test="checkbox-audioDescription"]').exists()).toBe(false); | ||
| const checkboxes = screen.getAllByRole('checkbox'); | ||
| expect(checkboxes).toHaveLength(1); | ||
| expect(screen.getByRole('checkbox', { name: /altText/i })).toBeInTheDocument(); | ||
| }); | ||
|
|
||
| it('should display the correct list of accessibility options if resource is html5/zip', () => { | ||
| const wrapper = mount(AccessibilityOptions, { | ||
| propsData: { | ||
| kind: 'html5', | ||
| }, | ||
| }); | ||
| it('shows HTML5-specific accessibility options to the user', () => { | ||
| renderComponent({ kind: 'html5' }); | ||
|
|
||
| expect(wrapper.findComponent('[data-test="checkbox-altText"]').exists()).toBe(true); | ||
| expect(wrapper.findComponent('[data-test="checkbox-highContrast"]').exists()).toBe(true); | ||
| expect(wrapper.findComponent('[data-test="checkbox-taggedPdf"]').exists()).toBe(false); | ||
| expect(wrapper.findComponent('[data-test="checkbox-signLanguage"]').exists()).toBe(false); | ||
| expect(wrapper.findComponent('[data-test="checkbox-audioDescription"]').exists()).toBe(false); | ||
| const checkboxes = screen.getAllByRole('checkbox'); | ||
| expect(checkboxes).toHaveLength(2); | ||
| expect(screen.getByRole('checkbox', { name: /altText/i })).toBeInTheDocument(); | ||
| expect(screen.getByRole('checkbox', { name: /highContrast/i })).toBeInTheDocument(); | ||
| }); | ||
|
|
||
| it('should display the correct list of accessibility options if resource is an audio', () => { | ||
| const wrapper = mount(AccessibilityOptions, { | ||
| propsData: { | ||
| kind: 'audio', | ||
| }, | ||
| }); | ||
| it('shows audio-specific accessibility options to the user', () => { | ||
|
LightCreator1007 marked this conversation as resolved.
|
||
| renderComponent({ kind: 'audio' }); | ||
|
|
||
| expect(wrapper.findComponent('[data-test="checkbox-captionsSubtitles"]').exists()).toBe(true); | ||
| expect(wrapper.findComponent('[data-test="tooltip-captionsSubtitles"]').exists()).toBe(false); | ||
| const checkboxes = screen.getAllByRole('checkbox'); | ||
| expect(checkboxes).toHaveLength(1); | ||
| expect(screen.getByRole('checkbox', { name: /captionsSubtitles/i })).toBeInTheDocument(); | ||
| expect(screen.queryByTestId('tooltip-captionsSubtitles')).not.toBeInTheDocument(); | ||
| }); | ||
|
|
||
| it('should render appropriate tooltips along with the checkbox', () => { | ||
| const wrapper = mount(AccessibilityOptions, { | ||
| propsData: { | ||
| kind: 'document', | ||
| }, | ||
| it('renders informative tooltips next to the corresponding options', () => { | ||
| renderComponent({ kind: 'document' }); | ||
|
|
||
| expect(screen.getByTestId('tooltip-altText')).toBeInTheDocument(); | ||
| expect(screen.getByTestId('tooltip-highContrast')).toBeInTheDocument(); | ||
| expect(screen.getByTestId('tooltip-taggedPdf')).toBeInTheDocument(); | ||
| }); | ||
|
|
||
| describe('User Interactions', () => { | ||
| it('emits an input event with the updated array when a user checks an option', async () => { | ||
|
LightCreator1007 marked this conversation as resolved.
|
||
| const { emitted } = renderComponent({ kind: 'document', value: [] }); | ||
|
|
||
| const altTextCheckbox = screen.getByRole('checkbox', { name: /altText/i }); | ||
|
LightCreator1007 marked this conversation as resolved.
|
||
| await userEvent.click(altTextCheckbox); | ||
|
|
||
| expect(emitted()).toHaveProperty('input'); | ||
| expect(emitted().input[0][0]).toEqual([AccessibilityCategories.ALT_TEXT]); | ||
| }); | ||
|
|
||
| expect(wrapper.findComponent('[data-test="checkbox-altText"]').exists()).toBe(true); | ||
| expect(wrapper.findComponent('[data-test="tooltip-altText"]').exists()).toBe(true); | ||
| expect(wrapper.findComponent('[data-test="checkbox-highContrast"]').exists()).toBe(true); | ||
| expect(wrapper.findComponent('[data-test="tooltip-highContrast"]').exists()).toBe(true); | ||
| expect(wrapper.findComponent('[data-test="checkbox-taggedPdf"]').exists()).toBe(true); | ||
| expect(wrapper.findComponent('[data-test="tooltip-taggedPdf"]').exists()).toBe(true); | ||
| expect(wrapper.findComponent('[data-test="checkbox-signLanguage"]').exists()).toBe(false); | ||
| expect(wrapper.findComponent('[data-test="tooltip-signLanguage"]').exists()).toBe(false); | ||
| expect(wrapper.findComponent('[data-test="checkbox-audioDescription"]').exists()).toBe(false); | ||
| expect(wrapper.findComponent('[data-test="tooltip-audioDescription"]').exists()).toBe(false); | ||
| it('emits an updated array with the item removed when a user unchecks a pre-checked option', async () => { | ||
| const { emitted } = renderComponent({ | ||
| kind: 'video', | ||
| value: [AccessibilityCategories.SIGN_LANGUAGE], | ||
| }); | ||
|
|
||
| const signLanguageCheckbox = screen.getByRole('checkbox', { name: /signLanguage/i }); | ||
| await userEvent.click(signLanguageCheckbox); | ||
|
|
||
| expect(emitted()).toHaveProperty('input'); | ||
| expect(emitted().input[0][0]).toEqual([]); | ||
| }); | ||
|
|
||
| it('renders correctly when accessibility options are pre-checked via v-model', () => { | ||
| renderComponent({ | ||
| kind: 'video', | ||
| value: [AccessibilityCategories.SIGN_LANGUAGE, AccessibilityCategories.CAPTIONS_SUBTITLES], | ||
| }); | ||
|
|
||
| expect(screen.getByRole('checkbox', { name: /signLanguage/i })).toBeChecked(); | ||
| expect(screen.getByRole('checkbox', { name: /captionsSubtitles/i })).toBeChecked(); | ||
| expect(screen.getByRole('checkbox', { name: /audioDescription/i })).not.toBeChecked(); | ||
| }); | ||
| }); | ||
| }); | ||
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.