UNPKG

@instructure/quiz-interactions

Version:

A React UI component Library for quiz interaction types.

99 lines (86 loc) 2.96 kB
import {describe, expect, it} from 'vitest' import EditStemController from '../editStemController' describe('EditStemController', () => { describe('#textForStemItem', () => { const blankId = '123' const dangerousText = '<script> console.log("hey") </script>' const defaultProps = { scoringData: { value: [ { id: blankId, scoringData: { blankText: dangerousText, }, }, ], }, } const controller = new EditStemController(defaultProps) it('type not blank returns the stemItem value', () => { const stemItem = {type: 'text', value: dangerousText} expect(controller.textForStemItem(stemItem)).toEqual(dangerousText) }) it('type blank returns scoringData blankText', () => { const stemItem = {type: 'blank', blankId} expect(controller.textForStemItem(stemItem)).toEqual(dangerousText) }) }) describe('#getFocusData', () => { const makeItems = omitIds => { return [ {type: 'text', id: 'id1', value: 'hello '}, {type: 'blank', id: 'id2', value: 'my'}, {type: 'text', id: 'id3', value: ' name '}, {type: 'blank', id: 'id4', value: 'is'}, {type: 'text', id: 'id5', value: ' bob smith'}, ] .filter(item => !omitIds.includes(item.id)) .map((item, idx) => Object.assign({}, item, {position: idx + 1})) } const runTest = (oldItems, newItems, expected) => { const controller = new EditStemController({stemItems: newItems}) expect(controller.getFocusData({stemItems: oldItems})).toEqual(expected) } it('returns nothing when a stem item is modified', () => { const oldItems = makeItems([]) const newItems = makeItems([]) newItems[0].value = 'hi' runTest(oldItems, newItems, null) }) it('deletes a blank between two text items', () => { const oldItems = makeItems([]) const newItems = [ {type: 'text', id: 'id2', value: 'hello my name ', position: 1}, {type: 'text', id: 'id4', value: 'is', position: 2}, {type: 'text', id: 'id5', value: 'bob smith', position: 3}, ] runTest(oldItems, newItems, { cursorPosition: 8, stemItem: { id: 'id2', position: 1, type: 'text', value: 'hello my name ', }, }) }) it('creates a blank from a text item', () => { const oldItems = makeItems([]) const newItems = makeItems(['id5']).concat([ {type: 'text', id: 'id5', value: ' ', position: 5}, {type: 'blank', id: 'id6', value: 'bob', position: 6}, {type: 'text', id: 'id7', value: ' smith', position: 5}, ]) runTest(oldItems, newItems, { cursorPosition: null, stemItem: { type: 'blank', id: 'id6', value: 'bob', position: 6, }, }) }) }) })