UNPKG

@instructure/quiz-grading

Version:

The Quiz React SDK by Instructure Inc.

66 lines (57 loc) 1.97 kB
import {describe, it, expect, afterAll} from 'vitest' import {fromJS} from 'immutable' import {setStoreProvider} from '@instructure/quiz-core/common/records/reduxRecord' import {mapStateToProps} from '../index' import {REGRADE_MODAL} from '@instructure/quiz-common/constants' const wrapState = obj => Object.fromEntries(Object.entries(obj).map(([k, v]) => [k, fromJS(v)])) describe('RegradingModal index', () => { const scoreReconciliation = 'no_points' const itemId = '100' const quizEntryId = '1' const scoringAlgorithm = 'Equivalence' const pointsPossible = 1.0 const scoringData = { value: true, } const defaultState = { quizEntries: { [quizEntryId]: { entry: { id: itemId, schema: 'Item', }, entryType: 'Item', pointsPossible, }, }, items: { [itemId]: { scoringAlgorithm, scoringData, }, }, regrading: { scoreReconciliation, }, } describe('mapStateToProps', () => { let props, state afterAll(() => setStoreProvider(null)) it('sets `modalOpen` based on presence of `REGRADE_MODAL` in state', () => { state = {modal: {isOpen: 'blah'}, ...defaultState} setStoreProvider({getAppState: () => wrapState(state)}) props = mapStateToProps(wrapState(state), {quizEntryId}) expect(props.modalOpen).toBe(false) state = {modal: {isOpen: REGRADE_MODAL}, ...defaultState} setStoreProvider({getAppState: () => wrapState(state)}) props = mapStateToProps(wrapState(state), {quizEntryId}) expect(props.modalOpen).toBe(true) }) it('sets `scoreReconciliation` based on value in state', () => { const stateWithModal = {modal: {}, ...defaultState} setStoreProvider({getAppState: () => wrapState(stateWithModal)}) props = mapStateToProps(wrapState(stateWithModal)) expect(props.scoreReconciliation).toEqual(scoreReconciliation) }) }) })