Skip to content

Commit

Permalink
feat: provide hints when incorrect answer (#117)
Browse files Browse the repository at this point in the history
  • Loading branch information
ReidyT authored Jan 22, 2024
1 parent 84553a7 commit 93d811f
Show file tree
Hide file tree
Showing 23 changed files with 319 additions and 80 deletions.
1 change: 1 addition & 0 deletions cypress/e2e/Admin/create/createView.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ const newMultipleChoiceData = {
},
],
explanation: 'my new explanation',
hints: 'my new hints'
};

describe('Create View', () => {
Expand Down
7 changes: 6 additions & 1 deletion cypress/e2e/Admin/create/fillBlanks.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ const newFillBlanksData = {
question: 'new question text',
text: 'My text with <blanks> and more <blanks>',
explanation: 'new explanation',
hints: 'new hints',
};

const { data } = QUESTION_APP_SETTINGS.find(
Expand All @@ -41,7 +42,8 @@ const fillBlanksQuestion = (
text,
question,
explanation,
}: { text: string; question: string; explanation: string },
hints,
}: { text: string; question: string; explanation: string; hints: string },
{ shouldSave = true } = {}
) => {
// fill question
Expand All @@ -55,6 +57,7 @@ const fillBlanksQuestion = (
cy.get(dataCyWrapper(FILL_BLANKS_TEXT_FIELD_CY)).type(text);
}

cy.fillHints(hints);
cy.fillExplanation(explanation);

// save
Expand Down Expand Up @@ -133,6 +136,7 @@ describe('Fill in the Blanks', () => {
'have.value',
data.text
);
cy.checkHintsField(data.hints);
cy.checkExplanationField(data.explanation);
});

Expand All @@ -152,6 +156,7 @@ describe('Fill in the Blanks', () => {
'have.value',
newFillBlanksData.text
);
cy.checkHintsField(newFillBlanksData.hints);
cy.checkExplanationField(newFillBlanksData.explanation);
});
});
Expand Down
7 changes: 7 additions & 0 deletions cypress/e2e/Admin/create/multipleChoices.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,17 +63,20 @@ const newMultipleChoiceData = {
},
],
explanation: 'my new explanation',
hints: 'my new hints',
};

export const fillMultipleChoiceQuestion = (
{
choices,
question,
explanation,
hints,
}: {
choices: MultipleChoicesChoice[];
question: string;
explanation: string;
hints: string;
},
{ shouldSave = true } = {}
) => {
Expand Down Expand Up @@ -126,6 +129,7 @@ export const fillMultipleChoiceQuestion = (
});
});

cy.fillHints(hints);
cy.fillExplanation(explanation);

// save
Expand Down Expand Up @@ -184,6 +188,7 @@ describe('Multiple Choices', () => {
fillMultipleChoiceQuestion(newMultipleChoiceData);
cy.checkErrorMessage({});

cy.checkHintsField(newMultipleChoiceData.hints);
cy.checkExplanationField(newMultipleChoiceData.explanation);
});

Expand Down Expand Up @@ -286,6 +291,7 @@ describe('Multiple Choices', () => {
});
cy.get(dataCyWrapper(QUESTION_BAR_PREV_CY)).should('be.disabled');

cy.checkHintsField(data.hints);
cy.checkExplanationField(data.explanation);
});

Expand All @@ -312,6 +318,7 @@ describe('Multiple Choices', () => {
).should(isCorrect ? 'be.checked' : 'not.be.checked');
});

cy.checkHintsField(newMultipleChoiceData.hints);
cy.checkExplanationField(newMultipleChoiceData.explanation);
});

Expand Down
7 changes: 6 additions & 1 deletion cypress/e2e/Admin/create/slider.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ const newSliderData = {
max: 90,
value: 40,
explanation: 'new explanation',
hints: 'new hints',
};

const { data } = QUESTION_APP_SETTINGS.find(
Expand All @@ -45,12 +46,13 @@ type SliderValues = {
max: number;
value: number;
explanation: string;
hints: string;
};

const id = data.questionId;

const fillSliderQuestion = (
{ min, max, value, question, explanation }: SliderValues,
{ min, max, value, question, explanation, hints }: SliderValues,
originalAppSettingDataValue: number,
{ shouldSave = true } = {}
) => {
Expand Down Expand Up @@ -78,6 +80,7 @@ const fillSliderQuestion = (
cy.get(`${dataCyWrapper(SLIDER_CY)}`).type(stepsString);
}

cy.fillHints(hints);
cy.fillExplanation(explanation);

// save
Expand Down Expand Up @@ -168,6 +171,7 @@ describe('Slider', () => {
'have.value',
data.value
);
cy.checkHintsField(data.hints);
cy.checkExplanationField(data.explanation);
});

Expand Down Expand Up @@ -196,6 +200,7 @@ describe('Slider', () => {
'not.have.value',
data.value
);
cy.checkHintsField(newSliderData.hints);
cy.checkExplanationField(newSliderData.explanation);
});
});
Expand Down
9 changes: 7 additions & 2 deletions cypress/e2e/Admin/create/textInput.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ const newTextInputData = {
question: 'new question text',
text: 'new text',
explanation: 'my explanation',
hints: 'my hints',
};

const { data } = QUESTION_APP_SETTINGS.find(
Expand All @@ -40,7 +41,8 @@ const fillTextInputQuestion = (
text,
question,
explanation,
}: { text: string; question: string; explanation: string },
hints,
}: { text: string; question: string; explanation: string; hints: string },
{ shouldSave = true } = {}
) => {
// fill question if not empty
Expand All @@ -55,7 +57,8 @@ const fillTextInputQuestion = (
cy.get(`${dataCyWrapper(TEXT_INPUT_FIELD_CY)} input`).type(text);
}

// fill explanation
// fill hints and explanation
cy.fillHints(hints);
cy.fillExplanation(explanation);

// save
Expand Down Expand Up @@ -143,6 +146,7 @@ describe('Text Input', () => {
data.text
);

cy.checkHintsField(data.hints);
cy.checkExplanationField(data.explanation);
});

Expand All @@ -163,6 +167,7 @@ describe('Text Input', () => {
newTextInputData.text
);

cy.checkHintsField(newTextInputData.hints);
cy.checkExplanationField(newTextInputData.explanation);
});
});
Expand Down
34 changes: 31 additions & 3 deletions cypress/e2e/play/fillBlanks.cy.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import { Context } from '@graasp/sdk';

import { TextAppDataData } from '../../../src/components/types/types';
import {
AppSettingData,
TextAppDataData,
} from '../../../src/components/types/types';
import {
APP_SETTING_NAMES,
FILL_BLANKS_TYPE,
Expand Down Expand Up @@ -37,7 +40,7 @@ const id = data.questionId;
const { text } = data as TextAppDataData;
const { answers, words } = splitSentence(text);

const explanationShouldNotBeVisible = () => cy.checkExplanationPlay(undefined);
const fillBlanksAppSettingsData = APP_SETTINGS[3].data as AppSettingData;

// verify all answers styles
const checkCorrection = (
Expand Down Expand Up @@ -89,7 +92,7 @@ const checkCorrection = (
if (shouldBeVisible) {
cy.checkExplanationPlay(data.explanation);
} else {
explanationShouldNotBeVisible();
cy.checkExplanationPlay(null);
}
});
};
Expand Down Expand Up @@ -193,6 +196,7 @@ describe('Play Fill In The Blanks', () => {
);
}
});
cy.checkHintsPlay(null);
cy.checkExplanationPlay(null);
checkInputDisabled(false);
cy.checkNumberOfAttemptsProgression({
Expand Down Expand Up @@ -235,6 +239,9 @@ describe('Play Fill In The Blanks', () => {

checkCorrection(splitSentence(data.text));

// hints should be hidden
cy.checkHintsPlay(null);

// success displayed in question bar
cy.checkStepStatus(id, true);

Expand Down Expand Up @@ -267,6 +274,9 @@ describe('Play Fill In The Blanks', () => {
const data = partiallyCorrectAppData.data;
checkCorrection(splitSentence(data.text));

// hints should be hidden
cy.checkHintsPlay(null);

// success displayed in question bar
cy.checkStepStatus(id, false);

Expand Down Expand Up @@ -298,6 +308,9 @@ describe('Play Fill In The Blanks', () => {
const data = shorterAppData.data;
checkCorrection(splitSentence(data.text));

// hints should be hidden
cy.checkHintsPlay(null);

// success displayed in question bar
cy.checkStepStatus(id, false);

Expand Down Expand Up @@ -326,6 +339,9 @@ describe('Play Fill In The Blanks', () => {
cy.visit('/');
cy.get(dataCyWrapper(buildQuestionStepCy(id))).click();

// hints should be hidden
cy.checkHintsPlay(null);

// we do not check correction: nothing matches
// but we want to know that the app didn't crash

Expand Down Expand Up @@ -400,6 +416,9 @@ describe('Play Fill In The Blanks', () => {

checkCorrection(splitSentence(data.text));

// hints should be hidden
cy.checkHintsPlay(null);

// success displayed in question bar
cy.checkStepStatus(id, true);

Expand Down Expand Up @@ -435,6 +454,9 @@ describe('Play Fill In The Blanks', () => {
const data = partiallyCorrectAppData.data;
checkCorrection(splitSentence(data.text), false);

// hints should be displayed
cy.checkHintsPlay(fillBlanksAppSettingsData.hints);

// success displayed in question bar
cy.checkStepStatus(id, false);

Expand Down Expand Up @@ -469,6 +491,9 @@ describe('Play Fill In The Blanks', () => {
const data = shorterAppData.data;
checkCorrection(splitSentence(data.text), false);

// hints should be displayed
cy.checkHintsPlay(fillBlanksAppSettingsData.hints);

// success displayed in question bar
cy.checkStepStatus(id, false);

Expand Down Expand Up @@ -500,6 +525,9 @@ describe('Play Fill In The Blanks', () => {
cy.visit('/');
cy.get(dataCyWrapper(buildQuestionStepCy(id))).click();

// hints should be displayed
cy.checkHintsPlay(fillBlanksAppSettingsData.hints);

// we do not check correction: nothing matches
// but we want to know that the app didn't crash

Expand Down
20 changes: 19 additions & 1 deletion cypress/e2e/play/multipleChoices.cy.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import { Context } from '@graasp/sdk';

import { MultipleChoicesAppSettingData } from '../../../src/components/types/types';
import {
AppSettingData,
MultipleChoicesAppSettingData,
} from '../../../src/components/types/types';
import { APP_SETTING_NAMES, QuestionType } from '../../../src/config/constants';
import {
EXPLANATION_PLAY_CY,
Expand Down Expand Up @@ -28,6 +31,8 @@ const { data } = QUESTION_APP_SETTINGS.find(
const id = data.questionId;
const { choices } = data as MultipleChoicesAppSettingData;

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

// click on choices -> become selected
const clickSelection = (selection: number[]) => {
// eslint-disable-next-line cypress/no-unnecessary-waiting
Expand Down Expand Up @@ -124,6 +129,7 @@ describe('Play Multiple Choices', () => {
dataCyWrapper(buildMultipleChoicesButtonCy(idx, false))
).should('be.visible');
});
cy.checkHintsPlay(null);
cy.checkExplanationPlay(null);
checkInputDisabled([], false);
cy.checkNumberOfAttemptsProgression({
Expand All @@ -141,6 +147,9 @@ describe('Play Multiple Choices', () => {
// verify all choices styles
checkCorrection(selection);

// hints should be hidden
cy.checkHintsPlay(null);

// error displayed in question bar
cy.checkStepStatus(id, false);
checkInputDisabled(selection, true);
Expand All @@ -164,6 +173,9 @@ describe('Play Multiple Choices', () => {

checkCorrection(selection);

// hints should be hidden
cy.checkHintsPlay(null);

// success displayed in question bar
cy.checkStepStatus(id, true);
checkInputDisabled(selection, true);
Expand Down Expand Up @@ -218,6 +230,8 @@ describe('Play Multiple Choices', () => {
);

checkCorrection(selection);
// hints should be hidden
cy.checkHintsPlay(null);
checkInputDisabled(selection, true);
cy.checkNumberOfAttemptsProgression({
numberOfAttempts: NUMBER_OF_ATTEMPTS,
Expand Down Expand Up @@ -256,6 +270,8 @@ describe('Play Multiple Choices', () => {
// verify all choices styles
checkCorrection(selection, false);

cy.checkHintsPlay(multipleChoiceAppSettingsData.hints);

// error displayed in question bar
cy.checkStepStatus(id, false);
checkInputDisabled(selection, false);
Expand All @@ -278,6 +294,7 @@ describe('Play Multiple Choices', () => {
cy.get(dataCyWrapper(PLAY_VIEW_SUBMIT_BUTTON_CY)).click();

checkCorrection(selection);
cy.checkHintsPlay(null);

// success displayed in question bar
cy.checkStepStatus(id, true);
Expand Down Expand Up @@ -336,6 +353,7 @@ describe('Play Multiple Choices', () => {
);

checkCorrection(selection, false);
cy.checkHintsPlay(multipleChoiceAppSettingsData.hints);
checkInputDisabled(selection, false);
cy.checkNumberOfAttemptsProgression({
numberOfAttempts: NUMBER_OF_ATTEMPTS,
Expand Down
Loading

0 comments on commit 93d811f

Please sign in to comment.