|
1 | | -import { shallowMount, mount } from '@vue/test-utils'; |
| 1 | +import { render, screen, within, configure } from '@testing-library/vue'; |
| 2 | +import userEvent from '@testing-library/user-event'; |
| 3 | +import VueRouter from 'vue-router'; |
2 | 4 | import AccessibilityOptions from '../AccessibilityOptions.vue'; |
| 5 | +import { AccessibilityCategories } from 'shared/constants'; |
| 6 | +import { metadataStrings } from 'shared/strings/metadataStrings'; |
| 7 | +import { ContentKindsNames } from 'shared/leUtils/ContentKinds'; |
| 8 | + |
| 9 | +configure({ testIdAttribute: 'data-test' }); |
3 | 10 |
|
4 | 11 | describe('AccessibilityOptions', () => { |
5 | | - it('smoke test', () => { |
6 | | - const wrapper = shallowMount(AccessibilityOptions, { |
7 | | - propsData: { |
8 | | - kind: 'document', |
| 12 | + const renderComponent = props => { |
| 13 | + return render(AccessibilityOptions, { |
| 14 | + props: { |
| 15 | + kind: ContentKindsNames.DOCUMENT, |
| 16 | + value: [], |
| 17 | + ...props, |
9 | 18 | }, |
| 19 | + routes: new VueRouter(), |
10 | 20 | }); |
11 | | - expect(wrapper.exists()).toBe(true); |
| 21 | + }; |
| 22 | + |
| 23 | + it('shows document-specific accessibility options to the user', () => { |
| 24 | + renderComponent({ kind: ContentKindsNames.DOCUMENT }); |
| 25 | + |
| 26 | + const checkboxes = screen.getAllByRole('checkbox'); |
| 27 | + expect(checkboxes).toHaveLength(3); |
| 28 | + |
| 29 | + expect(screen.getByText(metadataStrings.$tr('altText'))).toBeInTheDocument(); |
| 30 | + expect(screen.getByText(metadataStrings.$tr('highContrast'))).toBeInTheDocument(); |
| 31 | + expect(screen.getByText(metadataStrings.$tr('taggedPdf'))).toBeInTheDocument(); |
12 | 32 | }); |
13 | 33 |
|
14 | | - it('should display the correct list of accessibility options if resource is a document', () => { |
15 | | - const wrapper = mount(AccessibilityOptions, { |
16 | | - propsData: { |
17 | | - kind: 'document', |
18 | | - }, |
19 | | - }); |
| 34 | + it('shows video-specific accessibility options to the user', () => { |
| 35 | + renderComponent({ kind: ContentKindsNames.VIDEO }); |
| 36 | + |
| 37 | + const checkboxes = screen.getAllByRole('checkbox'); |
| 38 | + expect(checkboxes).toHaveLength(3); |
20 | 39 |
|
21 | | - expect(wrapper.findComponent('[data-test="checkbox-altText"]').exists()).toBe(true); |
22 | | - expect(wrapper.findComponent('[data-test="checkbox-highContrast"]').exists()).toBe(true); |
23 | | - expect(wrapper.findComponent('[data-test="checkbox-taggedPdf"]').exists()).toBe(true); |
24 | | - expect(wrapper.findComponent('[data-test="checkbox-signLanguage"]').exists()).toBe(false); |
25 | | - expect(wrapper.findComponent('[data-test="checkbox-audioDescription"]').exists()).toBe(false); |
| 40 | + expect(screen.getByText(metadataStrings.$tr('signLanguage'))).toBeInTheDocument(); |
| 41 | + expect(screen.getByText(metadataStrings.$tr('audioDescription'))).toBeInTheDocument(); |
| 42 | + expect(screen.getByText(metadataStrings.$tr('captionsSubtitles'))).toBeInTheDocument(); |
| 43 | + |
| 44 | + expect(screen.queryByTestId('tooltip-captionsSubtitles')).not.toBeInTheDocument(); |
26 | 45 | }); |
27 | 46 |
|
28 | | - it('should display the correct list of accessibility options if resource is a video', () => { |
29 | | - const wrapper = mount(AccessibilityOptions, { |
30 | | - propsData: { |
31 | | - kind: 'video', |
32 | | - }, |
33 | | - }); |
| 47 | + it('shows exercise-specific accessibility options to the user', () => { |
| 48 | + renderComponent({ kind: ContentKindsNames.EXERCISE }); |
| 49 | + |
| 50 | + const checkboxes = screen.getAllByRole('checkbox'); |
| 51 | + expect(checkboxes).toHaveLength(1); |
34 | 52 |
|
35 | | - expect(wrapper.findComponent('[data-test="checkbox-altText"]').exists()).toBe(false); |
36 | | - expect(wrapper.findComponent('[data-test="checkbox-highContrast"]').exists()).toBe(false); |
37 | | - expect(wrapper.findComponent('[data-test="checkbox-taggedPdf"]').exists()).toBe(false); |
38 | | - expect(wrapper.findComponent('[data-test="checkbox-signLanguage"]').exists()).toBe(true); |
39 | | - expect(wrapper.findComponent('[data-test="checkbox-audioDescription"]').exists()).toBe(true); |
40 | | - expect(wrapper.findComponent('[data-test="checkbox-captionsSubtitles"]').exists()).toBe(true); |
41 | | - expect(wrapper.findComponent('[data-test="tooltip-captionsSubtitles"]').exists()).toBe(false); |
| 53 | + expect(screen.getByText(metadataStrings.$tr('altText'))).toBeInTheDocument(); |
42 | 54 | }); |
43 | 55 |
|
44 | | - it('should display the correct list of accessibility options if resource is an exercise/practice', () => { |
45 | | - const wrapper = mount(AccessibilityOptions, { |
46 | | - propsData: { |
47 | | - kind: 'exercise', |
48 | | - }, |
49 | | - }); |
| 56 | + it('shows HTML5-specific accessibility options to the user', () => { |
| 57 | + renderComponent({ kind: ContentKindsNames.HTML5 }); |
| 58 | + |
| 59 | + const checkboxes = screen.getAllByRole('checkbox'); |
| 60 | + expect(checkboxes).toHaveLength(2); |
50 | 61 |
|
51 | | - expect(wrapper.findComponent('[data-test="checkbox-altText"]').exists()).toBe(true); |
52 | | - expect(wrapper.findComponent('[data-test="checkbox-highContrast"]').exists()).toBe(false); |
53 | | - expect(wrapper.findComponent('[data-test="checkbox-taggedPdf"]').exists()).toBe(false); |
54 | | - expect(wrapper.findComponent('[data-test="checkbox-signLanguage"]').exists()).toBe(false); |
55 | | - expect(wrapper.findComponent('[data-test="checkbox-audioDescription"]').exists()).toBe(false); |
| 62 | + expect(screen.getByText(metadataStrings.$tr('altText'))).toBeInTheDocument(); |
| 63 | + expect(screen.getByText(metadataStrings.$tr('highContrast'))).toBeInTheDocument(); |
56 | 64 | }); |
57 | 65 |
|
58 | | - it('should display the correct list of accessibility options if resource is html5/zip', () => { |
59 | | - const wrapper = mount(AccessibilityOptions, { |
60 | | - propsData: { |
61 | | - kind: 'html5', |
62 | | - }, |
63 | | - }); |
| 66 | + it('shows audio-specific accessibility options to the user', () => { |
| 67 | + renderComponent({ kind: ContentKindsNames.AUDIO }); |
64 | 68 |
|
65 | | - expect(wrapper.findComponent('[data-test="checkbox-altText"]').exists()).toBe(true); |
66 | | - expect(wrapper.findComponent('[data-test="checkbox-highContrast"]').exists()).toBe(true); |
67 | | - expect(wrapper.findComponent('[data-test="checkbox-taggedPdf"]').exists()).toBe(false); |
68 | | - expect(wrapper.findComponent('[data-test="checkbox-signLanguage"]').exists()).toBe(false); |
69 | | - expect(wrapper.findComponent('[data-test="checkbox-audioDescription"]').exists()).toBe(false); |
| 69 | + const checkboxes = screen.getAllByRole('checkbox'); |
| 70 | + expect(checkboxes).toHaveLength(1); |
| 71 | + |
| 72 | + expect(screen.getByText(metadataStrings.$tr('captionsSubtitles'))).toBeInTheDocument(); |
| 73 | + expect(screen.queryByTestId('tooltip-captionsSubtitles')).not.toBeInTheDocument(); |
70 | 74 | }); |
71 | 75 |
|
72 | | - it('should display the correct list of accessibility options if resource is an audio', () => { |
73 | | - const wrapper = mount(AccessibilityOptions, { |
74 | | - propsData: { |
75 | | - kind: 'audio', |
76 | | - }, |
77 | | - }); |
| 76 | + it('renders informative tooltips next to the corresponding options', () => { |
| 77 | + renderComponent({ kind: ContentKindsNames.DOCUMENT }); |
78 | 78 |
|
79 | | - expect(wrapper.findComponent('[data-test="checkbox-captionsSubtitles"]').exists()).toBe(true); |
80 | | - expect(wrapper.findComponent('[data-test="tooltip-captionsSubtitles"]').exists()).toBe(false); |
| 79 | + expect(screen.getByTestId('tooltip-altText')).toBeInTheDocument(); |
| 80 | + expect(screen.getByTestId('tooltip-highContrast')).toBeInTheDocument(); |
| 81 | + expect(screen.getByTestId('tooltip-taggedPdf')).toBeInTheDocument(); |
81 | 82 | }); |
82 | 83 |
|
83 | | - it('should render appropriate tooltips along with the checkbox', () => { |
84 | | - const wrapper = mount(AccessibilityOptions, { |
85 | | - propsData: { |
86 | | - kind: 'document', |
87 | | - }, |
| 84 | + describe('User Interactions', () => { |
| 85 | + it('emits an input event with the updated array when a user checks an option', async () => { |
| 86 | + const { emitted } = renderComponent({ kind: ContentKindsNames.DOCUMENT, value: [] }); |
| 87 | + |
| 88 | + const altTextCheckbox = within(screen.getByTestId('checkbox-altText')).getByRole('checkbox'); |
| 89 | + await userEvent.click(altTextCheckbox); |
| 90 | + |
| 91 | + expect(emitted()).toHaveProperty('input'); |
| 92 | + expect(emitted().input[0][0]).toEqual([AccessibilityCategories.ALT_TEXT]); |
88 | 93 | }); |
89 | 94 |
|
90 | | - expect(wrapper.findComponent('[data-test="checkbox-altText"]').exists()).toBe(true); |
91 | | - expect(wrapper.findComponent('[data-test="tooltip-altText"]').exists()).toBe(true); |
92 | | - expect(wrapper.findComponent('[data-test="checkbox-highContrast"]').exists()).toBe(true); |
93 | | - expect(wrapper.findComponent('[data-test="tooltip-highContrast"]').exists()).toBe(true); |
94 | | - expect(wrapper.findComponent('[data-test="checkbox-taggedPdf"]').exists()).toBe(true); |
95 | | - expect(wrapper.findComponent('[data-test="tooltip-taggedPdf"]').exists()).toBe(true); |
96 | | - expect(wrapper.findComponent('[data-test="checkbox-signLanguage"]').exists()).toBe(false); |
97 | | - expect(wrapper.findComponent('[data-test="tooltip-signLanguage"]').exists()).toBe(false); |
98 | | - expect(wrapper.findComponent('[data-test="checkbox-audioDescription"]').exists()).toBe(false); |
99 | | - expect(wrapper.findComponent('[data-test="tooltip-audioDescription"]').exists()).toBe(false); |
| 95 | + it('emits an updated array with the item removed when a user unchecks a pre-checked option', async () => { |
| 96 | + const { emitted } = renderComponent({ |
| 97 | + kind: ContentKindsNames.VIDEO, |
| 98 | + value: [AccessibilityCategories.SIGN_LANGUAGE], |
| 99 | + }); |
| 100 | + |
| 101 | + const signLanguageCheckbox = within(screen.getByTestId('checkbox-signLanguage')).getByRole( |
| 102 | + 'checkbox', |
| 103 | + ); |
| 104 | + await userEvent.click(signLanguageCheckbox); |
| 105 | + |
| 106 | + expect(emitted()).toHaveProperty('input'); |
| 107 | + expect(emitted().input[0][0]).toEqual([]); |
| 108 | + }); |
| 109 | + |
| 110 | + it('renders correctly when accessibility options are pre-checked via v-model', () => { |
| 111 | + renderComponent({ |
| 112 | + kind: ContentKindsNames.VIDEO, |
| 113 | + value: [AccessibilityCategories.SIGN_LANGUAGE, AccessibilityCategories.CAPTIONS_SUBTITLES], |
| 114 | + }); |
| 115 | + |
| 116 | + expect( |
| 117 | + within(screen.getByTestId('checkbox-signLanguage')).getByRole('checkbox'), |
| 118 | + ).toBeChecked(); |
| 119 | + expect( |
| 120 | + within(screen.getByTestId('checkbox-captionsSubtitles')).getByRole('checkbox'), |
| 121 | + ).toBeChecked(); |
| 122 | + expect( |
| 123 | + within(screen.getByTestId('checkbox-audioDescription')).getByRole('checkbox'), |
| 124 | + ).not.toBeChecked(); |
| 125 | + }); |
100 | 126 | }); |
101 | 127 | }); |
0 commit comments