Repository navigation
Question type conversion #6311
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
Draft
AlexVelezLl
wants to merge
14
commits into
learningequality:unstable
Choose a base branch
from
AlexVelezLl:question-type-conversion
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.
+7,851
−477
Draft
Question type conversion #6311
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
80846aa
Write no warning when not every response can be scored
AlexVelezLl 6a20b89
Fit the prominent insert action in with the toolbar's other tools
AlexVelezLl b3d006f
Document that an expanded popup keeps the rich text editor open
AlexVelezLl 18479dc
Move the caret past inline choice chips instead of selecting them
AlexVelezLl 724a920
Read a rich text editor's stored HTML through one helper
AlexVelezLl ea3536b
Add the inline choice interaction editor
AlexVelezLl e3a4126
Make inline choice chips easier to use with a keyboard or screen reader
AlexVelezLl 30149d8
Show the insert icon on the inline choice Insert action
AlexVelezLl b9901ee
Add the core for converting a question to another type
AlexVelezLl 60a4fb8
Implement conversion modules for descriptors
AlexVelezLl b66d1db
Focus a question's editor only when its card opens
AlexVelezLl 8cea036
Convert answers when the question type changes
AlexVelezLl f78254d
Check that every interaction exports its content for conversion
AlexVelezLl e0b8567
Give numeric answers to other types as the exercise language shows them
AlexVelezLl 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
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
71 changes: 71 additions & 0 deletions
71
...ws/QTIEditor/components/ChangeQuestionTypeModal/__tests__/ChangeQuestionTypeModal.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 |
|---|---|---|
| @@ -0,0 +1,71 @@ | ||
| import { render, screen, within } from '@testing-library/vue'; | ||
| import userEvent from '@testing-library/user-event'; | ||
| import VueRouter from 'vue-router'; | ||
| import ChangeQuestionTypeModal from '../index.vue'; | ||
| import { ConversionLoss } from '../../../constants'; | ||
| import { qtiEditorStrings as tr } from '../../../qtiEditorStrings'; | ||
|
|
||
| const renderModal = (props = {}) => | ||
| render(ChangeQuestionTypeModal, { | ||
| props: { | ||
| questionTypeLabel: 'Numeric input', | ||
| losses: [ConversionLoss.INCORRECT_ANSWERS_REMOVED, ConversionLoss.FORMATTING_REMOVED], | ||
| ...props, | ||
| }, | ||
| routes: new VueRouter(), | ||
| }); | ||
|
|
||
| describe('ChangeQuestionTypeModal', () => { | ||
| it('asks to confirm the change, naming the new type', () => { | ||
| renderModal(); | ||
| const dialog = screen.getByRole('dialog'); | ||
| expect(within(dialog).getByText(tr.$tr('changeQuestionTypeTitle'))).toBeInTheDocument(); | ||
| expect( | ||
| within(dialog).getByText(tr.$tr('changeQuestionTypeIntro', { type: 'Numeric input' })), | ||
| ).toBeInTheDocument(); | ||
| }); | ||
|
|
||
| it('lists what the change would remove or change, one sentence each', () => { | ||
| renderModal(); | ||
| const items = screen.getAllByRole('listitem').map(item => item.textContent.trim()); | ||
| expect(items).toEqual([tr.$tr('incorrectAnswersRemovedLoss'), tr.$tr('formattingRemovedLoss')]); | ||
| }); | ||
|
|
||
| it('shows each blank of a folded passage as it will appear in the question', () => { | ||
| renderModal({ losses: [ConversionLoss.PASSAGE_ADDED_TO_QUESTION] }); | ||
| expect(screen.getByRole('listitem')).toHaveTextContent(/"_____"/); | ||
| }); | ||
|
|
||
| it.each(Object.values(ConversionLoss))('has a sentence for %s', loss => { | ||
| renderModal({ losses: [loss] }); | ||
| expect(screen.getByRole('listitem').textContent.trim()).not.toBe(''); | ||
| }); | ||
|
|
||
| it('confirms with the Change button', async () => { | ||
| const user = userEvent.setup(); | ||
| const { emitted } = renderModal(); | ||
| await user.click(screen.getByRole('button', { name: tr.$tr('changeQuestionTypeAction') })); | ||
| expect(emitted().submit).toHaveLength(1); | ||
| expect(emitted().cancel).toBeUndefined(); | ||
| }); | ||
|
|
||
| it('cancels with the Cancel button', async () => { | ||
| const user = userEvent.setup(); | ||
| const { emitted } = renderModal(); | ||
| await user.click(screen.getByRole('button', { name: tr.$tr('cancelAction') })); | ||
| expect(emitted().cancel).toHaveLength(1); | ||
| expect(emitted().submit).toBeUndefined(); | ||
| }); | ||
|
|
||
| it('can be used with the keyboard only', async () => { | ||
| const user = userEvent.setup(); | ||
| const { emitted } = renderModal(); | ||
| await user.keyboard('{Escape}'); | ||
| expect(emitted().cancel).toHaveLength(1); | ||
|
|
||
| const change = screen.getByRole('button', { name: tr.$tr('changeQuestionTypeAction') }); | ||
| change.focus(); | ||
| await user.keyboard('{Enter}'); | ||
| expect(emitted().submit).toHaveLength(1); | ||
| }); | ||
| }); |
99 changes: 99 additions & 0 deletions
99
...tentcuration/frontend/shared/views/QTIEditor/components/ChangeQuestionTypeModal/index.vue
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 |
|---|---|---|
| @@ -0,0 +1,99 @@ | ||
| <template> | ||
|
|
||
| <KModal | ||
| :title="changeQuestionTypeTitle$()" | ||
| :submitText="changeQuestionTypeAction$()" | ||
| :cancelText="cancelAction$()" | ||
| @submit="$emit('submit')" | ||
| @cancel="$emit('cancel')" | ||
| > | ||
| <p>{{ changeQuestionTypeIntro$({ type: questionTypeLabel }) }}</p> | ||
| <ul class="losses"> | ||
| <li | ||
| v-for="loss in losses" | ||
| :key="loss" | ||
| > | ||
| {{ lossMessages[loss]({ blank: BLANK_TEXT }) }} | ||
| </li> | ||
| </ul> | ||
| </KModal> | ||
|
|
||
| </template> | ||
|
|
||
|
|
||
| <script> | ||
|
|
||
| import { ConversionLoss } from '../../constants'; | ||
| import { BLANK_TEXT } from '../../conversion/passage'; | ||
| import { qtiEditorStrings } from '../../qtiEditorStrings'; | ||
|
|
||
| /** | ||
| * Asks an author to confirm a change of question type that would remove or change some of | ||
| * the question, saying what. | ||
| */ | ||
| export default { | ||
| name: 'ChangeQuestionTypeModal', | ||
|
|
||
| setup() { | ||
| const { | ||
| changeQuestionTypeTitle$, | ||
| changeQuestionTypeIntro$, | ||
| changeQuestionTypeAction$, | ||
| cancelAction$, | ||
| } = qtiEditorStrings; | ||
|
|
||
| const lossMessages = { | ||
| [ConversionLoss.ANSWERS_REMOVED]: qtiEditorStrings.answersRemovedLoss$, | ||
| [ConversionLoss.INCORRECT_ANSWERS_REMOVED]: qtiEditorStrings.incorrectAnswersRemovedLoss$, | ||
| [ConversionLoss.ANY_CORRECT_ANSWER_ACCEPTED]: | ||
| qtiEditorStrings.anyCorrectAnswerAcceptedLoss$, | ||
| [ConversionLoss.CORRECT_ANSWERS_REDUCED]: qtiEditorStrings.correctAnswersReducedLoss$, | ||
| [ConversionLoss.CORRECT_ANSWERS_NOT_KEPT]: qtiEditorStrings.correctAnswersNotKeptLoss$, | ||
| [ConversionLoss.ORDER_BECOMES_ANSWER]: qtiEditorStrings.orderBecomesAnswerLoss$, | ||
| [ConversionLoss.ORDER_NOT_KEPT]: qtiEditorStrings.orderNotKeptLoss$, | ||
| [ConversionLoss.FORMATTING_REMOVED]: qtiEditorStrings.formattingRemovedLoss$, | ||
| [ConversionLoss.PASSAGE_ADDED_TO_QUESTION]: qtiEditorStrings.passageAddedToQuestionLoss$, | ||
| }; | ||
|
|
||
| return { | ||
| changeQuestionTypeTitle$, | ||
| changeQuestionTypeIntro$, | ||
| changeQuestionTypeAction$, | ||
| cancelAction$, | ||
| lossMessages, | ||
| BLANK_TEXT, | ||
| }; | ||
| }, | ||
|
|
||
| props: { | ||
| /** The label of the question type the author picked */ | ||
| questionTypeLabel: { | ||
| type: String, | ||
| required: true, | ||
| }, | ||
| /** ConversionLoss codes: what the change would remove or change */ | ||
| losses: { | ||
| type: Array, | ||
| required: true, | ||
| validator: losses => losses.every(loss => Object.values(ConversionLoss).includes(loss)), | ||
| }, | ||
| }, | ||
|
|
||
| emits: ['submit', 'cancel'], | ||
| }; | ||
|
|
||
| </script> | ||
|
|
||
|
|
||
| <style scoped> | ||
|
|
||
| .losses { | ||
| padding-inline-start: 24px; | ||
| margin: 0; | ||
| } | ||
|
|
||
| .losses li + li { | ||
| margin-top: 8px; | ||
| } | ||
|
|
||
| </style> |
Oops, something went wrong.
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.