Skip to content

Commit

Permalink
don't use behat specific css classes. Instead, setting them always, w…
Browse files Browse the repository at this point in the history
…ithout the behat prefix
  • Loading branch information
Glutamat42 committed May 7, 2024
1 parent 3a5af9a commit 579825e
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 41 deletions.
2 changes: 0 additions & 2 deletions classes/event/course_module_viewed.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,3 @@ public static function get_objectid_mapping(): array {
return ['db' => 'adleradaptivity', 'restore' => 'adleradaptivity'];
}
}

// TODO: documentation
15 changes: 7 additions & 8 deletions classes/output/view_renderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@ private function render_content($tasks, question_usage_by_activity $quba, stdCla
$completion = new completion_info($course);

$data = [
'is_behat_mode' => defined('BEHAT_SITE_RUNNING') && BEHAT_SITE_RUNNING,
'module_completed' => answer_questions::determine_module_completion_status($completion, $cm) == completion_helpers::STATUS_CORRECT,
'tasks' => []
];
Expand All @@ -77,7 +76,7 @@ private function render_content($tasks, question_usage_by_activity $quba, stdCla
'difficulty' => $this->get_difficulty_label($task['required_difficulty']),
'status_success' => in_array($task_status, [completion_helpers::STATUS_CORRECT, completion_helpers::STATUS_OPTIONAL_INCORRECT, completion_helpers::STATUS_OPTIONAL_NOT_ATTEMPTED]),
'status_message' => get_string($this->get_task_status_message_translation_key($task_status), 'mod_adleradaptivity'),
'status_behat_class' => $this->get_task_status_behat_class($task_status),
'status_class' => $this->get_task_status_class($task_status),
'questions' => []
];

Expand Down Expand Up @@ -113,13 +112,13 @@ private function get_task_status_message_translation_key(string $status): string
};
}

private function get_task_status_behat_class(string $status): string {
private function get_task_status_class(string $status): string {
return match ($status) {
completion_helpers::STATUS_NOT_ATTEMPTED => 'behat_task-not-attempted',
completion_helpers::STATUS_CORRECT => 'behat_task-correct',
completion_helpers::STATUS_INCORRECT => 'behat_task-incorrect',
completion_helpers::STATUS_OPTIONAL_NOT_ATTEMPTED => 'behat_task-optional-not-attempted',
completion_helpers::STATUS_OPTIONAL_INCORRECT => 'behat_task-optional-incorrect',
completion_helpers::STATUS_NOT_ATTEMPTED => 'task-not-attempted',
completion_helpers::STATUS_CORRECT => 'task-correct',
completion_helpers::STATUS_INCORRECT => 'task-incorrect',
completion_helpers::STATUS_OPTIONAL_NOT_ATTEMPTED => 'task-optional-not-attempted',
completion_helpers::STATUS_OPTIONAL_INCORRECT => 'task-optional-incorrect',
default => 'unknown',
};
}
Expand Down
14 changes: 6 additions & 8 deletions templates/questions.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,13 @@
Example context (json):
{
"module_completed": false,
"is_behat_mode": false,
"tasks": [
{
"title": "Task 1",
"optional": false,
"difficulty": "Medium",
"status_success": false,
"status_behat_class": "behat_status-failure",
"status_class": "status-failure",
"status_message": "Task not completed",
"questions": [
{
Expand All @@ -29,12 +28,12 @@
<div class="mod_adleradaptivity_questions">
<!-- Module completion messages -->
{{#module_completed}}
<div class="alert alert-success {{#is_behat_mode}}behat_module-success{{/is_behat_mode}}" role="alert">
<div class="alert alert-success module-success" role="alert">
{{#str}}view_module_completed_success, mod_adleradaptivity{{/str}}
</div>
{{/module_completed}}
{{^module_completed}}
<div class="alert alert-warning {{#is_behat_mode}}behat_module-failure{{/is_behat_mode}}" role="alert">
<div class="alert alert-warning module-failure" role="alert">
{{#str}}view_module_completed_no, mod_adleradaptivity{{/str}}
</div>
{{/module_completed}}
Expand All @@ -53,10 +52,10 @@

<!-- Task Status Handling -->
{{#status_success}}
<p class="{{#is_behat_mode}}{{{status_behat_class}}}{{/is_behat_mode}}">✅ {{{status_message}}}</p>
<p class="{{{status_class}}}">✅ {{{status_message}}}</p>
{{/status_success}}
{{^status_success}}
<div class="alert alert-warning {{#is_behat_mode}}{{{status_behat_class}}}{{/is_behat_mode}}" role="alert">
<div class="alert alert-warning {{{status_class}}}" role="alert">
{{{status_message}}}
</div>
{{/status_success}}
Expand All @@ -66,9 +65,8 @@
{{#questions}}
<div class="question">
<hr />
<!-- TODO: class always, not behat exclusive-->
{{#status_best_try}}
<p class="{{#is_behat_mode}}behat_question-status-success{{/is_behat_mode}}">✅ {{#str}}view_question_success, mod_adleradaptivity{{/str}}</p>
<p class="question-status-success">✅ {{#str}}view_question_success, mod_adleradaptivity{{/str}}</p>
{{/status_best_try}}
<div class="question-content">{{{content}}}</div>
</div>
Expand Down
14 changes: 7 additions & 7 deletions tests/behat/attempt.feature
Original file line number Diff line number Diff line change
Expand Up @@ -36,16 +36,16 @@ Feature: Attempt an adleradaptivity
And I click on "One" "qtype_multichoice > Answer" in the "Q2" "question"
And I click on "Three" "qtype_multichoice > Answer" in the "Q2" "question"
And I click on "Check" "button" in the "Q2" "question"
Then I should see a ".behat_module-success" element
And I should see a ".behat_task-correct" element
Then I should see a ".module-success" element
And I should see a ".task-correct" element

@javascript
Scenario: Attempt a question with an incorrect answer
When I am on the "Adler Activity 1" "mod_adleradaptivity > View" page logged in as "student"
And I click on "Two" "qtype_multichoice > Answer" in the "Q2" "question"
And I click on "Check" "button" in the "Q2" "question"
Then I should see a ".behat_module-failure" element
And I should see a ".behat_task-incorrect" element
Then I should see a ".module-failure" element
And I should see a ".task-incorrect" element

@javascript
Scenario: Attempt a question with a wrong answer that was previously correct and completed the task
Expand All @@ -55,8 +55,8 @@ Feature: Attempt an adleradaptivity
When I am on the "Adler Activity 1" "mod_adleradaptivity > View" page logged in as "student"
And I click on "Two" "qtype_multichoice > Answer" in the "Q2" "question"
And I click on "Check" "button" in the "Q2" "question"
Then I should see a ".behat_module-success" element
And I should see a ".behat_task-correct" element
Then I should see a ".module-success" element
And I should see a ".task-correct" element
# question is still considered correct, as it was answered correctly before, but the current answer is wrong
And I should see a ".behat_question-status-success" element
And I should see a ".question-status-success" element
And I should see "Partially correct"
32 changes: 16 additions & 16 deletions tests/behat/view_module.feature
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,10 @@ Feature: View an adleradaptivity

Scenario: Display module without any attempts
When I am on the "Adler Activity 1" "mod_adleradaptivity > View" page logged in as "student"
Then I should see a ".behat_module-failure" element
And I should see "1" ".behat_task-not-attempted" element
And I should see "1" ".behat_task-optional-not-attempted" element
And I should not see ".behat_question-status-success"
Then I should see a ".module-failure" element
And I should see "1" ".task-not-attempted" element
And I should see "1" ".task-optional-not-attempted" element
And I should not see ".question-status-success"

Scenario: Display attempt not sufficient to complete the module
Given user "student" has attempted "Adler Activity 1" with results:
Expand All @@ -45,22 +45,22 @@ Feature: View an adleradaptivity
| Q2 | incorrect |
| Q4 | incorrect |
When I am on the "Adler Activity 1" "mod_adleradaptivity > View" page logged in as "student"
Then I should see a ".behat_module-failure" element
And I should see "1" ".behat_question-status-success" elements
And I should see "1" ".behat_task-incorrect" element
And I should see "1" ".behat_task-optional-incorrect" element
Then I should see a ".module-failure" element
And I should see "1" ".question-status-success" elements
And I should see "1" ".task-incorrect" element
And I should see "1" ".task-optional-incorrect" element

Scenario: Display attempt sufficient to complete the module
Given user "student" has attempted "Adler Activity 1" with results:
| question_name | answer |
| Q2 | correct |
| Q4 | correct |
When I am on the "Adler Activity 1" "mod_adleradaptivity > View" page logged in as "student"
Then I should see a ".behat_module-success" element
And I should see "2" ".behat_question-status-success" elements
And I should not see a ".behat_task-optional-incorrect" element
And I should not see a ".behat_task-optional-not-attempted" element
And I should see a ".behat_task-correct" element
Then I should see a ".module-success" element
And I should see "2" ".question-status-success" elements
And I should not see a ".task-optional-incorrect" element
And I should not see a ".task-optional-not-attempted" element
And I should see a ".task-correct" element

Scenario: Display module with a question that has multiple references to it (in another module)
Given the following "activities" exist:
Expand All @@ -73,6 +73,6 @@ Feature: View an adleradaptivity
| task_title | question_category | question_name | difficulty |
| Task2_1 | Test questions | Q1 | 0 |
When I am on the "Adler Activity 2" "mod_adleradaptivity > View" page logged in as "student"
Then I should see a ".behat_module-failure" element
And I should see "1" ".behat_task-not-attempted" element
And I should not see ".behat_question-status-success"
Then I should see a ".module-failure" element
And I should see "1" ".task-not-attempted" element
And I should not see ".question-status-success"

0 comments on commit 579825e

Please sign in to comment.