Skip to content

Commit

Permalink
fixup! Move footer buttons from user-match-question
Browse files Browse the repository at this point in the history
  • Loading branch information
canac committed Jan 29, 2025
1 parent b071863 commit 2d67e08
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,8 @@ class UserMatchModalController {

// Request that the user-match-question component submit the form because the user clicked next
requestAnswerSubmit () {
// Changing this will trigger $onChanges in user-match-question, which will ultimately call
// onQuestionAnswer in this controller
this.answerSubmitted = true
}

Expand All @@ -184,6 +186,8 @@ class UserMatchModalController {
}

onQuestionAnswer (success, question, answer) {
// If the user-match-question selection was invalid, success will be false, but we still need to
// reset answerSubmitted so that we can set it to true later when the user tries to submit again
this.answerSubmitted = false
if (!success) {
return
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@ export default angular
questionCount: '<',
// Set to true from the parent to cause the form to submit and call onSubmit if it is valid
submitted: '<',
// Called with a `success` boolean to indicate whether the selection was valid
// If the selection is valid, it is also called with `question` set to the current question
// and `answer` set to the selected answer
onQuestionAnswer: '&'
}
})
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,21 @@ describe('userMatchQuestion', function () {
expect($ctrl.answer).toEqual('new answer')
})

it('submits the form', () => {
it('submits the form when submitted changes to true', () => {
$ctrl.$onChanges({
submitted: { currentValue: true }
})

expect($ctrl.onQuestionAnswer).toHaveBeenCalled()
})

it('does nothing when the when submitted changes to false', () => {
$ctrl.$onChanges({
submitted: { currentValue: false }
})

expect($ctrl.onQuestionAnswer).not.toHaveBeenCalled()
})
})

describe('selectAnswer()', () => {
Expand Down

0 comments on commit 2d67e08

Please sign in to comment.