Skip to content

Commit

Permalink
MDL-82034 core_course: Fix Activity chooser opening issues on behat
Browse files Browse the repository at this point in the history
  • Loading branch information
Amaia Anabitarte committed Dec 3, 2024
1 parent 31809bc commit 644272a
Show file tree
Hide file tree
Showing 27 changed files with 108 additions and 92 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,6 @@ Feature: Make test scenario can execute specific steps
And I press "Import"
And I should see "Scenario: Course with some disabled plugins"
When I am on "C1" course homepage with editing mode on
And I click on "Add an activity or resource" "button" in the "Section 1" "section"
And I open the activity chooser
Then I should see "Page" in the "Add an activity or resource" "dialogue"
And I should not see "Book" in the "Add an activity or resource" "dialogue"
9 changes: 6 additions & 3 deletions completion/tests/behat/default_activity_completion.feature
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ Feature: Allow teachers to edit the default activity completion rules in a cours
| completionview_assign | 0 |
And I click on "Save changes" "button" in the "[data-region='activitycompletion-assign']" "css_element"
And I am on "Course 1" course homepage with editing mode on
And I click on "Add an activity or resource" "button" in the "New section" "section"
And I click on "Add content" "button" in the "New section" "section"
And I click on "Activity or resource" "button" in the "New section" "section"
And I click on "Add a new Assignment" "link" in the "Add an activity or resource" "dialogue"
And I expand all fieldsets
# Completion tracking 2 = Add requirements.
Expand Down Expand Up @@ -83,7 +84,8 @@ Feature: Allow teachers to edit the default activity completion rules in a cours
And I click on "Save changes" "button" in the "[data-region='activitycompletion-forum']" "css_element"
Then I should see "Changes saved"
And I am on "Course 1" course homepage with editing mode on
And I click on "Add an activity or resource" "button" in the "New section" "section"
And I click on "Add content" "button" in the "New section" "section"
And I click on "Activity or resource" "button" in the "New section" "section"
And I click on "Add a new Forum" "link" in the "Add an activity or resource" "dialogue"
And I expand all fieldsets
# Completion tracking 2 = Add requirements.
Expand Down Expand Up @@ -122,7 +124,8 @@ Feature: Allow teachers to edit the default activity completion rules in a cours
And I click on "Save changes" "button" in the "[data-region='activitycompletion-glossary']" "css_element"
Then I should see "Changes saved"
And I am on "Course 1" course homepage with editing mode on
And I click on "Add an activity or resource" "button" in the "New section" "section"
And I click on "Add content" "button" in the "New section" "section"
And I click on "Activity or resource" "button" in the "New section" "section"
And I click on "Add a new Glossary" "link" in the "Add an activity or resource" "dialogue"
And I expand all fieldsets
# Completion tracking 2 = Add requirements.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ Feature: Courses can be created in Single Activity mode
| moodle/course:manageactivities | allow |
| moodle/course:viewparticipants | allow |
| moodle/role:assign | allow |
And I enable "subsection" "mod" plugin
When I log in as "kevin"
And I am on site homepage
And I press "Add a new course"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ Feature: Edit format course to Single Activity format
And the following "course enrolments" exist:
| user | course | role |
| teacher1 | C1 | editingteacher |
And I enable "subsection" "mod" plugin
And I log in as "teacher1"
And I am on "Course 1" course homepage
When I navigate to "Settings" in current page administration
Expand Down
2 changes: 2 additions & 0 deletions course/format/tests/behat/course_manageactivities.feature
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,9 @@ Feature: Verify edit utils availability
Given I log in as "teacher1"
When I am on "Course 1" course homepage
And I turn editing mode on
And I open the activity chooser
Then I should see "Add an activity or resource"
And I click on "Close" "button" in the "Add an activity or resource" "dialogue"
And I open "Activity sample 1" actions menu
And I should see "Edit settings"
And ".section_action_menu" "css_element" should exist in the "Section 1" "section"
Expand Down
4 changes: 4 additions & 0 deletions course/templates/activitychooserbutton.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@
type="button"
id="dropdownMenuButton"
data-toggle="dropdown"
data-action="open-addingcontent"
{{#modid}}
data-beforemod="{{modid}}"
{{/modid}}
aria-haspopup="true"
aria-expanded="false"
aria-label="{{#str}}insertcontentbefore, core, { "activityname": {{#quote}} {{activityname}} {{/quote}} } {{/str}}"
Expand Down
71 changes: 39 additions & 32 deletions course/tests/behat/activity_chooser.feature

Large diffs are not rendered by default.

13 changes: 7 additions & 6 deletions course/tests/behat/activity_chooser_plus.feature
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,15 @@ Feature: Use the activity chooser to insert activities anywhere in a section

Scenario: The activity chooser icon is hidden by default and be made visible on hover
Given I hover ".navbar-brand" "css_element"
And "Insert an activity or resource before 'Test Forum'" "button" should not be visible
When I hover "Insert an activity or resource before 'Test Forum'" "button"
Then "Insert an activity or resource before 'Test Forum'" "button" should be visible
And "Insert content before 'Test Forum'" "button" should not be visible
When I hover "Insert content before 'Test Forum'" "button"
Then "Insert content before 'Test Forum'" "button" should be visible

Scenario: The activity chooser can be used to insert modules before existing modules
Given I hover "Insert an activity or resource before 'Test Forum'" "button"
And I press "Insert an activity or resource before 'Test Forum'"
And I should see "Add an activity or resource" in the ".modal-title" "css_element"
Given I change window size to "large"
And I hover "Insert content before 'Test Forum'" "button"
And I press "Insert content before 'Test Forum'"
And I click on "Activity or resource" "button" in the ".dropdown .show" "css_element"
When I click on "Add a new Assignment" "link" in the "Add an activity or resource" "dialogue"
And I set the following fields to these values:
| Assignment name | Test Assignment |
Expand Down
15 changes: 14 additions & 1 deletion course/tests/behat/behat_course.php
Original file line number Diff line number Diff line change
Expand Up @@ -275,8 +275,10 @@ public function i_add_to_section_using_the_activity_chooser($activityname, $sect

$this->require_javascript('Please use the \'the following "activity" exists:\' data generator instead.');

$infrontpage = false;
if ($this->getSession()->getPage()->find('css', 'body#page-site-index') && (int) $sectionnum <= 1) {
// We are on the frontpage.
$infrontpage = true;
if ($sectionnum) {
// Section 1 represents the contents on the frontpage.
$sectionxpath = "//body[@id='page-site-index']" .
Expand All @@ -292,6 +294,14 @@ public function i_add_to_section_using_the_activity_chooser($activityname, $sect

// Clicks add activity or resource section link.
$sectionnode = $this->find('xpath', $sectionxpath);
if (!$infrontpage) {
$this->execute('behat_general::i_click_on_in_the', [
"//button[@data-action='open-addingcontent' and not(@data-beforemod)]",
'xpath',
$sectionnode,
'NodeElement',
]);
}
$this->execute('behat_general::i_click_on_in_the', [
"//button[@data-action='open-chooser' and not(@data-beforemod)]",
'xpath',
Expand Down Expand Up @@ -2157,8 +2167,11 @@ public function i_should_not_see_teacher_after($fteacher, $pteacher) {
* @Given /^I open the activity chooser$/
*/
public function i_open_the_activity_chooser() {
// Open the "Activity or resource and Subsection" dropdown first.
$this->execute('behat_general::i_click_on',
['//button[@data-action="open-addingcontent"]', 'xpath_element')];
$this->execute('behat_general::i_click_on',
array('//button[@data-action="open-chooser"]', 'xpath_element'));
['//button[@data-action="open-chooser"]', 'xpath_element')];

$node = $this->get_selected_node('xpath_element', '//div[@data-region="modules"]');
$this->ensure_node_is_visible($node);
Expand Down
2 changes: 1 addition & 1 deletion course/tests/behat/restrict_available_activities.feature
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,6 @@ Feature: Restrict activities availability
And I log out
And I log in as "teacher1"
When I am on "Course 1" course homepage with editing mode on
And I click on "Add an activity or resource" "button" in the "New section" "section"
And I open the activity chooser
Then "Add a new Assignment" "link" should not exist in the "Add an activity or resource" "dialogue"
Then "Add a new Glossary" "link" should not exist in the "Add an activity or resource" "dialogue"
4 changes: 2 additions & 2 deletions mod/data/tests/behat/create_activity.feature
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ Feature: Teachers can enable comments only if comments are enabled at site level

@javascript
Scenario: Teacher can enable comments if they are enabled at site level
Given I press "Add an activity or resource"
Given I open the activity chooser
And I click on "Add a new Database" "link" in the "Add an activity or resource" "dialogue"
When I expand all fieldsets
And "Allow comments on entries" "field" should exist
Expand All @@ -34,7 +34,7 @@ Feature: Teachers can enable comments only if comments are enabled at site level
# Disable comments in site config.
Given the following config values are set as admin:
| usecomments | 0 |
And I press "Add an activity or resource"
And I open the activity chooser
And I click on "Add a new Database" "link" in the "Add an activity or resource" "dialogue"
When I expand all fieldsets
And I set the field "Name" to "Test Database name 2"
Expand Down
16 changes: 8 additions & 8 deletions mod/lti/tests/behat/managecoursetools.feature
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ Feature: Manage course tools
| teacher1 | C2 | editingteacher |
And I log in as "teacher1"
And I am on "Course 1" course homepage with editing mode on
And I click on "Add an activity or resource" "button" in the "New section" "section"
And I open the activity chooser
And I should see "Teaching Tool 1" in the ".modal-body" "css_element"
And I should not see "Teaching Tool 2" in the ".modal-body" "css_element"
And I should not see "Teaching Tool 3" in the ".modal-body" "css_element"
Expand All @@ -181,15 +181,15 @@ Feature: Manage course tools
And I click on "Don't show in activity chooser" "field" in the "Teaching Tool 1" "table_row"
And I click on "Show in activity chooser" "field" in the "Teaching Tool 2" "table_row"
And I am on "Course 1" course homepage
And I click on "Add an activity or resource" "button" in the "New section" "section"
And I open the activity chooser
And I should not see "Teaching Tool 1" in the ".modal-body" "css_element"
And I should see "Teaching Tool 2" in the ".modal-body" "css_element"
And I should not see "Teaching Tool 3" in the ".modal-body" "css_element"
And I click on "Close" "button" in the ".modal-dialog" "css_element"

# Should not affect other courses.
And I am on "Course 2" course homepage
And I click on "Add an activity or resource" "button" in the "New section" "section"
And I open the activity chooser
And I should see "Teaching Tool 1" in the ".modal-body" "css_element"
And I should not see "Teaching Tool 2" in the ".modal-body" "css_element"
And I should not see "Teaching Tool 3" in the ".modal-body" "css_element"
Expand All @@ -200,7 +200,7 @@ Feature: Manage course tools
And I click on "Show in activity chooser" "field" in the "Teaching Tool 1" "table_row"
And I click on "Don't show in activity chooser" "field" in the "Teaching Tool 2" "table_row"
And I am on "Course 1" course homepage
And I click on "Add an activity or resource" "button" in the "New section" "section"
And I open the activity chooser
And I should see "Teaching Tool 1" in the ".modal-body" "css_element"
And I should not see "Teaching Tool 2" in the ".modal-body" "css_element"
And I should not see "Teaching Tool 3" in the ".modal-body" "css_element"
Expand All @@ -221,23 +221,23 @@ Feature: Manage course tools
| Course Tool 2 | /mod/lti/tests/fixtures/tool_provider.php | C1 | 1 |
And I log in as "teacher1"
And I am on "Course 1" course homepage with editing mode on
And I click on "Add an activity or resource" "button" in the "New section" "section"
And I open the activity chooser
And I should see "Course Tool 1" in the ".modal-body" "css_element"
And I should not see "Course Tool 2" in the ".modal-body" "css_element"
And I click on "Close" "button" in the ".modal-dialog" "css_element"
And I navigate to "LTI External tools" in current page administration
And I click on "Don't show in activity chooser" "field" in the "Course Tool 1" "table_row"
And I click on "Show in activity chooser" "field" in the "Course Tool 2" "table_row"
And I am on "Course 1" course homepage
And I click on "Add an activity or resource" "button" in the "New section" "section"
And I open the activity chooser
And I should not see "Course Tool 1" in the ".modal-body" "css_element"
And I should see "Course Tool 2" in the ".modal-body" "css_element"
And I click on "Close" "button" in the ".modal-dialog" "css_element"
And I navigate to "LTI External tools" in current page administration
And I click on "Show in activity chooser" "field" in the "Course Tool 1" "table_row"
And I click on "Don't show in activity chooser" "field" in the "Course Tool 2" "table_row"
And I am on "Course 1" course homepage
And I click on "Add an activity or resource" "button" in the "New section" "section"
And I open the activity chooser
And I should see "Course Tool 1" in the ".modal-body" "css_element"
And I should not see "Course Tool 2" in the ".modal-body" "css_element"

Expand Down Expand Up @@ -279,7 +279,7 @@ Feature: Manage course tools
And I restore "test_backup.mbz" backup into a new course using this options:
| Schema | Course name | Restored course |
And I should see "Restored course"
And I click on "Add an activity or resource" "button" in the "General" "section"
And I open the activity chooser
Then I should not see "Teaching Tool 1" in the ".modal-body" "css_element"
And I should see "Teaching Tool 2" in the ".modal-body" "css_element"
And I should not see "Course Tool 2" in the ".modal-body" "css_element"
Expand Down
11 changes: 6 additions & 5 deletions mod/scorm/tests/behat/default_completion.feature
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ Feature: Scorm activity default completion
Scenario: Completion conditions when there is no default set at site or course level.
Given I log in as "teacher1"
And I am on "Course 1" course homepage with editing mode on
And I press "Add an activity or resource"
And I open the activity chooser
When I click on "Add a new SCORM" "link" in the "Add an activity or resource" "dialogue"
And I expand all fieldsets
Then the field "None" matches value "1"
Expand All @@ -40,7 +40,7 @@ Feature: Scorm activity default completion
| completionstatusrequired_scorm[2] | 0 |
And I click on "Save changes" "button" in the "[data-region='activitycompletion-scorm']" "css_element"
And I am on "Course 1" course homepage with editing mode on
And I press "Add an activity or resource"
And I open the activity chooser
When I click on "Add a new SCORM" "link" in the "Add an activity or resource" "dialogue"
And I expand all fieldsets
Then the field "None" matches value "0"
Expand All @@ -62,7 +62,7 @@ Feature: Scorm activity default completion
| completionstatusrequired_scorm[2] | 0 |
And I click on "Save changes" "button" in the "[data-region='activitycompletion-scorm']" "css_element"
And I am on "Course 1" course homepage with editing mode on
And I press "Add an activity or resource"
And I open the activity chooser
When I click on "Add a new SCORM" "link" in the "Add an activity or resource" "dialogue"
And I expand all fieldsets
Then the field "None" matches value "0"
Expand All @@ -86,7 +86,7 @@ Feature: Scorm activity default completion
| course | module | completion |
| C1 | scorm | 1 |
And I am on "Course 1" course homepage with editing mode on
And I press "Add an activity or resource"
And I open the activity chooser
When I click on "Add a new SCORM" "link" in the "Add an activity or resource" "dialogue"
And I expand all fieldsets
Then the field "None" matches value "0"
Expand All @@ -105,7 +105,8 @@ Feature: Scorm activity default completion
| completionstatusrequired_scorm[2] | 1 |
And I click on "Save changes" "button" in the "[data-region='activitycompletion-scorm']" "css_element"
And I am on "Course 1" course homepage with editing mode on
And I press "Add an activity or resource"
# When I add a "Teaching Tool 1" to section "1" using the activity chooser
And I open the activity chooser
When I click on "Add a new SCORM" "link" in the "Add an activity or resource" "dialogue"
And I expand all fieldsets
Then the field "None" matches value "0"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@ Feature: Testing subsection_access_restrictions in mod_subsection
I need to set subsection conditions which prevent student access

Background:
Given I enable "subsection" "mod" plugin
And the following "users" exist:
Given the following "users" exist:
| username | firstname | lastname |
| teacher1 | Teacher | 1 |
| student1 | Student | 1 |
Expand Down
3 changes: 1 addition & 2 deletions mod/subsection/tests/behat/subsection_actionmenu.feature
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@ Feature: The module menu replaces the delegated section menu
I need to see the delegated section action menu instead of module menu.

Background:
Given I enable "subsection" "mod" plugin
And the following "users" exist:
Given the following "users" exist:
| username | firstname | lastname | email |
| teacher1 | Teacher | 1 | teacher1@example.com |
And the following "courses" exist:
Expand Down
3 changes: 1 addition & 2 deletions mod/subsection/tests/behat/subsection_coursepage.feature
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@ Feature: Users view subsections on course page
I need to view subsections on course page

Background:
Given I enable "subsection" "mod" plugin
And the following "users" exist:
Given the following "users" exist:
| username | firstname | lastname | email |
| teacher1 | Teacher | 1 | teacher1@example.com |
| student1 | Student | 1 | student1@example.com |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@ Feature: Courses should not lose subsection contents when mod_subsection is disa
Courses needs to be usable with mod_subsection disabled

Background:
Given I enable "subsection" "mod" plugin
And the following "users" exist:
Given the following "users" exist:
| username | firstname | lastname |
| teacher1 | Teacher | 1 |
| student1 | Student | 1 |
Expand Down
3 changes: 1 addition & 2 deletions mod/subsection/tests/behat/subsection_limit.feature
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@ Feature: Teacher can only add subsection when certain conditions are met
I need to create subsections only when possible

Background:
Given I enable "subsection" "mod" plugin
And the following "users" exist:
Given the following "users" exist:
| username | firstname | lastname | email |
| teacher1 | Teacher | 1 | teacher1@example.com |
And the following "courses" exist:
Expand Down
3 changes: 1 addition & 2 deletions mod/subsection/tests/behat/subsection_navigation.feature
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@ Feature: Teachers navigate to subsections
I need to navigate to subsections

Background:
Given I enable "subsection" "mod" plugin
And the following "users" exist:
Given the following "users" exist:
| username | firstname | lastname | email |
| teacher1 | Teacher | 1 | teacher1@example.com |
And the following "courses" exist:
Expand Down
3 changes: 1 addition & 2 deletions mod/subsection/tests/behat/subsection_no_completion.feature
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@ Feature: Subsection does not have completion.
I need to use subsection activity without completion

Background:
Given I enable "subsection" "mod" plugin
And the following "users" exist:
Given the following "users" exist:
| username | firstname | lastname | email |
| teacher1 | Teacher | 1 | teacher1@example.com |
And the following "courses" exist:
Expand Down
3 changes: 1 addition & 2 deletions mod/subsection/tests/behat/subsection_rename.feature
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@ Feature: Teachers can rename subsections
I need to sync subsection and activity names

Background:
Given I enable "subsection" "mod" plugin
And the following "users" exist:
Given the following "users" exist:
| username | firstname | lastname | email |
| teacher1 | Teacher | 1 | teacher1@example.com |
And the following "courses" exist:
Expand Down
Loading

0 comments on commit 644272a

Please sign in to comment.