Skip to content

Commit

Permalink
feat: reset the user's selection on retry of multiple choices
Browse files Browse the repository at this point in the history
  • Loading branch information
ReidyT committed Jul 17, 2024
1 parent 8d73a48 commit b01169d
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
20 changes: 20 additions & 0 deletions cypress/e2e/play/multipleChoices.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ const { data } = QUESTION_APP_SETTINGS.find(

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

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

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

const checkAllChoicesAreNotSelected = () =>
allChoicesIdx.forEach((idx) =>
cy
.get(dataCyWrapper(buildMultipleChoicesButtonCy(idx, false)))
.should('be.visible')
);

/**
* Checks that the buttons inputs and submit buttons are disabled or not.
* It is useful to check that:
Expand Down Expand Up @@ -306,6 +314,18 @@ describe('Play Multiple Choices', () => {
});
});

it('Reset selection on retry', () => {
const selection = [0, 2];

clickSelection(selection);

cy.get(dataCyWrapper(PLAY_VIEW_SUBMIT_BUTTON_CY)).click();
cy.get(dataCyWrapper(PLAY_VIEW_RETRY_BUTTON_CY)).click();

// Checks that the user's selection is reset on retry.
checkAllChoicesAreNotSelected();
});

it('Correct app data', () => {
// click on choices -> become selected
const selection = choices.reduce(
Expand Down
6 changes: 6 additions & 0 deletions src/components/play/multipleChoices/PlayMultipleChoices.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,12 @@ const PlayMultipleChoices = ({
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [choices, showCorrection, showCorrectness]);

// Reset the user's selection at each retry.
useEffect(() => {
setResponse([]);
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [numberOfRetry]);

const onResponseClick = (value: string) => {
const choiceIdx = response.choices?.findIndex((choice) => choice === value);

Expand Down

0 comments on commit b01169d

Please sign in to comment.