diff --git a/contentcuration/contentcuration/frontend/shared/views/QTIEditor/components/ValidationMessage/__tests__/ValidationMessage.spec.js b/contentcuration/contentcuration/frontend/shared/views/QTIEditor/components/ValidationMessage/__tests__/ValidationMessage.spec.js new file mode 100644 index 0000000000..e5f0e8d996 --- /dev/null +++ b/contentcuration/contentcuration/frontend/shared/views/QTIEditor/components/ValidationMessage/__tests__/ValidationMessage.spec.js @@ -0,0 +1,32 @@ +import { render } from '@testing-library/vue'; +import VueRouter from 'vue-router'; +import useKLiveRegion from 'kolibri-design-system/lib/composables/useKLiveRegion'; +import ValidationMessage from '../index.vue'; + +jest.mock('kolibri-design-system/lib/composables/useKLiveRegion'); + +let sendPoliteMessage; + +beforeEach(() => { + sendPoliteMessage = jest.fn(); + useKLiveRegion.mockReturnValue({ sendPoliteMessage }); +}); + +const renderWarning = props => + render(ValidationMessage, { + props: { warning: true, ...props }, + slots: { default: 'Too many options.' }, + routes: new VueRouter(), + }); + +describe('ValidationMessage', () => { + it('announces a warning politely as it appears', () => { + renderWarning(); + expect(sendPoliteMessage).toHaveBeenCalledWith('Too many options.'); + }); + + it('does not announce a warning with alert off', () => { + renderWarning({ alert: false }); + expect(sendPoliteMessage).not.toHaveBeenCalled(); + }); +}); diff --git a/contentcuration/contentcuration/frontend/shared/views/QTIEditor/components/ValidationMessage/index.vue b/contentcuration/contentcuration/frontend/shared/views/QTIEditor/components/ValidationMessage/index.vue index 2f917c3353..ab7cbd11ce 100644 --- a/contentcuration/contentcuration/frontend/shared/views/QTIEditor/components/ValidationMessage/index.vue +++ b/contentcuration/contentcuration/frontend/shared/views/QTIEditor/components/ValidationMessage/index.vue @@ -39,7 +39,7 @@ // A polite region inserted already filled is often skipped by screen readers, // so announce through KDS's persistent live region instead. function announceWarning() { - if (props.warning) { + if (props.warning && props.alert) { sendPoliteMessage(warningText.value.textContent.trim()); } } @@ -56,8 +56,8 @@ default: false, }, /** - * Whether an error is an alert, read out as it appears. Off when the component showing - * it announces its messages itself. + * Whether the message is read out as it appears: an error as an alert, a warning + * politely. Off when the component showing it announces its messages itself. */ alert: { type: Boolean, diff --git a/contentcuration/contentcuration/frontend/shared/views/QTIEditor/constants.js b/contentcuration/contentcuration/frontend/shared/views/QTIEditor/constants.js index 0858586bff..ac0ffce871 100644 --- a/contentcuration/contentcuration/frontend/shared/views/QTIEditor/constants.js +++ b/contentcuration/contentcuration/frontend/shared/views/QTIEditor/constants.js @@ -181,6 +181,8 @@ export const ConversionLoss = Object.freeze({ SETTINGS_REMOVED: 'SETTINGS_REMOVED', }); +export const RECOMMENDED_MAX_OPTIONS = 5; + export const RESPONSE_IDENTIFIER = 'RESPONSE'; export const SENTINEL_MARKER = 'data-studio-sentinel'; diff --git a/contentcuration/contentcuration/frontend/shared/views/QTIEditor/interactions/associate/Editor.vue b/contentcuration/contentcuration/frontend/shared/views/QTIEditor/interactions/associate/Editor.vue index daa93cd9d8..dded233e58 100644 --- a/contentcuration/contentcuration/frontend/shared/views/QTIEditor/interactions/associate/Editor.vue +++ b/contentcuration/contentcuration/frontend/shared/views/QTIEditor/interactions/associate/Editor.vue @@ -55,10 +55,18 @@
Match each character to his adversary.
The ${chip('r1', options, 'o0')} rises
` }), + }); + }; + const openClearingAnnouncements = async user => { + mockSendAssertiveMessage.mockClear(); + mockSendPoliteMessage.mockClear(); + return openChip(user, 0); + }; + + it('does not warn on a dropdown with 5 options', async () => { + const { user } = await renderWithOptions(5); + await openChip(user, 0); + expect(within(dialog()).queryByText(tooManyWarning())).not.toBeInTheDocument(); + }); + + it('describes the panel of a dropdown with 6 options with it, unannounced', async () => { + const { emitted, user } = await renderWithOptions(6); + expect(emitted()['update:errors'].at(-1)[0]).toEqual([]); + await openClearingAnnouncements(user); + expect(dialog()).toHaveAccessibleDescription(tooManyWarning()); + expect(mockSendPoliteMessage).not.toHaveBeenCalled(); + expect(mockSendAssertiveMessage).not.toHaveBeenCalled(); + }); + + it('announces it politely once when a 6th option is added', async () => { + const { user } = await renderWithOptions(5); + await openClearingAnnouncements(user); + await user.click(screen.getByRole('button', { name: tr.addInlineChoiceOptionBtn$() })); + await waitFor(() => expect(mockSendPoliteMessage).toHaveBeenCalled()); + expect(mockSendPoliteMessage.mock.calls).toEqual([[tooManyWarning()]]); + expect(within(dialog()).getByText(tooManyWarning())).toBeInTheDocument(); + expect(mockSendAssertiveMessage).not.toHaveBeenCalled(); + }); + + it('stops warning once an option is removed, leaving 5', async () => { + const { user } = await renderWithOptions(6); + await openChip(user, 0); + await user.click( + screen.getByRole('button', { name: tr.deleteInlineChoiceOptionBtn$({ number: 6 }) }), + ); + expect(within(dialog()).queryByText(tooManyWarning())).not.toBeInTheDocument(); + }); + }); + it('shows a passage without dropdowns on the passage editor', async () => { render(InlineChoiceEditor, { props: { diff --git a/contentcuration/contentcuration/frontend/shared/views/QTIEditor/interactions/inlineChoice/components/InlineChoiceOptions/index.vue b/contentcuration/contentcuration/frontend/shared/views/QTIEditor/interactions/inlineChoice/components/InlineChoiceOptions/index.vue index 28bbc3f93d..6401556787 100644 --- a/contentcuration/contentcuration/frontend/shared/views/QTIEditor/interactions/inlineChoice/components/InlineChoiceOptions/index.vue +++ b/contentcuration/contentcuration/frontend/shared/views/QTIEditor/interactions/inlineChoice/components/InlineChoiceOptions/index.vue @@ -12,20 +12,23 @@ role="dialog" aria-modal="true" :aria-label="inlineChoiceOptionsDialogLabel$({ number })" - :aria-describedby="problems.length ? problems.map((_, i) => problemId(i)).join(' ') : null" + :aria-describedby=" + panelMessages.length ? panelMessages.map((_, i) => panelMessageId(i)).join(' ') : null + " class="options-panel" @focusout="onFocusout" @keydown="onHistoryKeydown" @keydown.esc.stop="$emit('close')" > - +