Skip to content

Commit

Permalink
MOBILE-4428 quiz: Fix adaptive behaviour
Browse files Browse the repository at this point in the history
  • Loading branch information
NoelDeMartin committed Oct 16, 2023
1 parent 2019283 commit 33f61c3
Show file tree
Hide file tree
Showing 4 changed files with 73 additions and 8 deletions.
50 changes: 50 additions & 0 deletions src/addons/mod/quiz/tests/behat/quiz_adaptive.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
@mod @mod_quiz @app @javascript
Feature: Use adaptive quizzes 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 "activities" exist:
| activity | name | course | idnumber | preferredbehaviour |
| quiz | Quiz | C1 | quiz | adaptive |
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 |
And quiz "Quiz" contains the following questions:
| question | page |
| TF1 | 1 |

Scenario: Checks answers before submitting
Given 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
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
22 changes: 19 additions & 3 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 @@ -109,7 +125,7 @@ export class CoreQuestionHelperProvider {
return;
}

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

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

Expand Down

0 comments on commit 33f61c3

Please sign in to comment.