UNPKG

@instructure/quiz-interactions

Version:

A React UI component Library for quiz interaction types.

67 lines (57 loc) 2.25 kB
import {render} from '@testing-library/react' import {vi} from 'vitest' import {expect} from '@instructure/ui-test-utils' import EssayInteractionType from '../essay' import checkUserResponseTransform from '../../__tests__/sharedRecordTests' vi.mock('@instructure/canvas-rce/es/enhance-user-content/enhance_user_content', () => ({ enhanceUserContent: vi.fn(), })) describe('EssayInteractionType', () => { const IntTypeRecord = EssayInteractionType const intType = new IntTypeRecord() describe('#getDefaultScoringData', () => { it('defaults to an empty string value', () => { const scoring = intType.getDefaultScoringData() expect(scoring).to.deep.equal({value: ''}) }) }) describe('#getDefaultInteractionData', () => { it('returns essay options when slug is "essay" ', () => { const options = intType.getDefaultInteractionData() expect(options.essay).to.be.null() expect(options.rce).to.be.true() expect(options.spellCheck).to.be.false() expect(options.wordCount).to.be.false() expect(options.wordLimitEnabled).to.be.false() expect(options.wordLimitMax).to.be.null() expect(options.wordLimitMin).to.be.null() expect(options.fileUpload).to.be.false() }) }) describe('#hasResponse', () => { it('returns true when there is a response', () => { const resp = 'this is my essay' expect(intType.hasResponse(resp)).to.be.true() }) it('returns false when there is no response', () => { const resp = '' expect(intType.hasResponse(resp)).to.be.false() }) }) const response = {interactionData: {rce: false}, response: 'adb', expected: 'adb'} checkUserResponseTransform( new EssayInteractionType(), response, response, out => out.props.children, ) describe('getRenderedResponse with rce content', () => { it('renders via RichContentRenderer and sanitizes XSS', () => { const intType = new EssayInteractionType() const output = intType.getRenderedResponse("<script>alert('hi')</script>adb", {rce: true}) const {container} = render(output) expect(container.querySelector('script')).to.be.null() expect(container.textContent).to.contain('adb') }) }) })