@@ -7,6 +7,7 @@ import { inlineChoiceInteractionDescriptor as descriptor } from '../Descriptor';
77import { getDropdowns } from '../parse' ;
88import { QuestionType } from '../../../constants' ;
99import { qtiEditorStrings as tr } from '../../../qtiEditorStrings' ;
10+ import { updates } from '../../../utils/testingFixtures' ;
1011import { CHIP , chip } from './renderPassage' ;
1112import { dragSortStrings as dragTr } from 'shared/views/dragSort/dragSortStrings' ;
1213import { getTipTapEditorStrings } from 'shared/views/TipTapEditor/TipTapEditor/TipTapEditorStrings' ;
@@ -97,7 +98,7 @@ const section = name => screen.getByRole('heading', { name }).parentElement;
9798
9899/** The dropdowns of the last interaction the editor emitted, as saved and read back. */
99100function savedDropdowns ( emitted ) {
100- const [ interaction ] = emitted [ 'update:interaction' ] . at ( - 1 ) ;
101+ const [ interaction ] = updates ( emitted ) . at ( - 1 ) ;
101102 const state = descriptor . parse ( interaction . bodyXml , interaction . responseDeclarations ) ;
102103 return getDropdowns ( state . passage ) ;
103104}
@@ -216,7 +217,7 @@ describe('InlineChoiceEditor', () => {
216217
217218 expect ( input ) . toHaveValue ( 'spins' ) ;
218219 expect ( chips ( ) [ 1 ] ) . toHaveTextContent ( 'spins' ) ;
219- expect ( savedDropdowns ( emitted ( ) ) [ 1 ] . options ) . toEqual ( [
220+ expect ( savedDropdowns ( emitted ) [ 1 ] . options ) . toEqual ( [
220221 { id : 'revolves' , text : 'spins' } ,
221222 { id : 'circles' , text : 'circles' } ,
222223 ] ) ;
@@ -231,7 +232,7 @@ describe('InlineChoiceEditor', () => {
231232 await waitFor ( ( ) => expect ( optionInputs ( ) [ 2 ] ) . toHaveFocus ( ) ) ;
232233 await user . keyboard ( 'rotates' ) ;
233234 expect ( chips ( ) [ 1 ] ) . toHaveTextContent ( / ^ 3 / ) ;
234- expect ( savedDropdowns ( emitted ( ) ) [ 1 ] . options . map ( o => o . text ) ) . toEqual ( [
235+ expect ( savedDropdowns ( emitted ) [ 1 ] . options . map ( o => o . text ) ) . toEqual ( [
235236 'revolves' ,
236237 'circles' ,
237238 'rotates' ,
@@ -248,7 +249,7 @@ describe('InlineChoiceEditor', () => {
248249 expect ( optionInputs ( ) . map ( input => input . value ) ) . toEqual ( [ 'Sun' , 'Stars' ] ) ;
249250 // The chip needs a correct answer, so its count is in its name, beside the error icon.
250251 expect ( chips ( ) [ 0 ] ) . toHaveAccessibleName ( / 2 o p t i o n s / ) ;
251- expect ( savedDropdowns ( emitted ( ) ) [ 0 ] . options . map ( o => o . text ) ) . toEqual ( [ 'Sun' , 'Stars' ] ) ;
252+ expect ( savedDropdowns ( emitted ) [ 0 ] . options . map ( o => o . text ) ) . toEqual ( [ 'Sun' , 'Stars' ] ) ;
252253 } ) ;
253254
254255 it ( 'keeps focus in the panel on the option that takes a removed one’s place' , async ( ) => {
@@ -295,7 +296,7 @@ describe('InlineChoiceEditor', () => {
295296 expect ( radio ( 2 ) ) . not . toBeChecked ( ) ;
296297 expect ( radio ( 3 ) ) . toBeChecked ( ) ;
297298 expect ( chips ( ) [ 0 ] ) . toHaveTextContent ( 'Stars' ) ;
298- expect ( savedDropdowns ( emitted ( ) ) [ 0 ] . correctId ) . toBe ( 'stars' ) ;
299+ expect ( savedDropdowns ( emitted ) [ 0 ] . correctId ) . toBe ( 'stars' ) ;
299300 } ) ;
300301
301302 it ( 'keeps the correct mark on the same option when it moves' , async ( ) => {
@@ -313,7 +314,7 @@ describe('InlineChoiceEditor', () => {
313314 expect (
314315 screen . getByRole ( 'radio' , { name : tr . markInlineChoiceOptionCorrect$ ( { number : 2 } ) } ) ,
315316 ) . toBeChecked ( ) ;
316- const [ , dropdown ] = savedDropdowns ( emitted ( ) ) ;
317+ const [ , dropdown ] = savedDropdowns ( emitted ) ;
317318 expect ( dropdown . options . map ( o => o . text ) ) . toEqual ( [ 'circles' , 'revolves' , 'rotates' ] ) ;
318319 expect ( dropdown . correctId ) . toBe ( 'revolves' ) ;
319320 } ) ;
@@ -327,7 +328,7 @@ describe('InlineChoiceEditor', () => {
327328 ) ;
328329
329330 expect ( chips ( ) [ 1 ] ) . toHaveTextContent ( tr . errorNoCorrectAnswer$ ( ) ) ;
330- expect ( savedDropdowns ( emitted ( ) ) [ 1 ] . correctId ) . toBeNull ( ) ;
331+ expect ( savedDropdowns ( emitted ) [ 1 ] . correctId ) . toBeNull ( ) ;
331332 } ) ;
332333
333334 it ( 'restores the list when the edit is undone in the passage' , async ( ) => {
@@ -519,7 +520,7 @@ describe('InlineChoiceEditor', () => {
519520 const { emitted, user } = await renderEditor ( ) ;
520521 await user . click ( shuffle ( ) ) ;
521522
522- const [ interaction ] = emitted ( ) [ 'update:interaction' ] . at ( - 1 ) ;
523+ const [ interaction ] = updates ( emitted ) . at ( - 1 ) ;
523524 expect ( [ ...interaction . bodyXml . matchAll ( / s h u f f l e = " ( \w + ) " / g) ] . map ( m => m [ 1 ] ) ) . toEqual ( [
524525 'true' ,
525526 'true' ,
@@ -690,7 +691,7 @@ describe('InlineChoiceEditor', () => {
690691 await screen . findByRole ( 'dialog' ) ;
691692 await waitFor ( ( ) => expect ( optionInputs ( ) [ 0 ] ) . toHaveFocus ( ) ) ;
692693 await user . keyboard ( 'Venus' ) ;
693- const saved = savedDropdowns ( emitted ( ) ) ;
694+ const saved = savedDropdowns ( emitted ) ;
694695 expect ( saved ) . toHaveLength ( 3 ) ;
695696 expect ( saved . map ( d => d . options . map ( o => o . text ) ) ) . toContainEqual ( [ 'Venus' ] ) ;
696697 } ) ;
@@ -717,16 +718,36 @@ describe('InlineChoiceEditor', () => {
717718 await openChip ( user , 1 ) ;
718719 await user . type ( optionInputs ( ) [ 0 ] , 's' ) ;
719720
720- const [ interaction ] = emitted ( ) [ 'update:interaction' ] . at ( - 1 ) ;
721+ const [ interaction ] = updates ( emitted ) . at ( - 1 ) ;
721722 expect ( interaction . bodyXml ) . toContain ( `src="${ image } "` ) ;
722723 expect ( interaction . bodyXml ) . not . toContain ( '/content/storage/' ) ;
723724 } ) ;
724725
725- it ( 'does not save which chip is open' , async ( ) => {
726- const { emitted, user } = await renderEditor ( ) ;
727- const before = emitted ( ) [ 'update:interaction' ] . at ( - 1 ) [ 0 ] . bodyXml ;
728- await openChip ( user , 0 ) ;
729- expect ( emitted ( ) [ 'update:interaction' ] . at ( - 1 ) [ 0 ] . bodyXml ) . toBe ( before ) ;
726+ describe ( 'emits' , ( ) => {
727+ it ( 'emits update:interaction for an edit made as the card closes' , async ( ) => {
728+ const { emitted, updateProps } = await renderEditor ( ) ;
729+ fireEvent . click ( screen . getByRole ( 'checkbox' , { name : tr . shuffleAnswersLabel$ ( ) } ) ) ;
730+ await updateProps ( { mode : 'view' } ) ;
731+ expect ( updates ( emitted ) ) . toHaveLength ( 1 ) ;
732+ } ) ;
733+
734+ it ( 'does not emit update:interaction on mount in edit mode' , async ( ) => {
735+ const { emitted } = await renderEditor ( ) ;
736+ expect ( updates ( emitted ) ) . toHaveLength ( 0 ) ;
737+ } ) ;
738+
739+ it ( 'does not emit update:interaction when the mode changes' , async ( ) => {
740+ const { emitted, updateProps } = await renderEditor ( { mode : 'view' } ) ;
741+ await updateProps ( { mode : 'edit' } ) ;
742+ await updateProps ( { mode : 'view' } ) ;
743+ expect ( updates ( emitted ) ) . toHaveLength ( 0 ) ;
744+ } ) ;
745+
746+ it ( 'does not emit update:interaction on opening a chip' , async ( ) => {
747+ const { emitted, user } = await renderEditor ( ) ;
748+ await openChip ( user , 0 ) ;
749+ expect ( updates ( emitted ) ) . toHaveLength ( 0 ) ;
750+ } ) ;
730751 } ) ;
731752
732753 it ( 'restores every chip’s options and correct answer when reopened' , async ( ) => {
@@ -735,7 +756,7 @@ describe('InlineChoiceEditor', () => {
735756 await user . click (
736757 screen . getByRole ( 'radio' , { name : tr . markInlineChoiceOptionCorrect$ ( { number : 3 } ) } ) ,
737758 ) ;
738- const [ saved ] = emitted ( ) [ 'update:interaction' ] . at ( - 1 ) ;
759+ const [ saved ] = updates ( emitted ) . at ( - 1 ) ;
739760 unmount ( ) ;
740761
741762 await renderEditor ( { interaction : saved } ) ;
0 commit comments