UNPKG

@instructure/quiz-interactions

Version:

A React UI component Library for quiz interaction types.

88 lines (72 loc) 3.03 kB
import sortBy from 'lodash/sortBy' import OrderingInteractionType from '../ordering' import checkUserResponseTransform from '../../__tests__/sharedRecordTests' describe('OrderingInteractionType', () => { const IntTypeRecord = OrderingInteractionType const intType = new IntTypeRecord() describe('#getDefaultInteractionData', () => { it('returns four blank choices', () => { const intData = intType.getDefaultInteractionData() expect(Object.keys(intData.choices).length).toBe(4) }) }) describe('#getDefaultScoringData', () => { it('returns scoring data with a value of an array of choice uuids', () => { const intData = intType.getDefaultInteractionData() const sortedIntChoiceIds = sortBy(Object.keys(intData.choices), uuid => uuid) const scoringData = intType.getDefaultScoringData(intData) const softedScoringDataIds = sortBy(scoringData.value, uuid => uuid) expect(softedScoringDataIds).toEqual(sortedIntChoiceIds) }) }) describe('#defaultProperties', () => { it('enumerates to proper keys', () => { const explicitProperties = Object.keys(intType.defaultProperties) expect(explicitProperties).toContain('includeLabels') expect(explicitProperties).toContain('displayAnswersParagraph') expect(explicitProperties).toContain('topLabel') expect(explicitProperties).toContain('bottomLabel') }) }) describe('#getDefaultUserResponse', () => { it('uses shuffledOrder if provided', () => { const intData = { shuffledOrder: [1, 2, 5, 4, 6, 3], } const response = intType.getDefaultUserResponse(intData) expect(response.value).toBe(intData.shuffledOrder) }) it('returns a list of all choice uuids when shuffledOrder is not provided', () => { const intData = intType.getDefaultInteractionData() const sortedIntChoiceIds = sortBy(Object.keys(intData.choices), uuid => uuid) const response = intType.getDefaultUserResponse(intData) const sortedResponseValue = sortBy(response.value, uuid => uuid) expect(sortedResponseValue).toEqual(sortedIntChoiceIds) }) }) describe('#hasResponse', () => { it('returns true when there is a response', () => { const resp = [1, 2, 3] expect(intType.hasResponse(resp)).toBe(true) }) it('returns false when there is no response', () => { const resp = null expect(intType.hasResponse(resp)).toBe(false) }) }) const interactionData = { choices: { uuid1: {id: 'uuid1', itemBody: 'a'}, uuid2: {id: 'uuid2', itemBody: 'b'}, uuid3: {id: 'uuid3', itemBody: 'c'}, }, } const validResponse = ['uuid1', 'uuid2', 'uuid3'] const invalidResponse = ['uuid1', 'uuid2', 'uuid4'] checkUserResponseTransform( new OrderingInteractionType(), {response: validResponse, interactionData, expected: 'a,b,c'}, {response: invalidResponse, interactionData, expected: 'a,b'}, out => out.map(rcr => rcr.props.content).join(','), ) })