Skip to content

Commit c4df01d

Browse files
authored
feat: reset the user's selection on retry of multiple choices (#166)
1 parent 8d73a48 commit c4df01d

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed

cypress/e2e/play/multipleChoices.cy.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ const { data } = QUESTION_APP_SETTINGS.find(
3333

3434
const id = data.questionId;
3535
const { choices } = data as MultipleChoicesAppSettingData;
36+
const allChoicesIdx = choices.map((_c, idx) => idx);
3637

3738
const multipleChoiceAppSettingsData = APP_SETTINGS[0].data as AppSettingData;
3839

@@ -90,6 +91,13 @@ const checkCorrection = (selection: number[], showCorrection = true) => {
9091
}
9192
};
9293

94+
const checkAllChoicesAreNotSelected = () =>
95+
allChoicesIdx.forEach((idx) =>
96+
cy
97+
.get(dataCyWrapper(buildMultipleChoicesButtonCy(idx, false)))
98+
.should('be.visible')
99+
);
100+
93101
/**
94102
* Checks that the buttons inputs and submit buttons are disabled or not.
95103
* It is useful to check that:
@@ -306,6 +314,18 @@ describe('Play Multiple Choices', () => {
306314
});
307315
});
308316

317+
it('Reset selection on retry', () => {
318+
const selection = [0, 2];
319+
320+
clickSelection(selection);
321+
322+
cy.get(dataCyWrapper(PLAY_VIEW_SUBMIT_BUTTON_CY)).click();
323+
cy.get(dataCyWrapper(PLAY_VIEW_RETRY_BUTTON_CY)).click();
324+
325+
// Checks that the user's selection is reset on retry.
326+
checkAllChoicesAreNotSelected();
327+
});
328+
309329
it('Correct app data', () => {
310330
// click on choices -> become selected
311331
const selection = choices.reduce(

src/components/play/multipleChoices/PlayMultipleChoices.tsx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,12 @@ const PlayMultipleChoices = ({
208208
// eslint-disable-next-line react-hooks/exhaustive-deps
209209
}, [choices, showCorrection, showCorrectness]);
210210

211+
// Reset the user's selection at each retry.
212+
useEffect(() => {
213+
setResponse([]);
214+
// eslint-disable-next-line react-hooks/exhaustive-deps
215+
}, [numberOfRetry]);
216+
211217
const onResponseClick = (value: string) => {
212218
const choiceIdx = response.choices?.findIndex((choice) => choice === value);
213219

0 commit comments

Comments
 (0)