Skip to content

Commit

Permalink
Merge pull request #3822 from NoelDeMartin/MOBILE-4428
Browse files Browse the repository at this point in the history
MOBILE-4428 quiz: Fix adaptive behaviour
  • Loading branch information
dpalou authored Oct 17, 2023
2 parents 68f67ea + 3183737 commit 70501ce
Show file tree
Hide file tree
Showing 4 changed files with 177 additions and 11 deletions.
151 changes: 151 additions & 0 deletions src/addons/mod/quiz/tests/behat/quiz_behaviour.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,151 @@
@mod @mod_quiz @app @javascript
Feature: Use quizzes with different behaviours in the app

Background:
Given the following "courses" exist:
| fullname | shortname |
| Course 1 | C1 |
And the following "users" exist:
| username |
| student1 |
And the following "course enrolments" exist:
| user | course | role |
| student1 | C1 | student |
And the following "question categories" exist:
| contextlevel | reference | name |
| Course | C1 | Test questions |
And the following "questions" exist:
| questioncategory | qtype | name |
| Test questions | multichoice | TF1 |

Scenario: Adaptive behaviour
Given the following "activities" exist:
| activity | name | course | idnumber | preferredbehaviour |
| quiz | Quiz | C1 | quiz | adaptive |
And quiz "Quiz" contains the following questions:
| question | page |
| TF1 | 1 |
And I entered the quiz activity "Quiz" on course "Course 1" as "student1" in the app
And I press "Attempt quiz now" in the app

When I press "Two" in the app
And I press "Check" in the app
And I press "OK" near "Are you sure?" in the app
Then I should find "That is not right at all" in the app

When I press "Two" in the app
And I press "One" in the app
And I press "Check" in the app
And I press "OK" near "Are you sure?" in the app
Then I should find "Parts, but only parts, of your response are correct" in the app

When I press "Three" in the app
And I press "Check" in the app
And I press "OK" near "Are you sure?" in the app
Then I should find "Well done" in the app

When I press "Submit" in the app
And I press "Submit all and finish" in the app
And I press "OK" near "Once you submit" in the app
Then I should find "Mark 0.33 out of 1.00" in the app

Scenario: Immediate feedback behaviour
Given the following "activities" exist:
| activity | name | course | idnumber | preferredbehaviour | canredoquestions |
| quiz | Quiz | C1 | quiz | immediatefeedback | 1 |
And quiz "Quiz" contains the following questions:
| question | page |
| TF1 | 1 |
And I entered the quiz activity "Quiz" on course "Course 1" as "student1" in the app
And I press "Attempt quiz now" in the app

When I press "Two" in the app
And I press "Check" in the app
And I press "OK" near "Are you sure?" in the app
Then I should find "That is not right at all" in the app
And I should find "Mark 0.00 out of 1.00" in the app

When I press "Try another question like this one" in the app
And I press "OK" near "Are you sure?" in the app
And I press "One" in the app
And I press "Check" in the app
And I press "OK" near "Are you sure?" in the app
Then I should find "Parts, but only parts, of your response are correct" in the app
And I should find "Mark 0.50 out of 1.00" in the app

When I press "Try another question like this one" in the app
And I press "OK" near "Are you sure?" in the app
And I press "One" in the app
And I press "Three" in the app
And I press "Check" in the app
And I press "OK" near "Are you sure?" in the app
Then I should find "Well done!" in the app
And I should find "The odd numbers are One and Three" in the app
And I should find "Mark 1.00 out of 1.00" in the app

When I press "Submit" in the app
And I press "Submit all and finish" in the app
And I press "OK" near "Once you submit" in the app
Then I should find "Mark 1.00 out of 1.00" in the app

Scenario: Deferred feedback with CBM behaviour
Given the following "activities" exist:
| activity | name | course | idnumber | preferredbehaviour |
| quiz | Quiz | C1 | quiz | deferredcbm |
And quiz "Quiz" contains the following questions:
| question | page |
| TF1 | 1 |
And I entered the quiz activity "Quiz" on course "Course 1" as "student1" in the app

When I press "Attempt quiz now" in the app
And I press "One" in the app
And I press "Four" in the app
And I press "Quite sure" in the app
And I press "Submit" in the app
And I press "Submit all and finish" in the app
And I press "OK" near "Once you submit" in the app
Then I should find "CBM mark 1.50" in the app
And I should find "Parts, but only parts, of your response are correct" in the app

Scenario: Interactive behaviour
Given the following "activities" exist:
| activity | name | course | idnumber | preferredbehaviour |
| quiz | Quiz | C1 | quiz | interactive |
And quiz "Quiz" contains the following questions:
| question | page |
| TF1 | 1 |
And I entered the quiz activity "Quiz" on course "Course 1" as "student1" in the app

When I press "Attempt quiz now" in the app
Then I should find "Tries remaining: 3" in the app

When I press "Two" in the app
And I press "Check" in the app
And I press "OK" near "Are you sure?" in the app
Then I should find "That is not right at all" in the app
And I should find "Hint 1" in the app
And I should find "Tries remaining: 2" in the app

When I press "Try again" in the app
And I press "OK" near "Are you sure?" in the app
And I press "Two" in the app
And I press "One" in the app
And I press "Check" in the app
And I press "OK" near "Are you sure?" in the app
Then I should find "Parts, but only parts, of your response are correct" in the app
And I should find "Hint 2" in the app
And I should find "Tries remaining: 1" in the app

When I press "Try again" in the app
And I press "OK" near "Are you sure?" in the app
And I press "Three" in the app
And I press "Check" in the app
And I press "OK" near "Are you sure?" in the app
Then I should find "Well done!" in the app
And I should find "The odd numbers are One and Three" in the app
And I should find "Correct" within "Question 1" "ion-item-divider" in the app

When I press "Submit" in the app
And I press "Submit all and finish" in the app
And I press "OK" near "Once you submit" in the app
Then I should find "Mark 0.33 out of 1.00" in the app
5 changes: 1 addition & 4 deletions src/addons/mod/quiz/tests/behat/quiz_navigation.feature
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
@mod @mod_quiz @app @javascript
Feature: Attempt a quiz in app
As a student
In order to demonstrate what I know
I need to be able to attempt quizzes
Feature: Navigate through a quiz in the app

Background:
Given the following "courses" exist:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@
<!-- Question behaviour buttons. -->
<ion-button *ngFor="let button of question?.behaviourButtons" class="ion-margin-vertical ion-text-wrap" expand="block"
(click)="buttonClicked.emit(button)" [disabled]="button.disabled">
{{ button.value }}
<core-format-text [component]="component" [componentId]="componentId" [text]="button.value" [contextLevel]="contextLevel"
[contextInstanceId]="contextInstanceId" [courseId]="courseId">
</core-format-text>
</ion-button>

<!-- Question feedback. -->
Expand Down
28 changes: 22 additions & 6 deletions src/core/features/question/services/question-helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,18 +42,34 @@ export class CoreQuestionHelperProvider {
* @param question Question.
* @param button Behaviour button (DOM element).
*/
protected addBehaviourButton(question: CoreQuestionQuestion, button: HTMLInputElement): void {
protected addBehaviourButton(question: CoreQuestionQuestion, button: HTMLElement): void {
if (!button || !question) {
return;
}

question.behaviourButtons = question.behaviourButtons || [];

// Extract the data we want.
if (button instanceof HTMLInputElement) {
// Old behaviour that changed in 4.2 because of MDL-78874.
question.behaviourButtons.push({
id: button.id,
name: button.name,
value: button.value,
disabled: button.disabled,
});

return;
}

if (!(button instanceof HTMLButtonElement)) {
return;
}

question.behaviourButtons.push({
id: button.id,
name: button.name,
value: button.value,
value: button.innerHTML,
disabled: button.disabled,
});
}
Expand Down Expand Up @@ -101,15 +117,15 @@ export class CoreQuestionHelperProvider {
* The buttons aren't deleted from the content because all the im-controls block will be removed afterwards.
*
* @param question Question to treat.
* @param selector Selector to search the buttons. By default, '.im-controls input[type="submit"]'.
* @param selector Selector to search the buttons. By default, '.im-controls [type="submit"]'.
*/
extractQbehaviourButtons(question: CoreQuestionQuestionParsed, selector?: string): void {
if (CoreQuestionDelegate.getPreventSubmitMessage(question)) {
// The question is not fully supported, don't extract the buttons.
return;
}

selector = selector || '.im-controls input[type="submit"]';
selector = selector || '.im-controls [type="submit"]';

const element = CoreDomUtils.convertToElement(question.html);

Expand Down Expand Up @@ -169,7 +185,7 @@ export class CoreQuestionHelperProvider {
*/
extractQbehaviourRedoButton(question: CoreQuestionQuestion): void {
// Create a fake div element so we can search using querySelector.
const redoSelector = 'input[type="submit"][name*=redoslot], input[type="submit"][name*=tryagain]';
const redoSelector = '[type="submit"][name*=redoslot], [type="submit"][name*=tryagain]';

// Search redo button in feedback.
if (!this.searchBehaviourButton(question, 'html', '.outcome ' + redoSelector)) {
Expand Down Expand Up @@ -739,7 +755,7 @@ export class CoreQuestionHelperProvider {
protected searchBehaviourButton(question: CoreQuestionQuestion, htmlProperty: string, selector: string): boolean {
const element = CoreDomUtils.convertToElement(question[htmlProperty]);

const button = <HTMLInputElement> element.querySelector(selector);
const button = element.querySelector<HTMLElement>(selector);
if (!button) {
return false;
}
Expand Down

0 comments on commit 70501ce

Please sign in to comment.