Skip to content

Commit

Permalink
ucfopen#2035 Adding logic to prevent the current question index from …
Browse files Browse the repository at this point in the history
…selecting a question past the last one.
  • Loading branch information
FrenjaminBanklin committed Dec 20, 2022
1 parent 8e1667d commit 4bd8118
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ const QuestionBank = props => {
if (typeof currentQuestionIndex === 'undefined') currentQuestionIndex = null

if (currentQuestionIndex !== null) {
// this shouldn't happen, but to prevent weird lockouts constrain current question index to the highest possible
if (currentQuestionIndex >= props.model.children.models.length) {
currentQuestionIndex = props.model.children.models.length - 1
}
const questionModel = props.model.children.models[currentQuestionIndex]
const Component = questionModel.getComponentClass()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,4 +107,36 @@ describe('QuestionBank', () => {
const expectedChild = childComponents[0]
expect(expectedChild.props.id).toBe('child-id2')
})

test('QuestionBank component renders, question index past cap, multiple children', () => {
const model = OboModel.create({
id: 'id',
type: 'ObojoboDraft.Chunks.QuestionBank',
children: [
{
id: 'child-id1',
type: 'Test.Chunks.QuestionBankTestChunk'
},
{
id: 'child-id2',
type: 'Test.Chunks.QuestionBankTestChunk'
}
]
})

const moduleData = {
focusState: {}
}

const component = renderer.create(
<QuestionBank model={model} moduleData={moduleData} questionIndex={2} />
)

const childComponents = component.root.findAllByProps({ className: TEST_COMPONENT_CLASS })
expect(childComponents.length).toBe(1)

// providing a question index higher than the highest possible value should constrain it to the highest possible value
const expectedChild = childComponents[0]
expect(expectedChild.props.id).toBe('child-id2')
})
})

0 comments on commit 4bd8118

Please sign in to comment.