Skip to content

Commit 93d811f

Browse files
authored
feat: provide hints when incorrect answer (#117)
1 parent 84553a7 commit 93d811f

23 files changed

+319
-80
lines changed

cypress/e2e/Admin/create/createView.cy.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ const newMultipleChoiceData = {
4141
},
4242
],
4343
explanation: 'my new explanation',
44+
hints: 'my new hints'
4445
};
4546

4647
describe('Create View', () => {

cypress/e2e/Admin/create/fillBlanks.cy.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ const newFillBlanksData = {
2626
question: 'new question text',
2727
text: 'My text with <blanks> and more <blanks>',
2828
explanation: 'new explanation',
29+
hints: 'new hints',
2930
};
3031

3132
const { data } = QUESTION_APP_SETTINGS.find(
@@ -41,7 +42,8 @@ const fillBlanksQuestion = (
4142
text,
4243
question,
4344
explanation,
44-
}: { text: string; question: string; explanation: string },
45+
hints,
46+
}: { text: string; question: string; explanation: string; hints: string },
4547
{ shouldSave = true } = {}
4648
) => {
4749
// fill question
@@ -55,6 +57,7 @@ const fillBlanksQuestion = (
5557
cy.get(dataCyWrapper(FILL_BLANKS_TEXT_FIELD_CY)).type(text);
5658
}
5759

60+
cy.fillHints(hints);
5861
cy.fillExplanation(explanation);
5962

6063
// save
@@ -133,6 +136,7 @@ describe('Fill in the Blanks', () => {
133136
'have.value',
134137
data.text
135138
);
139+
cy.checkHintsField(data.hints);
136140
cy.checkExplanationField(data.explanation);
137141
});
138142

@@ -152,6 +156,7 @@ describe('Fill in the Blanks', () => {
152156
'have.value',
153157
newFillBlanksData.text
154158
);
159+
cy.checkHintsField(newFillBlanksData.hints);
155160
cy.checkExplanationField(newFillBlanksData.explanation);
156161
});
157162
});

cypress/e2e/Admin/create/multipleChoices.cy.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,17 +63,20 @@ const newMultipleChoiceData = {
6363
},
6464
],
6565
explanation: 'my new explanation',
66+
hints: 'my new hints',
6667
};
6768

6869
export const fillMultipleChoiceQuestion = (
6970
{
7071
choices,
7172
question,
7273
explanation,
74+
hints,
7375
}: {
7476
choices: MultipleChoicesChoice[];
7577
question: string;
7678
explanation: string;
79+
hints: string;
7780
},
7881
{ shouldSave = true } = {}
7982
) => {
@@ -126,6 +129,7 @@ export const fillMultipleChoiceQuestion = (
126129
});
127130
});
128131

132+
cy.fillHints(hints);
129133
cy.fillExplanation(explanation);
130134

131135
// save
@@ -184,6 +188,7 @@ describe('Multiple Choices', () => {
184188
fillMultipleChoiceQuestion(newMultipleChoiceData);
185189
cy.checkErrorMessage({});
186190

191+
cy.checkHintsField(newMultipleChoiceData.hints);
187192
cy.checkExplanationField(newMultipleChoiceData.explanation);
188193
});
189194

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

294+
cy.checkHintsField(data.hints);
289295
cy.checkExplanationField(data.explanation);
290296
});
291297

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

321+
cy.checkHintsField(newMultipleChoiceData.hints);
315322
cy.checkExplanationField(newMultipleChoiceData.explanation);
316323
});
317324

cypress/e2e/Admin/create/slider.cy.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ const newSliderData = {
3232
max: 90,
3333
value: 40,
3434
explanation: 'new explanation',
35+
hints: 'new hints',
3536
};
3637

3738
const { data } = QUESTION_APP_SETTINGS.find(
@@ -45,12 +46,13 @@ type SliderValues = {
4546
max: number;
4647
value: number;
4748
explanation: string;
49+
hints: string;
4850
};
4951

5052
const id = data.questionId;
5153

5254
const fillSliderQuestion = (
53-
{ min, max, value, question, explanation }: SliderValues,
55+
{ min, max, value, question, explanation, hints }: SliderValues,
5456
originalAppSettingDataValue: number,
5557
{ shouldSave = true } = {}
5658
) => {
@@ -78,6 +80,7 @@ const fillSliderQuestion = (
7880
cy.get(`${dataCyWrapper(SLIDER_CY)}`).type(stepsString);
7981
}
8082

83+
cy.fillHints(hints);
8184
cy.fillExplanation(explanation);
8285

8386
// save
@@ -168,6 +171,7 @@ describe('Slider', () => {
168171
'have.value',
169172
data.value
170173
);
174+
cy.checkHintsField(data.hints);
171175
cy.checkExplanationField(data.explanation);
172176
});
173177

@@ -196,6 +200,7 @@ describe('Slider', () => {
196200
'not.have.value',
197201
data.value
198202
);
203+
cy.checkHintsField(newSliderData.hints);
199204
cy.checkExplanationField(newSliderData.explanation);
200205
});
201206
});

cypress/e2e/Admin/create/textInput.cy.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ const newTextInputData = {
2626
question: 'new question text',
2727
text: 'new text',
2828
explanation: 'my explanation',
29+
hints: 'my hints',
2930
};
3031

3132
const { data } = QUESTION_APP_SETTINGS.find(
@@ -40,7 +41,8 @@ const fillTextInputQuestion = (
4041
text,
4142
question,
4243
explanation,
43-
}: { text: string; question: string; explanation: string },
44+
hints,
45+
}: { text: string; question: string; explanation: string; hints: string },
4446
{ shouldSave = true } = {}
4547
) => {
4648
// fill question if not empty
@@ -55,7 +57,8 @@ const fillTextInputQuestion = (
5557
cy.get(`${dataCyWrapper(TEXT_INPUT_FIELD_CY)} input`).type(text);
5658
}
5759

58-
// fill explanation
60+
// fill hints and explanation
61+
cy.fillHints(hints);
5962
cy.fillExplanation(explanation);
6063

6164
// save
@@ -143,6 +146,7 @@ describe('Text Input', () => {
143146
data.text
144147
);
145148

149+
cy.checkHintsField(data.hints);
146150
cy.checkExplanationField(data.explanation);
147151
});
148152

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

170+
cy.checkHintsField(newTextInputData.hints);
166171
cy.checkExplanationField(newTextInputData.explanation);
167172
});
168173
});

cypress/e2e/play/fillBlanks.cy.ts

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
import { Context } from '@graasp/sdk';
22

3-
import { TextAppDataData } from '../../../src/components/types/types';
3+
import {
4+
AppSettingData,
5+
TextAppDataData,
6+
} from '../../../src/components/types/types';
47
import {
58
APP_SETTING_NAMES,
69
FILL_BLANKS_TYPE,
@@ -37,7 +40,7 @@ const id = data.questionId;
3740
const { text } = data as TextAppDataData;
3841
const { answers, words } = splitSentence(text);
3942

40-
const explanationShouldNotBeVisible = () => cy.checkExplanationPlay(undefined);
43+
const fillBlanksAppSettingsData = APP_SETTINGS[3].data as AppSettingData;
4144

4245
// verify all answers styles
4346
const checkCorrection = (
@@ -89,7 +92,7 @@ const checkCorrection = (
8992
if (shouldBeVisible) {
9093
cy.checkExplanationPlay(data.explanation);
9194
} else {
92-
explanationShouldNotBeVisible();
95+
cy.checkExplanationPlay(null);
9396
}
9497
});
9598
};
@@ -193,6 +196,7 @@ describe('Play Fill In The Blanks', () => {
193196
);
194197
}
195198
});
199+
cy.checkHintsPlay(null);
196200
cy.checkExplanationPlay(null);
197201
checkInputDisabled(false);
198202
cy.checkNumberOfAttemptsProgression({
@@ -235,6 +239,9 @@ describe('Play Fill In The Blanks', () => {
235239

236240
checkCorrection(splitSentence(data.text));
237241

242+
// hints should be hidden
243+
cy.checkHintsPlay(null);
244+
238245
// success displayed in question bar
239246
cy.checkStepStatus(id, true);
240247

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

277+
// hints should be hidden
278+
cy.checkHintsPlay(null);
279+
270280
// success displayed in question bar
271281
cy.checkStepStatus(id, false);
272282

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

311+
// hints should be hidden
312+
cy.checkHintsPlay(null);
313+
301314
// success displayed in question bar
302315
cy.checkStepStatus(id, false);
303316

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

342+
// hints should be hidden
343+
cy.checkHintsPlay(null);
344+
329345
// we do not check correction: nothing matches
330346
// but we want to know that the app didn't crash
331347

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

401417
checkCorrection(splitSentence(data.text));
402418

419+
// hints should be hidden
420+
cy.checkHintsPlay(null);
421+
403422
// success displayed in question bar
404423
cy.checkStepStatus(id, true);
405424

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

457+
// hints should be displayed
458+
cy.checkHintsPlay(fillBlanksAppSettingsData.hints);
459+
438460
// success displayed in question bar
439461
cy.checkStepStatus(id, false);
440462

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

494+
// hints should be displayed
495+
cy.checkHintsPlay(fillBlanksAppSettingsData.hints);
496+
472497
// success displayed in question bar
473498
cy.checkStepStatus(id, false);
474499

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

528+
// hints should be displayed
529+
cy.checkHintsPlay(fillBlanksAppSettingsData.hints);
530+
503531
// we do not check correction: nothing matches
504532
// but we want to know that the app didn't crash
505533

cypress/e2e/play/multipleChoices.cy.ts

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
import { Context } from '@graasp/sdk';
22

3-
import { MultipleChoicesAppSettingData } from '../../../src/components/types/types';
3+
import {
4+
AppSettingData,
5+
MultipleChoicesAppSettingData,
6+
} from '../../../src/components/types/types';
47
import { APP_SETTING_NAMES, QuestionType } from '../../../src/config/constants';
58
import {
69
EXPLANATION_PLAY_CY,
@@ -28,6 +31,8 @@ const { data } = QUESTION_APP_SETTINGS.find(
2831
const id = data.questionId;
2932
const { choices } = data as MultipleChoicesAppSettingData;
3033

34+
const multipleChoiceAppSettingsData = APP_SETTINGS[0].data as AppSettingData;
35+
3136
// click on choices -> become selected
3237
const clickSelection = (selection: number[]) => {
3338
// eslint-disable-next-line cypress/no-unnecessary-waiting
@@ -124,6 +129,7 @@ describe('Play Multiple Choices', () => {
124129
dataCyWrapper(buildMultipleChoicesButtonCy(idx, false))
125130
).should('be.visible');
126131
});
132+
cy.checkHintsPlay(null);
127133
cy.checkExplanationPlay(null);
128134
checkInputDisabled([], false);
129135
cy.checkNumberOfAttemptsProgression({
@@ -141,6 +147,9 @@ describe('Play Multiple Choices', () => {
141147
// verify all choices styles
142148
checkCorrection(selection);
143149

150+
// hints should be hidden
151+
cy.checkHintsPlay(null);
152+
144153
// error displayed in question bar
145154
cy.checkStepStatus(id, false);
146155
checkInputDisabled(selection, true);
@@ -164,6 +173,9 @@ describe('Play Multiple Choices', () => {
164173

165174
checkCorrection(selection);
166175

176+
// hints should be hidden
177+
cy.checkHintsPlay(null);
178+
167179
// success displayed in question bar
168180
cy.checkStepStatus(id, true);
169181
checkInputDisabled(selection, true);
@@ -218,6 +230,8 @@ describe('Play Multiple Choices', () => {
218230
);
219231

220232
checkCorrection(selection);
233+
// hints should be hidden
234+
cy.checkHintsPlay(null);
221235
checkInputDisabled(selection, true);
222236
cy.checkNumberOfAttemptsProgression({
223237
numberOfAttempts: NUMBER_OF_ATTEMPTS,
@@ -256,6 +270,8 @@ describe('Play Multiple Choices', () => {
256270
// verify all choices styles
257271
checkCorrection(selection, false);
258272

273+
cy.checkHintsPlay(multipleChoiceAppSettingsData.hints);
274+
259275
// error displayed in question bar
260276
cy.checkStepStatus(id, false);
261277
checkInputDisabled(selection, false);
@@ -278,6 +294,7 @@ describe('Play Multiple Choices', () => {
278294
cy.get(dataCyWrapper(PLAY_VIEW_SUBMIT_BUTTON_CY)).click();
279295

280296
checkCorrection(selection);
297+
cy.checkHintsPlay(null);
281298

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

338355
checkCorrection(selection, false);
356+
cy.checkHintsPlay(multipleChoiceAppSettingsData.hints);
339357
checkInputDisabled(selection, false);
340358
cy.checkNumberOfAttemptsProgression({
341359
numberOfAttempts: NUMBER_OF_ATTEMPTS,

0 commit comments

Comments
 (0)