-
-
Notifications
You must be signed in to change notification settings - Fork 304
implement choice interaction parsing and serialization for QTIEditor #6012
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
Abhishek-Punhani
wants to merge
14
commits into
learningequality:unstable
Choose a base branch
from
Abhishek-Punhani:Issue5965
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.
Open
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
839b0fd
feat(qti): add base utilities, constants, and ValidationMessage
Abhishek-Punhani 11e937f
feat(qti): implement base useInteraction and XML serialization
Abhishek-Punhani a619cb8
feat(qti): implement ChoiceInteractionDescriptor and useChoiceInterac…
Abhishek-Punhani e4f17ed
feat(qti): implement ChoiceInteractionEditor UI and Editor updates
Abhishek-Punhani faa6686
refactor: migrate ChoiceInteractionEditor to Composition API and impl…
Abhishek-Punhani 91347d5
refactor: optimize QTI item assembly with XML attribute escaping, int…
Abhishek-Punhani b879ab9
refactor: rename answers property to choices in QTI choice interactio…
Abhishek-Punhani fcdf400
refactor: unify bodyXml and responseDeclarations into a single update…
Abhishek-Punhani 83abe32
refactor: migrate XML assembly to a robust DOM-based implementation a…
Abhishek-Punhani fa11bef
refactor: update ChoiceInteractionEditor UI labels acc to new figma …
Abhishek-Punhani 429d02f
refactor: update the validation error styling acc to new figma spec
Abhishek-Punhani 120deb3
removeing unused class and fix test
Abhishek-Punhani e5f6c58
refactor: rename declarations to responseDeclarations and add innerHT…
Abhishek-Punhani 6896864
refactor: move background color styling from ChoiceInteractionEditor …
Abhishek-Punhani 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
33 changes: 33 additions & 0 deletions
33
...on/contentcuration/frontend/shared/views/QTIEditor/components/ValidationMessage/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,33 @@ | ||
| <template> | ||
|
|
||
| <div> | ||
| <p | ||
| class="validation-message" | ||
| role="alert" | ||
| :style="{ color: $themeTokens.error }" | ||
| > | ||
| <slot></slot> | ||
| </p> | ||
| </div> | ||
|
|
||
| </template> | ||
|
|
||
|
|
||
| <script> | ||
|
|
||
| export default { | ||
| name: 'ValidationMessage', | ||
| }; | ||
|
|
||
| </script> | ||
|
|
||
|
|
||
| <style scoped> | ||
|
|
||
| .validation-message { | ||
| margin: 2px 0 0; | ||
| font-size: 14px; | ||
| line-height: 1.4; | ||
| } | ||
|
|
||
| </style> |
181 changes: 181 additions & 0 deletions
181
...ration/frontend/shared/views/QTIEditor/composables/__tests__/useChoiceInteraction.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,181 @@ | ||
| import { ref } from 'vue'; | ||
| import { useChoiceInteraction } from '../useChoiceInteraction'; | ||
| import { QuestionType } from '../../constants'; | ||
|
|
||
| // --------------------------------------------------------------------------- | ||
| // Helpers | ||
| // --------------------------------------------------------------------------- | ||
|
|
||
| function makeAnswer(overrides = {}) { | ||
| return { id: 'choice_a', content: 'A', correct: false, fixed: false, ...overrides }; | ||
| } | ||
|
|
||
| function makeBlock(choices, questionType = QuestionType.SINGLE_SELECT) { | ||
| const maxChoices = questionType === QuestionType.SINGLE_SELECT ? 1 : 2; | ||
| const correctIds = choices.filter(a => a.correct).map(a => a.id); | ||
|
|
||
| const bodyXml = `<qti-choice-interaction response-identifier="RESPONSE" max-choices="${maxChoices}"> | ||
| ${choices.map(a => `<qti-simple-choice identifier="${a.id}">${a.content}</qti-simple-choice>`).join('\n ')} | ||
| </qti-choice-interaction>`; | ||
|
|
||
| const declaration = `<qti-response-declaration identifier="RESPONSE" | ||
| cardinality="${questionType === QuestionType.SINGLE_SELECT ? 'single' : 'multiple'}" | ||
| base-type="identifier"> | ||
| <qti-correct-response> | ||
| ${correctIds.map(id => `<qti-value>${id}</qti-value>`).join('')} | ||
| </qti-correct-response> | ||
| </qti-response-declaration>`; | ||
|
|
||
| return { bodyXml, responseDeclarations: [declaration] }; | ||
| } | ||
|
|
||
| function setup(choices, questionType = QuestionType.SINGLE_SELECT) { | ||
| const qt = ref(questionType); | ||
| const block = makeBlock(choices, questionType); | ||
| return { qt, ...useChoiceInteraction(block, qt) }; | ||
| } | ||
|
|
||
| // --------------------------------------------------------------------------- | ||
| // Tests | ||
| // --------------------------------------------------------------------------- | ||
|
|
||
| describe('useChoiceInteraction', () => { | ||
| describe('addChoice()', () => { | ||
| it('appends a new choice to the list', () => { | ||
| const { state, addChoice } = setup([ | ||
| makeAnswer({ id: 'a', content: 'A' }), | ||
| makeAnswer({ id: 'b', content: 'B' }), | ||
| ]); | ||
| addChoice(); | ||
| expect(state.value.choices).toHaveLength(3); | ||
| }); | ||
|
|
||
| it('new choice has a generated "choice_" identifier', () => { | ||
| const { state, addChoice } = setup([makeAnswer({ id: 'a' }), makeAnswer({ id: 'b' })]); | ||
| addChoice(); | ||
| const newAnswer = state.value.choices[2]; | ||
| expect(newAnswer.id).toMatch(/^choice_[a-z0-9]{8}$/); | ||
| }); | ||
|
|
||
| it('new choice has empty content and correct: false', () => { | ||
| const { state, addChoice } = setup([makeAnswer({ id: 'a' }), makeAnswer({ id: 'b' })]); | ||
| addChoice(); | ||
| const newAnswer = state.value.choices[2]; | ||
| expect(newAnswer.content).toBe(''); | ||
| expect(newAnswer.correct).toBe(false); | ||
| }); | ||
| }); | ||
|
|
||
| describe('removeChoice()', () => { | ||
| it('removes the choice with the given id', () => { | ||
| const { state, removeChoice } = setup([makeAnswer({ id: 'a' }), makeAnswer({ id: 'b' })]); | ||
| removeChoice('a'); | ||
| expect(state.value.choices.find(a => a.id === 'a')).toBeUndefined(); | ||
| }); | ||
|
|
||
| it('is a no-op when only one choice remains', () => { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. So, for when we add a new question (i.e. assessment item) to the list, there should be at least one choice, too right? |
||
| const { state, removeChoice } = setup([makeAnswer({ id: 'a' })]); | ||
| removeChoice('a'); | ||
| expect(state.value.choices).toHaveLength(1); | ||
| }); | ||
| }); | ||
|
|
||
| describe('moveChoiceUp()', () => { | ||
| it('swaps choice with the previous one', () => { | ||
| const { state, moveChoiceUp } = setup([ | ||
| makeAnswer({ id: 'a' }), | ||
| makeAnswer({ id: 'b' }), | ||
| makeAnswer({ id: 'c' }), | ||
| ]); | ||
| moveChoiceUp('b'); | ||
| expect(state.value.choices.map(a => a.id)).toEqual(['b', 'a', 'c']); | ||
| }); | ||
|
|
||
| it('is a no-op when the choice is first', () => { | ||
| const { state, moveChoiceUp } = setup([makeAnswer({ id: 'a' }), makeAnswer({ id: 'b' })]); | ||
| moveChoiceUp('a'); | ||
| expect(state.value.choices.map(a => a.id)).toEqual(['a', 'b']); | ||
| }); | ||
| }); | ||
|
|
||
| describe('moveChoiceDown()', () => { | ||
| it('swaps choice with the next one', () => { | ||
| const { state, moveChoiceDown } = setup([ | ||
| makeAnswer({ id: 'a' }), | ||
| makeAnswer({ id: 'b' }), | ||
| makeAnswer({ id: 'c' }), | ||
| ]); | ||
| moveChoiceDown('b'); | ||
| expect(state.value.choices.map(a => a.id)).toEqual(['a', 'c', 'b']); | ||
| }); | ||
|
|
||
| it('is a no-op when the choice is last', () => { | ||
| const { state, moveChoiceDown } = setup([makeAnswer({ id: 'a' }), makeAnswer({ id: 'b' })]); | ||
| moveChoiceDown('b'); | ||
| expect(state.value.choices.map(a => a.id)).toEqual(['a', 'b']); | ||
| }); | ||
| }); | ||
|
|
||
| describe('toggleCorrectChoice()', () => { | ||
| it('singleSelect: sets only the target as correct and clears others', () => { | ||
| const { state, toggleCorrectChoice, qt } = setup([ | ||
| makeAnswer({ id: 'a', correct: true }), | ||
| makeAnswer({ id: 'b', correct: false }), | ||
| ]); | ||
| qt.value = QuestionType.SINGLE_SELECT; | ||
| toggleCorrectChoice('b'); | ||
| expect(state.value.choices.find(a => a.id === 'b').correct).toBe(true); | ||
| expect(state.value.choices.find(a => a.id === 'a').correct).toBe(false); | ||
| }); | ||
|
|
||
| it('multiSelect: toggles only the target, leaves others unchanged', () => { | ||
| const { state, toggleCorrectChoice, qt } = setup( | ||
| [makeAnswer({ id: 'a', correct: true }), makeAnswer({ id: 'b', correct: false })], | ||
| QuestionType.MULTI_SELECT, | ||
| ); | ||
| qt.value = QuestionType.MULTI_SELECT; | ||
| toggleCorrectChoice('b'); | ||
| expect(state.value.choices.find(a => a.id === 'b').correct).toBe(true); | ||
| expect(state.value.choices.find(a => a.id === 'a').correct).toBe(true); | ||
| }); | ||
|
|
||
| it('multiSelect: toggles correct off when already correct', () => { | ||
| const { state, toggleCorrectChoice, qt } = setup( | ||
| [makeAnswer({ id: 'a', correct: true }), makeAnswer({ id: 'b', correct: true })], | ||
| QuestionType.MULTI_SELECT, | ||
| ); | ||
| qt.value = QuestionType.MULTI_SELECT; | ||
| toggleCorrectChoice('a'); | ||
| expect(state.value.choices.find(a => a.id === 'a').correct).toBe(false); | ||
| expect(state.value.choices.find(a => a.id === 'b').correct).toBe(true); | ||
| }); | ||
| }); | ||
|
|
||
| describe('setPrompt()', () => { | ||
| it('updates the prompt field', () => { | ||
| const { state, setPrompt } = setup([makeAnswer({ id: 'a' }), makeAnswer({ id: 'b' })]); | ||
| setPrompt('<p>New prompt</p>'); | ||
| expect(state.value.prompt).toBe('<p>New prompt</p>'); | ||
| }); | ||
| }); | ||
|
|
||
| describe('setChoiceContent()', () => { | ||
| it('updates content for the target choice only', () => { | ||
| const { state, setChoiceContent } = setup([ | ||
| makeAnswer({ id: 'a', content: 'Old' }), | ||
| makeAnswer({ id: 'b', content: 'Unchanged' }), | ||
| ]); | ||
| setChoiceContent('a', 'New content'); | ||
| expect(state.value.choices.find(a => a.id === 'a').content).toBe('New content'); | ||
| expect(state.value.choices.find(a => a.id === 'b').content).toBe('Unchanged'); | ||
| }); | ||
| }); | ||
|
|
||
| describe('setShuffle()', () => { | ||
| it('updates the shuffle flag', () => { | ||
| const { state, setShuffle } = setup([makeAnswer({ id: 'a' }), makeAnswer({ id: 'b' })]); | ||
| setShuffle(true); | ||
| expect(state.value.shuffle).toBe(true); | ||
| }); | ||
| }); | ||
| }); | ||
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could we add a comment here that we are currently using only the first interaction, but can be expansible to multiple interactions per question in the future?