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 @@
{{ errorTooFewPairs$() }} + + {{ tooManyPairsWarning }} +

+ + {{ tooManyDistractorsWarning }} +