Skip to content

Commit

Permalink
MDL-67668 behat: Update tests for inplace editable field type
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewnicols committed Nov 23, 2020
1 parent fd71823 commit 0d580d2
Show file tree
Hide file tree
Showing 17 changed files with 86 additions and 102 deletions.
13 changes: 13 additions & 0 deletions blocks/site_main_menu/tests/behat/behat_block_site_main_menu.php
Expand Up @@ -150,4 +150,17 @@ public function i_open_actions_menu_in_site_main_menu_block($activityname) {
$xpath = "//*[contains(concat(' ',normalize-space(@class),' '),' block_site_main_menu ')]//li[contains(., $activityname)]";
$this->execute('behat_action_menu::i_open_the_action_menu_in', [$xpath, 'xpath_element']);
}

/**
* Return the list of partial named selectors.
*
* @return array
*/
public static function get_partial_named_selectors(): array {
return [
new behat_component_named_selector('Activity', [
"//*[contains(concat(' ',normalize-space(@class),' '),' block_site_main_menu ')]//li[contains(., %locator%)]"
]),
];
}
}
13 changes: 7 additions & 6 deletions blocks/site_main_menu/tests/behat/edit_activities.feature
Expand Up @@ -6,15 +6,16 @@ Feature: Edit activities in main menu block

@javascript
Scenario: Edit name of acitivity in-place in site main menu block
Given I log in as "admin"
Given the following "activity" exists:
| activity | forum |
| course | Acceptance test site |
| name | My forum name |
| idnumber | forum |
And I log in as "admin"
And I am on site homepage
And I navigate to "Turn editing on" in current page administration
And I add the "Main menu" block
When I add a "Forum" to section "0" and I fill the form with:
| Forum name | My forum name |
And I click on "Edit title" "link" in the "My forum name" activity in site main menu block
And I set the field "New name for activity My forum name" to "New forum name"
And I press the enter key
When I set the field "Edit title" in the "My forum name" "block_site_main_menu > Activity" to "New forum name"
Then I should not see "My forum name"
And I should see "New forum name"
And I follow "New forum name"
Expand Down
Expand Up @@ -158,4 +158,17 @@ public function i_open_actions_menu_in_social_activities_block($activityname) {
$xpath = "//*[contains(concat(' ',normalize-space(@class),' '),' block_social_activities ')]//li[contains(., $activityname)]";
$this->execute('behat_action_menu::i_open_the_action_menu_in', [$xpath, 'xpath_element']);
}

/**
* Return the list of partial named selectors.
*
* @return array
*/
public static function get_partial_named_selectors(): array {
return [
new behat_component_named_selector('Activity', [
"//*[contains(concat(' ',normalize-space(@class),' '),' block_social_activities ')]//li[contains(., %locator%)]",
]),
];
}
}
5 changes: 1 addition & 4 deletions blocks/social_activities/tests/behat/edit_activities.feature
Expand Up @@ -25,9 +25,7 @@ Feature: Edit activities in social activities block
And I click on "Add a new Forum" "link" in the "Add an activity or resource" "dialogue"
And I set the field "Forum name" to "My forum name"
And I press "Save and return to course"
And I click on "Edit title" "link" in the "My forum name" activity in social activities block
And I set the field "New name for activity My forum name" to "New forum name"
And I press the enter key
When I set the field "Edit title" in the "My forum name" "block_social_activities > Activity" to "New forum name"
Then I should not see "My forum name" in the "Social activities" "block"
And I should see "New forum name"
And I follow "New forum name"
Expand Down Expand Up @@ -84,4 +82,3 @@ Feature: Edit activities in social activities block
And I should not see "My forum name" in the "Social activities" "block"
And I click on "My forum name" "link" in the "Recent activity" "block"
And I should see "My forum name" in the ".breadcrumb" "css_element"
And I log out
4 changes: 1 addition & 3 deletions cohort/tests/behat/add_cohort.feature
Expand Up @@ -62,9 +62,7 @@ Feature: Add cohorts of users
@javascript
Scenario: Edit cohort name in-place
When I follow "Cohorts"
And I click on "Edit cohort name" "link" in the "Test cohort name" "table_row"
And I set the field "New name for cohort Test cohort name" to "Students cohort"
And I press the enter key
And I set the field "Edit cohort name" to "Students cohort"
Then I should not see "Test cohort name"
And I should see "Students cohort"
And I follow "Cohorts"
Expand Down
Expand Up @@ -53,9 +53,7 @@ Feature: Sections can be edited and deleted in topics format

@javascript
Scenario: Inline edit section name in topics format
When I click on "Edit topic name" "link" in the "li#section-1" "css_element"
And I set the field "New name for topic Topic 1" to "Midterm evaluation"
And I press the enter key
When I set the field "Edit topic name" in the "li#section-1" "css_element" to "Midterm evaluation"
Then I should not see "Topic 1" in the "region-main" "region"
And "New name for topic" "field" should not exist
And I should see "Midterm evaluation" in the "li#section-1" "css_element"
Expand Down
4 changes: 1 addition & 3 deletions course/format/weeks/tests/behat/edit_delete_sections.feature
Expand Up @@ -54,9 +54,7 @@ Feature: Sections can be edited and deleted in weeks format

@javascript
Scenario: Inline edit section name in weeks format
When I click on "Edit week name" "link" in the "li#section-1" "css_element"
And I set the field "New name for week 1 May - 7 May" to "Midterm evaluation"
And I press the enter key
When I set the field "Edit week name" in the "li#section-1" "css_element" to "Midterm evaluation"
Then I should not see "1 May - 7 May" in the "region-main" "region"
And "New name for week" "field" should not exist
And I should see "Midterm evaluation" in the "li#section-1" "css_element"
Expand Down
15 changes: 8 additions & 7 deletions course/tests/behat/activities_edit_name.feature
Expand Up @@ -15,15 +15,16 @@ Feature: Edit activity name in-place
And the following "course enrolments" exist:
| user | course | role |
| teacher1 | C1 | editingteacher |
And the following "activity" exists:
| course | C1 |
| activity | forum |
| name | Test forum name |
| description | Test forum description |
| idnumber | forum1 |
When I log in as "teacher1"
And I am on "Course 1" course homepage with editing mode on
And I add a "Forum" to section "1" and I fill the form with:
| Forum name | Test forum name |
| Description | Test forum description |
# Rename activity
And I click on "Edit title" "link" in the "//div[contains(@class,'activityinstance') and contains(.,'Test forum name')]" "xpath_element"
And I set the field "New name for activity Test forum name" to "Good news"
And I press the enter key
And I set the field "Edit title" in the "Test forum name" "activity" to "Good news"
Then I should not see "Test forum name" in the ".course-content" "css_element"
And "New name for activity Test forum name" "field" should not exist
And I should see "Good news"
Expand All @@ -32,7 +33,7 @@ Feature: Edit activity name in-place
And I should not see "Test forum name"
# Cancel renaming
And I click on "Edit title" "link" in the "//div[contains(@class,'activityinstance') and contains(.,'Good news')]" "xpath_element"
And I set the field "New name for activity Good news" to "Terrible news"
And I type "Terrible news"
And I press the escape key
And "New name for activity Good news" "field" should not exist
And I should see "Good news"
Expand Down
22 changes: 6 additions & 16 deletions course/tests/behat/behat_course.php
Expand Up @@ -852,22 +852,12 @@ public function i_move_activity_to_section($activityname, $sectionnumber) {
* @param string $newactivityname
*/
public function i_change_activity_name_to($activityname, $newactivityname) {

if (!$this->running_javascript()) {
throw new DriverException('Change activity name step is not available with Javascript disabled');
}

$activity = $this->escape($activityname);

$this->execute('behat_course::i_click_on_in_the_activity',
array(get_string('edittitle'), "link", $activity)
);

// Adding chr(10) to save changes.
$this->execute('behat_forms::i_set_the_field_to',
array('title', $this->escape($newactivityname) . chr(10))
);

$this->execute('behat_forms::i_set_the_field_in_container_to', [
get_string('edittitle'),
$activityname,
'activity',
$newactivityname
]);
}

/**
Expand Down
9 changes: 1 addition & 8 deletions customfield/tests/behat/edit_categories.feature
Expand Up @@ -12,23 +12,19 @@ Feature: Managers can manage categories for course custom fields
Then I should see "Other fields" in the "#customfield_catlist" "css_element"
And I navigate to "Reports > Logs" in site administration
And I press "Get these logs"
And I log out

Scenario: Edit a category name for custom course fields
Given the following "custom field categories" exist:
| name | component | area | itemid |
| Category for test | core_course | course | 0 |
And I log in as "admin"
And I navigate to "Courses > Course custom fields" in site administration
And I click on "Edit category name" "link" in the "//div[contains(@class,'categoryinstance') and contains(.,'Category for test')]" "xpath_element"
And I set the field "New value for Category for test" to "Good fields"
And I press the enter key
And I set the field "Edit category name" in the "//div[contains(@class,'categoryinstance') and contains(.,'Category for test')]" "xpath_element" to "Good fields"
Then I should not see "Category for test" in the "#customfield_catlist" "css_element"
And "New value for Category for test" "field" should not exist
And I should see "Good fields" in the "#customfield_catlist" "css_element"
And I navigate to "Reports > Logs" in site administration
And I press "Get these logs"
And I log out

Scenario: Delete a category for custom course fields
Given the following "custom field categories" exist:
Expand All @@ -46,7 +42,6 @@ Feature: Managers can manage categories for course custom fields
Then I should not see "Test category" in the "#customfield_catlist" "css_element"
And I navigate to "Reports > Logs" in site administration
And I press "Get these logs"
And I log out

Scenario: Move field in the course custom fields to another category
Given the following "custom field categories" exist:
Expand Down Expand Up @@ -78,7 +73,6 @@ Feature: Managers can manage categories for course custom fields
And I press "Move \"Field1\""
And I follow "After field Field2"
And "Field1" "text" should appear after "Field2" "text"
And I log out

Scenario: Reorder course custom field categories
Given the following "custom field categories" exist:
Expand Down Expand Up @@ -108,4 +102,3 @@ Feature: Managers can manage categories for course custom fields
And "Field1" "text" should appear after "Category1" "text"
And "Category2" "text" should appear after "Field1" "text"
And "Category3" "text" should appear after "Category2" "text"
And I log out
12 changes: 6 additions & 6 deletions mod/book/tests/behat/edit_tags.feature
Expand Up @@ -12,16 +12,16 @@ Feature: Edited book chapters handle tags correctly
And the following "courses" exist:
| fullname | shortname | format |
| Course 1 | C1 | topics |
And the following "activity" exists:
| activity | book |
| course | C1 |
| idnumber | book1 |
| name | Test book |
| description | A book about dreams |
And the following "course enrolments" exist:
| user | course | role |
| teacher1 | C1 | editingteacher |
| student1 | C1 | student |
And I log in as "teacher1"
And I am on "Course 1" course homepage with editing mode on
And I add a "Book" to section "1" and I fill the form with:
| Name | Test book |
| Description | A book about dreams! |
And I log out

Scenario: Book chapter edition of custom tags works as expected
Given I log in as "teacher1"
Expand Down
3 changes: 1 addition & 2 deletions mod/forum/tests/behat/advanced_search.feature
Expand Up @@ -130,8 +130,7 @@ Feature: The forum search allows users to perform advanced searches for forum po
And I press "Search forums"
And I should see "Advanced search"
And I set the field "Is tagged with" to "SearchedTag"
And I click on "[data-value='SearchedTag']" "css_element"
And I press the escape key
And I press the enter key
When I press "Search forums"
Then I should see "My subject"
And I should not see "Your subjective"
Expand Down
4 changes: 1 addition & 3 deletions mod/lti/tests/behat/renametool.feature
Expand Up @@ -21,9 +21,7 @@ Feature: Rename external tools via inline editing
And I am on "Course 1" course homepage with editing mode on
And I add a "External tool" to section "1" and I fill the form with:
| Activity name | Test tool activity 1 |
And I click on "Edit title" "link" in the "li#section-1" "css_element"
And I set the field "New name for activity Test tool activity 1" to "Test tool activity renamed"
And I press the enter key
And I set the field "Edit title" in the "li#section-1" "css_element" to "Test tool activity renamed"
And I navigate to "Setup > Gradebook setup" in the course gradebook
Then I should not see "Test tool activity 1"
And I should see "Test tool activity renamed"
7 changes: 5 additions & 2 deletions mod/quiz/tests/behat/behat_mod_quiz.php
Expand Up @@ -397,7 +397,8 @@ public function i_set_the_max_mark_for_quiz_question($questionname, $newmark) {

$this->execute('behat_general::assert_page_contains_text', $this->escape(get_string('edittitleinstructions')));

$this->execute('behat_forms::i_set_the_field_to', array('maxmark', $this->escape($newmark) . chr(10)));
$this->execute('behat_general::i_type', [$newmark]);
$this->execute('behat_general::i_press_named_key', ['', 'enter']);
}

/**
Expand Down Expand Up @@ -653,7 +654,9 @@ public function i_set_the_section_heading_for($sectionname, $sectionheading) {

$this->execute('behat_general::assert_page_contains_text', $this->escape(get_string('edittitleinstructions')));

$this->execute('behat_forms::i_set_the_field_to', array('section', $this->escape($sectionheading) . chr(10)));
$this->execute('behat_general::i_press_named_key', ['', 'backspace']);
$this->execute('behat_general::i_type', [$sectionheading]);
$this->execute('behat_general::i_press_named_key', ['', 'enter']);
}

/**
Expand Down
23 changes: 13 additions & 10 deletions mod/quiz/tests/behat/editing_set_marks_no_attempts.feature
Expand Up @@ -17,16 +17,19 @@ Feature: Edit quiz marks with no attempts
And the following "activities" exist:
| activity | name | course | idnumber | grade | decimalpoints | questiondecimalpoints |
| quiz | Quiz 1 | C1 | quiz1 | 20 | 2 | -1 |
And I log in as "teacher1"
And I am on "Course 1" course homepage
And I add a "True/False" question to the "Quiz 1" quiz with:
| Question name | First question |
| Question text | Answer me |
| Default mark | 2.0 |
And I add a "True/False" question to the "Quiz 1" quiz with:
| Question name | Second question |
| Question text | Answer again |
| Default mark | 3.0 |

And the following "question categories" exist:
| contextlevel | reference | name |
| Course | C1 | Test questions |
And the following "questions" exist:
| questioncategory | qtype | name | questiontext |
| Test questions | truefalse | First question | Answer me |
| Test questions | truefalse | Second question | Answer again |
And quiz "Quiz 1" contains the following questions:
| question | page | maxmark |
| First question | 1 | 2.0 |
| Second question | 1 | 3.0 |
And I am on the "Quiz 1" "mod_quiz > Edit" page logged in as "teacher1"

@javascript
Scenario: Set the max mark for a question.
Expand Down

0 comments on commit 0d580d2

Please sign in to comment.