diff --git a/blocks/site_main_menu/tests/behat/add_url.feature b/blocks/site_main_menu/tests/behat/add_url.feature
index dbd6386272a..1b2a7df7682 100644
--- a/blocks/site_main_menu/tests/behat/add_url.feature
+++ b/blocks/site_main_menu/tests/behat/add_url.feature
@@ -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"
diff --git a/course/templates/chooser_help.mustache b/course/templates/chooser_help.mustache
index b63502b8434..ad4dda234bf 100644
--- a/course/templates/chooser_help.mustache
+++ b/course/templates/chooser_help.mustache
@@ -47,7 +47,7 @@
-
+
{{#str}} add {{/str}}
diff --git a/course/templates/chooser_item.mustache b/course/templates/chooser_item.mustache
index f8507561689..92b930fc431 100644
--- a/course/templates/chooser_item.mustache
+++ b/course/templates/chooser_item.mustache
@@ -31,7 +31,7 @@
}}
diff --git a/course/tests/behat/activity_chooser.feature b/course/tests/behat/activity_chooser.feature
new file mode 100644
index 00000000000..9d3f2b90053
--- /dev/null
+++ b/course/tests/behat/activity_chooser.feature
@@ -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"
diff --git a/course/tests/behat/behat_course.php b/course/tests/behat/behat_course.php
index 16fa6e3e3ad..8453529c71f 100644
--- a/course/tests/behat/behat_course.php
+++ b/course/tests/behat/behat_course.php
@@ -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);
+ }
}
diff --git a/lang/en/course.php b/lang/en/course.php
index cc82f2cf51b..2573793f933 100644
--- a/lang/en/course.php
+++ b/lang/en/course.php
@@ -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';