@pie-element/ebsr 8.2.5 → 8.2.6-next.56

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -8,38 +8,35 @@ import { Main } from '../main';
8
8
  import EbsrConfigure from '../index';
9
9
 
10
10
  jest.mock('react-dom', () => ({
11
- render: jest.fn()
11
+ render: jest.fn(),
12
12
  }));
13
13
 
14
14
  jest.mock('@pie-framework/pie-configure-events', () => ({
15
- ModelUpdatedEvent: update => {
15
+ ModelUpdatedEvent: (update) => {
16
16
  return {
17
17
  update,
18
18
  preventDefault: jest.fn(),
19
- stopImmediatePropagation: jest.fn()
19
+ stopImmediatePropagation: jest.fn(),
20
20
  };
21
- }
21
+ },
22
22
  }));
23
23
 
24
24
  jest.mock('@pie-lib/config-ui', () => ({
25
25
  choiceUtils: {
26
- firstAvailableIndex: jest.fn()
26
+ firstAvailableIndex: jest.fn(),
27
27
  },
28
28
  settings: {
29
- Panel: props => <div {...props} />,
29
+ Panel: (props) => <div {...props} />,
30
30
  toggle: jest.fn(),
31
31
  radio: jest.fn(),
32
- dropdown: jest.fn()
32
+ dropdown: jest.fn(),
33
33
  },
34
34
  layout: {
35
- ConfigLayout: props => <div>{props.children}</div>
36
- }
35
+ ConfigLayout: (props) => <div>{props.children}</div>,
36
+ },
37
37
  }));
38
38
 
39
- jest.mock(
40
- '@pie-element/multiple-choice/configure/lib',
41
- () => class MockConfigure {}
42
- );
39
+ jest.mock('@pie-element/multiple-choice/configure/lib', () => class MockConfigure {});
43
40
 
44
41
  const PART_A = 'partA';
45
42
  const PART_B = 'partB';
@@ -49,12 +46,12 @@ const createDefaultModel = (model, newModel = {}) => ({
49
46
  ...newModel,
50
47
  partA: {
51
48
  ...model.partA,
52
- ...newModel.partA
49
+ ...newModel.partA,
53
50
  },
54
51
  partB: {
55
52
  ...model.partB,
56
- ...newModel.partB
57
- }
53
+ ...newModel.partB,
54
+ },
58
55
  });
59
56
 
60
57
  const model = createDefaultModel(defaults.model, {
@@ -67,20 +64,20 @@ const model = createDefaultModel(defaults.model, {
67
64
  correct: true,
68
65
  feedback: {
69
66
  type: 'custom',
70
- value: 'foo'
71
- }
67
+ value: 'foo',
68
+ },
72
69
  },
73
70
  {
74
71
  value: 'green',
75
72
  label: 'Green',
76
73
  feedback: {
77
- type: 'default'
78
- }
79
- }
74
+ type: 'default',
75
+ },
76
+ },
80
77
  ],
81
78
  choicePrefix: 'numbers',
82
79
  prompt: `prompt ${PART_A}`,
83
- errors: {}
80
+ errors: {},
84
81
  },
85
82
  partB: {
86
83
  choiceMode: 'radio',
@@ -91,21 +88,21 @@ const model = createDefaultModel(defaults.model, {
91
88
  correct: true,
92
89
  feedback: {
93
90
  type: 'custom',
94
- value: 'foo'
95
- }
91
+ value: 'foo',
92
+ },
96
93
  },
97
94
  {
98
95
  value: 'purple',
99
96
  label: 'Purple',
100
97
  feedback: {
101
- type: 'default'
102
- }
103
- }
98
+ type: 'default',
99
+ },
100
+ },
104
101
  ],
105
102
  choicePrefix: 'numbers',
106
103
  prompt: `prompt ${PART_B}`,
107
- errors: {}
108
- }
104
+ errors: {},
105
+ },
109
106
  });
110
107
 
111
108
  describe('index', () => {
@@ -135,28 +132,28 @@ describe('index', () => {
135
132
  configuration={defaults.configuration}
136
133
  onConfigurationChanged={el.onConfigurationChanged}
137
134
  onModelChanged={el.onModelChanged}
138
- />
135
+ />,
139
136
  );
140
137
 
141
138
  // mock onModelChanged to dispatch a MODEL_UPDATED event (as multiple-choice does)
142
- main.instance().partA.onModelChanged = m => {
139
+ main.instance().partA.onModelChanged = (m) => {
143
140
  const event = new ModelUpdatedEvent(m, false);
144
141
 
145
142
  el.dispatchEvent({
146
143
  ...event,
147
144
  target: {
148
- getAttribute: jest.fn().mockReturnValue('A')
149
- }
145
+ getAttribute: jest.fn().mockReturnValue('A'),
146
+ },
150
147
  });
151
148
  };
152
- main.instance().partB.onModelChanged = m => {
149
+ main.instance().partB.onModelChanged = (m) => {
153
150
  const event = new ModelUpdatedEvent(m, false);
154
151
 
155
152
  el.dispatchEvent({
156
153
  ...event,
157
154
  target: {
158
- getAttribute: jest.fn().mockReturnValue('B')
159
- }
155
+ getAttribute: jest.fn().mockReturnValue('B'),
156
+ },
160
157
  });
161
158
  };
162
159
  });
@@ -168,7 +165,7 @@ describe('index', () => {
168
165
  });
169
166
  it('with-overrides-snapshot', () => {
170
167
  const m = EbsrConfigure.createDefaultModel({
171
- partA: { rationale: 'foo', teacherInstructions: 'ti' }
168
+ partA: { rationale: 'foo', teacherInstructions: 'ti' },
172
169
  });
173
170
  expect(m).toMatchSnapshot();
174
171
  });
@@ -199,12 +196,12 @@ describe('index', () => {
199
196
  expect(main.instance().partA.configuration).toEqual({
200
197
  ...defaults.configuration.partA,
201
198
  partLabels: defaults.configuration.partLabels,
202
- settingsPanelDisabled: true
199
+ settingsPanelDisabled: true,
203
200
  });
204
201
  expect(main.instance().partB.configuration).toEqual({
205
202
  ...defaults.configuration.partB,
206
203
  partLabels: defaults.configuration.partLabels,
207
- settingsPanelDisabled: true
204
+ settingsPanelDisabled: true,
208
205
  });
209
206
  });
210
207
  });
@@ -216,8 +213,8 @@ describe('index', () => {
216
213
  el.dispatchEvent({
217
214
  ...event,
218
215
  target: {
219
- getAttribute: jest.fn().mockReturnValue(key)
220
- }
216
+ getAttribute: jest.fn().mockReturnValue(key),
217
+ },
221
218
  });
222
219
 
223
220
  expect(ReactDOM.render).toBeCalled();
@@ -226,30 +223,20 @@ describe('index', () => {
226
223
  };
227
224
 
228
225
  describe('onModelUpdated', () => {
229
- assetOnModelUpdated(
230
- 'dispatching MODEL_UPDATED updates model.partA',
231
- 'A',
232
- { updatedA: true },
233
- { updatedA: true }
234
- );
235
- assetOnModelUpdated(
236
- 'dispatching MODEL_UPDATED updates model.partB',
237
- 'B',
238
- { updatedB: true },
239
- { updatedB: true }
240
- );
226
+ assetOnModelUpdated('dispatching MODEL_UPDATED updates model.partA', 'A', { updatedA: true }, { updatedA: true });
227
+ assetOnModelUpdated('dispatching MODEL_UPDATED updates model.partB', 'B', { updatedB: true }, { updatedB: true });
241
228
 
242
229
  assetOnModelUpdated(
243
230
  'dispatching MODEL_UPDATED with update undefined does not update model.partA',
244
231
  'A',
245
232
  undefined,
246
- createDefaultModel(model).partA
233
+ createDefaultModel(model).partA,
247
234
  );
248
235
  assetOnModelUpdated(
249
236
  'dispatching MODEL_UPDATED with update undefined does not update model.partB',
250
237
  'B',
251
238
  undefined,
252
- createDefaultModel(model).partB
239
+ createDefaultModel(model).partB,
253
240
  );
254
241
  });
255
242
 
@@ -263,126 +250,90 @@ describe('index', () => {
263
250
  };
264
251
 
265
252
  describe('part update', () => {
266
- assetPartUpdate(
267
- 'Dispatching Model Updated Event will update Teacher Instructions',
268
- 'partA',
269
- { ...model.partA, teacherInstructions: 'Part A Teacher Instructions' }
270
- );
271
- assetPartUpdate(
272
- 'Dispatching Model Updated Event will update Teacher Instructions',
273
- 'partB',
274
- { ...model.partB, teacherInstructions: 'Part B Teacher Instructions' }
275
- );
276
- assetPartUpdate(
277
- 'Dispatching Model Updated Event will update Prompt',
278
- 'partA',
279
- { ...model.partA, prompt: 'Prompt A' }
280
- );
281
- assetPartUpdate(
282
- 'Dispatching Model Updated Event will update Prompt',
283
- 'partB',
284
- { ...model.partA, prompt: 'Prompt B' }
285
- );
253
+ assetPartUpdate('Dispatching Model Updated Event will update Teacher Instructions', 'partA', {
254
+ ...model.partA,
255
+ teacherInstructions: 'Part A Teacher Instructions',
256
+ });
257
+ assetPartUpdate('Dispatching Model Updated Event will update Teacher Instructions', 'partB', {
258
+ ...model.partB,
259
+ teacherInstructions: 'Part B Teacher Instructions',
260
+ });
261
+ assetPartUpdate('Dispatching Model Updated Event will update Prompt', 'partA', {
262
+ ...model.partA,
263
+ prompt: 'Prompt A',
264
+ });
265
+ assetPartUpdate('Dispatching Model Updated Event will update Prompt', 'partB', {
266
+ ...model.partA,
267
+ prompt: 'Prompt B',
268
+ });
286
269
 
287
- assetPartUpdate(
288
- 'Dispatching Model Updated Event will update Choices - ADD CHOICE',
289
- 'partA',
290
- {
291
- ...model.partA,
292
- choices: [
293
- ...model.partA.choices,
294
- {
295
- label: 'label',
296
- value: utils.firstAvailableIndex(
297
- model.partA.choices.map(c => c.value),
298
- 0
299
- ),
300
- feedback: {
301
- type: 'none'
302
- }
303
- }
304
- ]
305
- }
306
- );
307
- assetPartUpdate(
308
- 'Dispatching Model Updated Event will update Choices - ADD CHOICE',
309
- 'partB',
310
- {
311
- ...model.partB,
312
- choices: [
313
- ...model.partB.choices,
314
- {
315
- label: 'label',
316
- value: utils.firstAvailableIndex(
317
- model.partB.choices.map(c => c.value),
318
- 0
319
- ),
320
- feedback: {
321
- type: 'none'
322
- }
323
- }
324
- ]
325
- }
326
- );
327
- assetPartUpdate(
328
- 'Dispatching Model Updated Event will update Choices - REMOVE CHOICE',
329
- 'partA',
330
- {
331
- ...model.partA,
332
- choices: model.partA.choices.splice(0, 2)
333
- }
334
- );
335
- assetPartUpdate(
336
- 'Dispatching Model Updated Event will update Choices - REMOVE CHOICE',
337
- 'partB',
338
- {
339
- ...model.partB,
340
- choices: model.partB.choices.splice(0, 2)
341
- }
342
- );
343
- assetPartUpdate(
344
- 'Dispatching Model Updated Event will update Choices - CHANGE CHOICE',
345
- 'partA',
346
- {
347
- ...model.partA,
348
- choices: model.partA.choices.splice(1, 1, {
349
- correct: true,
350
- value: 'green',
351
- label: value => value.charAt(0).toUpperCase() + value.slice(1),
270
+ assetPartUpdate('Dispatching Model Updated Event will update Choices - ADD CHOICE', 'partA', {
271
+ ...model.partA,
272
+ choices: [
273
+ ...model.partA.choices,
274
+ {
275
+ label: 'label',
276
+ value: utils.firstAvailableIndex(
277
+ model.partA.choices.map((c) => c.value),
278
+ 0,
279
+ ),
352
280
  feedback: {
353
281
  type: 'none',
354
- value: ''
355
- }
356
- })
357
- }
358
- );
359
- assetPartUpdate(
360
- 'Dispatching Model Updated Event will update Choices - CHANGE CHOICE',
361
- 'partB',
362
- {
363
- ...model.partB,
364
- choices: model.partB.choices.splice(1, 1, {
365
- correct: true,
366
- value: 'green',
367
- label: value => value.charAt(0).toUpperCase() + value.slice(1),
282
+ },
283
+ },
284
+ ],
285
+ });
286
+ assetPartUpdate('Dispatching Model Updated Event will update Choices - ADD CHOICE', 'partB', {
287
+ ...model.partB,
288
+ choices: [
289
+ ...model.partB.choices,
290
+ {
291
+ label: 'label',
292
+ value: utils.firstAvailableIndex(
293
+ model.partB.choices.map((c) => c.value),
294
+ 0,
295
+ ),
368
296
  feedback: {
369
297
  type: 'none',
370
- value: ''
371
- }
372
- })
373
- }
374
- );
298
+ },
299
+ },
300
+ ],
301
+ });
302
+ assetPartUpdate('Dispatching Model Updated Event will update Choices - REMOVE CHOICE', 'partA', {
303
+ ...model.partA,
304
+ choices: model.partA.choices.splice(0, 2),
305
+ });
306
+ assetPartUpdate('Dispatching Model Updated Event will update Choices - REMOVE CHOICE', 'partB', {
307
+ ...model.partB,
308
+ choices: model.partB.choices.splice(0, 2),
309
+ });
310
+ assetPartUpdate('Dispatching Model Updated Event will update Choices - CHANGE CHOICE', 'partA', {
311
+ ...model.partA,
312
+ choices: model.partA.choices.splice(1, 1, {
313
+ correct: true,
314
+ value: 'green',
315
+ label: (value) => value.charAt(0).toUpperCase() + value.slice(1),
316
+ feedback: {
317
+ type: 'none',
318
+ value: '',
319
+ },
320
+ }),
321
+ });
322
+ assetPartUpdate('Dispatching Model Updated Event will update Choices - CHANGE CHOICE', 'partB', {
323
+ ...model.partB,
324
+ choices: model.partB.choices.splice(1, 1, {
325
+ correct: true,
326
+ value: 'green',
327
+ label: (value) => value.charAt(0).toUpperCase() + value.slice(1),
328
+ feedback: {
329
+ type: 'none',
330
+ value: '',
331
+ },
332
+ }),
333
+ });
375
334
 
376
- assetPartUpdate(
377
- 'Dispatching Model Updated Event will update Choices',
378
- 'partA',
379
- { ...model.partA, choices: [] }
380
- );
381
- assetPartUpdate(
382
- 'Dispatching Model Updated Event will update Choices',
383
- 'partB',
384
- { ...model.partB, choices: [] }
385
- );
335
+ assetPartUpdate('Dispatching Model Updated Event will update Choices', 'partA', { ...model.partA, choices: [] });
336
+ assetPartUpdate('Dispatching Model Updated Event will update Choices', 'partB', { ...model.partB, choices: [] });
386
337
  });
387
338
  });
388
339
 
@@ -408,7 +359,7 @@ describe('main', () => {
408
359
  configuration={defaults.configuration}
409
360
  onConfigurationChanged={el.onConfigurationChanged}
410
361
  onModelChanged={el.onModelChanged}
411
- />
362
+ />,
412
363
  );
413
364
  });
414
365
 
@@ -426,29 +377,29 @@ describe('main', () => {
426
377
  'changes partA - checkbox',
427
378
  {
428
379
  partA: {
429
- choiceMode: 'checkbox'
430
- }
380
+ choiceMode: 'checkbox',
381
+ },
431
382
  },
432
383
  {
433
384
  ...model,
434
385
  partA: {
435
- choiceMode: 'checkbox'
436
- }
437
- }
386
+ choiceMode: 'checkbox',
387
+ },
388
+ },
438
389
  );
439
390
  assertOnModelChanged(
440
391
  'changes partA - choicePrefix',
441
392
  {
442
393
  partA: {
443
- choicePrefix: 'numbers'
444
- }
394
+ choicePrefix: 'numbers',
395
+ },
445
396
  },
446
397
  {
447
398
  ...model,
448
399
  partA: {
449
- choicePrefix: 'numbers'
450
- }
451
- }
400
+ choicePrefix: 'numbers',
401
+ },
402
+ },
452
403
  );
453
404
  assertOnModelChanged(
454
405
  'changes partA - partialScoring',
@@ -457,94 +408,94 @@ describe('main', () => {
457
408
  },
458
409
  {
459
410
  ...model,
460
- partialScoring: false
461
- }
411
+ partialScoring: false,
412
+ },
462
413
  );
463
414
  assertOnModelChanged(
464
415
  'changes partA - lockChoiceOrder',
465
416
  {
466
417
  partA: {
467
- lockChoiceOrder: true
468
- }
418
+ lockChoiceOrder: true,
419
+ },
469
420
  },
470
421
  {
471
422
  ...model,
472
423
  partA: {
473
- lockChoiceOrder: true
474
- }
475
- }
424
+ lockChoiceOrder: true,
425
+ },
426
+ },
476
427
  );
477
428
  assertOnModelChanged(
478
429
  'changes partA - scoringType',
479
430
  {
480
- scoringType: 'auto'
431
+ scoringType: 'auto',
481
432
  },
482
433
  {
483
434
  ...model,
484
- scoringType: 'auto'
485
- }
435
+ scoringType: 'auto',
436
+ },
486
437
  );
487
438
  assertOnModelChanged(
488
439
  'changes partB - checkbox',
489
440
  {
490
441
  partB: {
491
- choiceMode: 'checkbox'
492
- }
442
+ choiceMode: 'checkbox',
443
+ },
493
444
  },
494
445
  {
495
446
  ...model,
496
447
  partB: {
497
- choiceMode: 'checkbox'
498
- }
499
- }
448
+ choiceMode: 'checkbox',
449
+ },
450
+ },
500
451
  );
501
452
  assertOnModelChanged(
502
453
  'changes partB - choicePrefix',
503
454
  {
504
455
  partB: {
505
- choicePrefix: 'numbers'
506
- }
456
+ choicePrefix: 'numbers',
457
+ },
507
458
  },
508
459
  {
509
460
  ...model,
510
461
  partB: {
511
- choicePrefix: 'numbers'
512
- }
513
- }
462
+ choicePrefix: 'numbers',
463
+ },
464
+ },
514
465
  );
515
466
  assertOnModelChanged(
516
467
  'changes partB - partialScoring',
517
468
  {
518
- partialScoring: false
469
+ partialScoring: false,
519
470
  },
520
471
  {
521
472
  ...model,
522
- partialScoring: false
523
- }
473
+ partialScoring: false,
474
+ },
524
475
  );
525
476
  assertOnModelChanged(
526
477
  'changes partB - lockChoiceOrder',
527
478
  {
528
479
  partB: {
529
- lockChoiceOrder: true
530
- }
480
+ lockChoiceOrder: true,
481
+ },
531
482
  },
532
483
  {
533
484
  ...model,
534
485
  partB: {
535
- lockChoiceOrder: true
536
- }
537
- }
486
+ lockChoiceOrder: true,
487
+ },
488
+ },
538
489
  );
539
490
  assertOnModelChanged(
540
491
  'changes partB - scoringType',
541
492
  {
542
- scoringType: 'auto'
493
+ scoringType: 'auto',
543
494
  },
544
495
  {
545
496
  ...model,
546
- scoringType: 'auto'
547
- }
497
+ scoringType: 'auto',
498
+ },
548
499
  );
549
500
  });
550
501
  });