@instructure/quiz-taking
Version:
65 lines (58 loc) • 1.92 kB
JavaScript
import {fromJS} from 'immutable'
import {wrapState} from '../../../../../tests/utils/wrapState'
import {mapStateToProps, mapDispatchToProps, getPinnedItems} from '../index'
import {describe, expect, it, vi} from 'vitest'
describe('Taking Sidebar Index', () => {
describe('honorsSidebarProps', () => {
const scrollToItemStub = vi.fn()
const props = {
scrollToItem: scrollToItemStub,
}
it('honors props if scrollToItem included', () => {
let mapDTP = mapDispatchToProps(f => f, props)
mapDTP.scrollToItem()
expect(scrollToItemStub).toHaveBeenCalledOnce()
mapDTP = mapDispatchToProps(f => f, props)
mapDTP.scrollToItem()
expect(scrollToItemStub).toHaveBeenCalledTimes(2)
})
it('honors props if sidebarOpen included', () => {
const stateToProps = wrapState({
quizSessions: {
activeQuizSessionId: '1',
1: {
allowBacktracking: true,
oneAtATimeType: 'question',
},
},
sidebar: {
isOpen: true,
},
})
let mapDTP = mapStateToProps(stateToProps, {sidebarOpen: 'this is a prop'})
expect(mapDTP.sidebarOpen).toEqual('this is a prop')
mapDTP = mapStateToProps(stateToProps, {})
expect(mapDTP.sidebarOpen).toBe(true)
})
})
describe('#getPinnedItems', () => {
it('returns a list of pins with correct position and sessionItemId', () => {
const fakeState = wrapState({
sessionItems: {
10: {id: 10, position: 1},
20: {id: 20, position: 2},
30: {id: 30, position: 3},
},
})
const fakeQuizSession = fromJS({
takingData: {
pins: [2, 3],
},
})
expect(getPinnedItems(fakeState, fakeQuizSession).toJS()).toEqual([
{position: 2, sessionItemId: 20},
{position: 3, sessionItemId: 30},
])
})
})
})