Skip to content

Commit

Permalink
MDL-67264 core_course: Activity chooser behat
Browse files Browse the repository at this point in the history
Update the selectors to use a button
Add new tests to cover new functionality
Add new new step definitions to minimise usage of xpaths

Co-authored-by: Mathew May <[email protected]>
Co-authored-by: Mihail Geshoski <[email protected]>
Co-authored-by: Peter <[email protected]>
  • Loading branch information
3 people committed Feb 13, 2020
1 parent 05b27f2 commit 37cf89b
Show file tree
Hide file tree
Showing 6 changed files with 119 additions and 14 deletions.
2 changes: 1 addition & 1 deletion blocks/site_main_menu/tests/behat/add_url.feature
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,4 @@ Feature: Add URL to main menu block
| External URL | http://www.google.com |
| id_display | In pop-up |
Then "google" "link" should exist in the "Main menu" "block"
And "Add an activity or resource" "link" should exist in the "Main menu" "block"
And "Add an activity or resource" "button" should exist in the "Main menu" "block"
2 changes: 1 addition & 1 deletion course/templates/chooser_help.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
<button data-action="close-chooser-option-summary" class="closeoptionsummary btn btn-secondary" tabindex="0" data-modname="{{modulename}}">
{{#str}} back {{/str}}
</button>
<a href="{{urls.addoption}}" aria-label="{{#str}} addnew, moodle, {{label}} {{/str}}" data-action="add-chooser-option" class="addoption btn btn-primary" tabindex="0">
<a href="{{urls.addoption}}" title="{{#str}} addnew, moodle, {{label}} {{/str}}" data-action="add-chooser-option" class="addoption btn btn-primary" tabindex="0">
{{#str}} add {{/str}}
</a>
</div>
Expand Down
8 changes: 4 additions & 4 deletions course/templates/chooser_item.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -31,18 +31,18 @@
}}
<div role="menuitem" tabindex="-1" aria-label="{{label}}" class="option d-block text-center py-3 px-2" data-region="chooser-option-container" data-modname="{{modulename}}">
<div class="optioninfo w-100" data-region="chooser-option-info-container">
<a class="d-block" href="{{urls.addoption}}" aria-label="{{#str}} addnew, moodle, {{label}} {{/str}}" tabindex="-1" data-action="add-chooser-option">
<a class="d-block" href="{{urls.addoption}}" title="{{#str}} addnew, moodle, {{label}} {{/str}}" tabindex="-1" data-action="add-chooser-option">
<span class="optionicon d-block">
{{#icon}}
{{>core/pix_icon}}
{{/icon}}
</span>
<span class="optionname d-block">{{label}}</span>
</a>
<div class="optionactions btn-group" role="group" aria-label="{{#str}} actionsfor, moodle, {{label}}{{/str}}" data-region="chooser-option-actions-container">
<button class="btn btn-icon icon-no-margin icon-size-3 m-0 optionaction" data-action="show-option-summary" tabindex="-1" aria-label="{{#str}} moreinfo {{/str}}">
<div class="optionactions btn-group" role="group" data-region="chooser-option-actions-container">
<button class="btn btn-icon icon-no-margin icon-size-3 m-0 optionaction" data-action="show-option-summary" tabindex="-1">
<span aria-hidden="true">{{#pix}} docs, core {{/pix}}</span>
<span class="sr-only">{{#str}} moreinfo {{/str}}</span>
<span class="sr-only">{{#str}} informationformodule, core_course, {{label}} {{/str}}</span>
</button>
</div>
</div>
Expand Down
55 changes: 55 additions & 0 deletions course/tests/behat/activity_chooser.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
@core @core_course @javascript
Feature: Display and choose from the available activities in course
In order to add activities to a course
As a teacher
I should be enabled to choose from a list of available activities and also being able to read their summaries.

Background:
Given the following "users" exist:
| username | firstname | lastname | email |
| teacher | Teacher | 1 | teacher@example.com |
And the following "courses" exist:
| fullname | shortname | format |
| Course | C | topics |
And the following "course enrolments" exist:
| user | course | role |
| teacher | C | editingteacher |
And I log in as "teacher"
And I am on "Course" course homepage with editing mode on

Scenario: The available activities are displayed to the teacher in the activity chooser
Given I click on "Add an activity or resource" "button" in the "Topic 1" "section"
Then I should see "Add an activity or resource" in the ".modal-title" "css_element"
And I should see "Assignment" in the ".modal-body" "css_element"

Scenario: The teacher can choose to add an activity from the activity items in the activity chooser
Given I click on "Add an activity or resource" "button" in the "Topic 3" "section"
When I click on "Add a new Assignment" "link" in the "Add an activity or resource" "dialogue"
Then I should see "Adding a new Assignment"
And I set the following fields to these values:
| Assignment name | Test Assignment Topic 3 |
And I press "Save and return to course"
Then I should see "Test Assignment Topic 3" in the "Topic 3" "section"

Scenario: The teacher can choose to add an activity from the activity summary in the activity chooser
Given I click on "Add an activity or resource" "button" in the "Topic 1" "section"
When I click on "Information about the Assignment activity" "button" in the "Add an activity or resource" "dialogue"
When I click on "Add a new Assignment" "link" in the "help" "core_course > Activity chooser screen"
Then I should see "Adding a new Assignment"

Scenario: Show summary
Given I click on "Add an activity or resource" "button" in the "Topic 1" "section"
When I click on "Information about the Assignment activity" "button" in the "Add an activity or resource" "dialogue"
Then I should see "Assignment" in the "help" "core_course > Activity chooser screen"
And I should see "The assignment activity module enables a teacher to communicate tasks, collect work and provide grades and feedback."

Scenario: Hide summary
Given I click on "Add an activity or resource" "button" in the "Topic 1" "section"
When I click on "Information about the Assignment activity" "button" in the "modules" "core_course > Activity chooser screen"
And I should see "The assignment activity module enables a teacher to communicate tasks, collect work and provide grades and feedback." in the "help" "core_course > Activity chooser screen"
And I should see "Back" in the "help" "core_course > Activity chooser screen"
When I click on "Back" "button" in the "help" "core_course > Activity chooser screen"
Then "modules" "core_course > Activity chooser screen" should exist
And "help" "core_course > Activity chooser screen" should not exist
And "Back" "button" should not exist in the "modules" "core_course > Activity chooser screen"
And I should not see "The assignment activity module enables a teacher to communicate tasks, collect work and provide grades and feedback." in the "Add an activity or resource" "dialogue"
65 changes: 57 additions & 8 deletions course/tests/behat/behat_course.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,41 @@
*/
class behat_course extends behat_base {

/**
* Return the list of partial named selectors.
*
* @return array
*/
public static function get_partial_named_selectors(): array {
return [
new behat_component_named_selector(
'Activity chooser screen', [
"%core_course/activityChooser%//*[@data-region=%locator%][contains(concat(' ', @class, ' '), ' carousel-item ')]"
]
),
];
}

/**
* Return a list of the Mink named replacements for the component.
*
* Named replacements allow you to define parts of an xpath that can be reused multiple times, or in multiple
* xpaths.
*
* This method should return a list of {@link behat_component_named_replacement} and the docs on that class explain
* how it works.
*
* @return behat_component_named_replacement[]
*/
public static function get_named_replacements(): array {
return [
new behat_component_named_replacement(
'activityChooser',
".//*[contains(concat(' ', @class, ' '), ' modchooser ')][contains(concat(' ', @class, ' '), ' modal-dialog ')]"
),
];
}

/**
* Turns editing mode on.
* @Given /^I turn editing mode on$/
Expand Down Expand Up @@ -203,17 +238,18 @@ public function i_add_to_section($activity, $section) {

// Clicks add activity or resource section link.
$sectionxpath = $sectionxpath . "/descendant::div" .
"[contains(concat(' ', normalize-space(@class) , ' '), ' section-modchooser ')]/span/a";
$sectionnode = $this->find('xpath', $sectionxpath);
$sectionnode->click();
"[contains(concat(' ', normalize-space(@class) , ' '), ' section-modchooser ')]/button";

$this->execute('behat_general::i_click_on', [$sectionxpath, 'xpath']);

// Clicks the selected activity if it exists.
$activityxpath = "//div[@id='chooseform']/descendant::label" .
"/descendant::span[contains(concat(' ', normalize-space(@class), ' '), ' typename ')]" .
$activityxpath = "//div[contains(concat(' ', normalize-space(@class), ' '), ' modchooser ')]" .
"/descendant::div[contains(concat(' ', normalize-space(@class), ' '), ' optioninfo ')]" .
"/descendant::span[contains(concat(' ', normalize-space(@class), ' '), ' optionname ')]" .
"[normalize-space(.)=$activityliteral]" .
"/parent::label/child::input";
$activitynode = $this->find('xpath', $activityxpath);
$activitynode->doubleClick();
"/parent::a";

$this->execute('behat_general::i_click_on', [$activityxpath, 'xpath']);

} else {
// Without Javascript.
Expand Down Expand Up @@ -1938,4 +1974,17 @@ public function i_should_not_see_teacher_after($fteacher, $pteacher) {
throw new ExpectationException($msg, $this->getSession());
}
}

/**
* Open the activity chooser in a course.
*
* @Given /^I open the activity chooser$/
*/
public function i_open_the_activity_chooser() {
$this->execute('behat_general::i_click_on',
array('//button[@data-action="open-chooser"]', 'xpath_element'));

$node = $this->get_selected_node('xpath_element', '//div[@data-region="modules"]');
$this->ensure_node_is_visible($node);
}
}
1 change: 1 addition & 0 deletions lang/en/course.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
$string['errorendbeforestart'] = 'The end date ({$a}) is before the course start date.';
$string['favourite'] = 'Starred course';
$string['gradetopassnotset'] = 'This course does not have a grade to pass set. It may be set in the grade item of the course (Gradebook setup).';
$string['informationformodule'] = 'Information about the {$a} activity';
$string['nocourseactivity'] = 'Not enough course activity between the start and the end of the course';
$string['nocourseendtime'] = 'The course does not have an end time';
$string['nocoursesections'] = 'No course sections';
Expand Down

0 comments on commit 37cf89b

Please sign in to comment.