mirror of
https://github.com/moodle/moodle.git
synced 2025-04-21 08:22:07 +02:00
MDL-67264 core_course: Activity chooser behat
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 <mathewm@hotmail.co.nz> Co-authored-by: Mihail Geshoski <mihail@moodle.com> Co-authored-by: Peter <peterrolanddias@gmail.com>
This commit is contained in:
parent
05b27f2118
commit
37cf89b34a
@ -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"
|
||||
|
@ -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>
|
||||
|
@ -31,7 +31,7 @@
|
||||
}}
|
||||
<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}}
|
||||
@ -39,10 +39,10 @@
|
||||
</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>
|
||||
|
55
course/tests/behat/activity_chooser.feature
Normal file
55
course/tests/behat/activity_chooser.feature
Normal file
@ -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"
|
@ -42,6 +42,41 @@ use Behat\Gherkin\Node\TableNode as TableNode,
|
||||
*/
|
||||
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$/
|
||||
@ -203,17 +238,18 @@ class behat_course extends behat_base {
|
||||
|
||||
// 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.
|
||||
@ -1938,4 +1974,17 @@ class behat_course extends behat_base {
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
@ -42,6 +42,7 @@ $string['customfieldsettings'] = 'Common course custom fields settings';
|
||||
$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';
|
||||
|
Loading…
x
Reference in New Issue
Block a user