Repository navigation
Add the inline choice interaction editor #6303
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
AlexVelezLl
wants to merge
7
commits into
learningequality:unstable
Choose a base branch
from
AlexVelezLl:issue-6182-inline-choice-editor
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.
+2,465
−176
Open
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
ffe92cf
Write no warning when not every response can be scored
AlexVelezLl 382a419
Fit the prominent insert action in with the toolbar's other tools
AlexVelezLl a97bd8a
Document that an expanded popup keeps the rich text editor open
AlexVelezLl ae7d7ab
Move the caret past inline choice chips instead of selecting them
AlexVelezLl 01831f7
Read a rich text editor's stored HTML through one helper
AlexVelezLl 04db0d7
Add the inline choice interaction editor
AlexVelezLl 4ec7055
Make inline choice chips easier to use with a keyboard or screen reader
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
67 changes: 67 additions & 0 deletions
67
.../frontend/shared/views/QTIEditor/composables/__tests__/useInlineChoiceInteraction.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,67 @@ | ||
| import { nextTick, ref } from 'vue'; | ||
| import { useInlineChoiceInteraction } from '../useInlineChoiceInteraction'; | ||
| import { inlineChoiceInteractionDescriptor } from '../../interactions/inlineChoice/Descriptor'; | ||
| import { QuestionType, ValidationError } from '../../constants'; | ||
| import { chip } from '../../interactions/inlineChoice/__tests__/renderPassage'; | ||
|
|
||
| const PASSAGE = `<p>The ${chip('r1', [ | ||
| ['a', 'Moon'], | ||
| ['b', 'Sun'], | ||
| ])} rises</p>`; | ||
|
|
||
| function setup(state = { prompt: '', passage: PASSAGE, shuffle: false }) { | ||
| const questionType = ref(QuestionType.INLINE_CHOICE); | ||
| const block = inlineChoiceInteractionDescriptor.buildXML(state, QuestionType.INLINE_CHOICE); | ||
| return useInlineChoiceInteraction(block, questionType); | ||
| } | ||
|
|
||
| describe('useInlineChoiceInteraction', () => { | ||
| it('reads the dropdowns out of the passage', () => { | ||
| const { dropdowns } = setup(); | ||
| expect(dropdowns.value).toEqual([ | ||
| { | ||
| responseIdentifier: 'r1', | ||
| options: [ | ||
| { id: 'a', text: 'Moon' }, | ||
| { id: 'b', text: 'Sun' }, | ||
| ], | ||
| correctId: null, | ||
| }, | ||
| ]); | ||
| }); | ||
|
|
||
| it('sets the question', () => { | ||
| const { state, setPrompt } = setup(); | ||
| setPrompt('<p>Fill in the blanks</p>'); | ||
| expect(state.value.prompt).toBe('<p>Fill in the blanks</p>'); | ||
| }); | ||
|
|
||
| it('sets the passage, and the dropdowns follow it', () => { | ||
| const { dropdowns, setPassage } = setup(); | ||
| setPassage(`<p>${chip('r2', [['c', 'Earth']], 'c')}</p>`); | ||
| expect(dropdowns.value.map(d => d.responseIdentifier)).toEqual(['r2']); | ||
| }); | ||
|
|
||
| it('writes Shuffle onto every dropdown in the saved XML', () => { | ||
| const { bodyXml, setShuffle } = setup({ | ||
| prompt: '', | ||
| passage: `<p>${chip('r1', [['a', 'x']], 'a')} ${chip('r2', [['b', 'y']], 'b')}</p>`, | ||
| shuffle: false, | ||
| }); | ||
| setShuffle(true); | ||
| const shuffles = [...bodyXml.value.matchAll(/shuffle="(\w+)"/g)].map(m => m[1]); | ||
| expect(shuffles).toEqual(['true', 'true']); | ||
| }); | ||
|
|
||
| it('reads Shuffle back from a saved item', () => { | ||
| const { state } = setup({ prompt: '', passage: PASSAGE, shuffle: true }); | ||
| expect(state.value.shuffle).toBe(true); | ||
| }); | ||
|
|
||
| it('reports a passage with no dropdown', async () => { | ||
| const { errors, setPassage } = setup(); | ||
| setPassage('<p>No dropdowns here</p>'); | ||
| await nextTick(); | ||
| expect(errors.value).toEqual([{ code: ValidationError.NO_INTERACTION }]); | ||
| }); | ||
| }); |
43 changes: 43 additions & 0 deletions
43
...contentcuration/frontend/shared/views/QTIEditor/composables/useInlineChoiceInteraction.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,43 @@ | ||
| import { computed, readonly } from 'vue'; | ||
| import { inlineChoiceInteractionDescriptor } from '../interactions/inlineChoice/Descriptor'; | ||
| import { getDropdowns } from '../interactions/inlineChoice/parse'; | ||
| import { useInteraction } from './useInteraction'; | ||
|
|
||
| /** | ||
| * Composable for the inline choice interaction editor. | ||
| * | ||
| * Extends useInteraction with the question-level mutations. A dropdown's options are not | ||
| * edited here: they live in the passage, and are changed through the passage editor's node | ||
| * commands so that each edit is one step of its history. | ||
| * | ||
| * @param {{ bodyXml: string, responseDeclarations: string[] }} interactionBlock | ||
| * @param {import('vue').Ref<string|null>} questionType | ||
| */ | ||
| export function useInlineChoiceInteraction(interactionBlock, questionType) { | ||
| const base = useInteraction(inlineChoiceInteractionDescriptor, interactionBlock, questionType); | ||
| const { state } = base; | ||
|
|
||
| /** Every dropdown in the passage, in document order. */ | ||
| const dropdowns = computed(() => getDropdowns(state.value.passage)); | ||
|
|
||
| function setPrompt(html) { | ||
| state.value = { ...state.value, prompt: html }; | ||
| } | ||
|
|
||
| function setPassage(html) { | ||
| state.value = { ...state.value, passage: html }; | ||
| } | ||
|
|
||
| function setShuffle(val) { | ||
| state.value = { ...state.value, shuffle: val }; | ||
| } | ||
|
|
||
| return { | ||
| ...base, | ||
| state: readonly(state), | ||
| dropdowns, | ||
| setPrompt, | ||
| setPassage, | ||
| setShuffle, | ||
| }; | ||
| } |
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
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.