File tree Expand file tree Collapse file tree
packages/multiple-choice/src Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11import React from 'react' ;
2- import _ from 'lodash' ;
32import { shallow , mount } from 'enzyme' ;
43import { ChoiceInput } from '../choice-input' ;
54import toJson from 'enzyme-to-json' ;
65
76describe ( 'ChoiceInput' , ( ) => {
87 let onChange , wrapper ;
98
10- const mkWrapper = ( opts = { } ) => {
11- opts = _ . extend (
12- {
13- checked : false ,
14- disabled : false ,
15- choiceMode : 'checkbox' ,
16- label : 'label' ,
17- displayKey : '1' ,
18- correctness : 'correct' ,
19- value : 'value' ,
20- classes : {
21- label : 'label' ,
22- } ,
23- } ,
24- opts ,
25- ) ;
26-
27- return shallow ( < ChoiceInput { ...opts } onChange = { onChange } /> ) ;
9+ const mkWrapper = ( opts = { } ) => {
10+ const defaultOpts = {
11+ checked : false ,
12+ disabled : false ,
13+ choiceMode : 'checkbox' ,
14+ label : 'label' ,
15+ displayKey : '1' ,
16+ correctness : 'correct' ,
17+ value : 'value' ,
18+ classes : {
19+ label : 'label' ,
20+ } ,
2821 } ;
2922
23+ const finalOpts = { ...defaultOpts , ...opts } ;
24+
25+ return shallow ( < ChoiceInput { ...finalOpts } onChange = { onChange } /> ) ;
26+ } ;
27+
3028 beforeEach ( ( ) => {
3129 onChange = jest . fn ( ) ;
3230 wrapper = mkWrapper ( ) ;
Original file line number Diff line number Diff line change 11import React from 'react' ;
2- import _ from 'lodash' ;
32import { shallow } from 'enzyme' ;
43import { MultipleChoice , Choice } from '../multiple-choice' ;
5- import { CorrectAnswerToggle } from '@pie-lib/pie-toolbox/correct-answer-toggle' ;
4+ import { CorrectAnswerToggle } from '@pie-lib/pie-toolbox/correct-answer-toggle' ;
65
76describe ( 'Choice' , ( ) => {
87 let wrapper ,
@@ -67,17 +66,15 @@ describe('CorespringChoice', () => {
6766
6867 let mkWrapper = ( opts , clone = true ) => {
6968 opts = clone
70- ? ( opts = _ . merge (
71- {
72- classes : { } ,
73- choices : [ ] ,
74- disabled : false ,
75- keyMode : 'letters' ,
76- onChoiceChanged : jest . fn ( ) ,
77- mode : 'gather' ,
78- } ,
79- opts ,
80- ) )
69+ ? {
70+ classes : { } ,
71+ choices : [ ] ,
72+ disabled : false ,
73+ keyMode : 'letters' ,
74+ onChoiceChanged : jest . fn ( ) ,
75+ mode : 'gather' ,
76+ ...opts
77+ }
8178 : opts ;
8279
8380 return shallow ( < MultipleChoice { ...opts } /> ) ;
Original file line number Diff line number Diff line change 1- import concat from 'lodash/concat' ;
2- import uniq from 'lodash/uniq' ;
3- import without from 'lodash/without' ;
4-
51export function updateSessionValue ( session , choiceMode , data ) {
62 session . value = session . value || [ ] ;
73 if ( choiceMode === 'checkbox' ) {
84 if ( data . selected ) {
9- session . value = uniq ( concat ( session . value , [ data . value ] ) ) ;
5+ session . value = Array . from ( new Set ( [ ... session . value , data . value ] ) ) ;
106 } else {
11- session . value = without ( session . value , data . value ) ;
7+ session . value = session . value . filter ( v => v !== data . value ) ;
128 }
139 }
1410
You can’t perform that action at this time.
0 commit comments