From 2d67e08908fb93ace8ddd69fa8c55f7665138289 Mon Sep 17 00:00:00 2001 From: Caleb Cox Date: Wed, 29 Jan 2025 12:25:17 -0600 Subject: [PATCH] fixup! Move footer buttons from user-match-question --- .../userMatchModal/userMatchModal.component.js | 4 ++++ .../userMatchQuestion/userMatchQuestion.component.js | 3 +++ .../userMatchQuestion.component.spec.js | 10 +++++++++- 3 files changed, 16 insertions(+), 1 deletion(-) diff --git a/src/common/components/userMatchModal/userMatchModal.component.js b/src/common/components/userMatchModal/userMatchModal.component.js index cb6a8ff3c..e9f4d6ea8 100644 --- a/src/common/components/userMatchModal/userMatchModal.component.js +++ b/src/common/components/userMatchModal/userMatchModal.component.js @@ -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 } @@ -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 diff --git a/src/common/components/userMatchModal/userMatchQuestion/userMatchQuestion.component.js b/src/common/components/userMatchModal/userMatchQuestion/userMatchQuestion.component.js index 55929dae3..b85b37fce 100644 --- a/src/common/components/userMatchModal/userMatchQuestion/userMatchQuestion.component.js +++ b/src/common/components/userMatchModal/userMatchQuestion/userMatchQuestion.component.js @@ -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: '&' } }) diff --git a/src/common/components/userMatchModal/userMatchQuestion/userMatchQuestion.component.spec.js b/src/common/components/userMatchModal/userMatchQuestion/userMatchQuestion.component.spec.js index f08e19d0e..3e1552a6e 100644 --- a/src/common/components/userMatchModal/userMatchQuestion/userMatchQuestion.component.spec.js +++ b/src/common/components/userMatchModal/userMatchQuestion/userMatchQuestion.component.spec.js @@ -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()', () => {