Skip to content

Commit

Permalink
MDL-78288 behat: New availability info selectors
Browse files Browse the repository at this point in the history
- Create a new availability info selectors for section and activity data info regions
- Replace css_element by created selectors in the existing behat tests
  • Loading branch information
Amaia Anabitarte committed Jul 12, 2023
1 parent 290e6f4 commit b9a840f
Show file tree
Hide file tree
Showing 7 changed files with 89 additions and 38 deletions.
Expand Up @@ -44,7 +44,7 @@ Feature: Confirm that conditions on completion no longer cause a bug
And I click on "Activity completion" "button" in the "Add restriction..." "dialogue"
And I set the field with xpath "//div[contains(concat(' ', normalize-space(@class), ' '), ' availability-item ')][preceding-sibling::div]//select[@name='cm']" to "Page2"
And I press "Save and return to course"
And I click on "Show more" "button" in the "#section-1 .availabilityinfo" "css_element"
And I click on "Show more" "button" in the "TestGlossary" "core_availability > Activity availability"
Then I should see "Not available unless:" in the ".activity.glossary" "css_element"
And I should see "The activity Page1 is marked complete" in the ".activity.glossary" "css_element"
And I should see "The activity Page2 is marked complete" in the ".activity.glossary" "css_element"
Expand Down
51 changes: 51 additions & 0 deletions availability/tests/behat/behat_availability.php
@@ -0,0 +1,51 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.

require_once(__DIR__ . '/../../../lib/behat/behat_base.php');

/**
* Availability related behat steps and selectors definitions.
*
* @package core_availability
* @category test
* @copyright 2023 Amaia Anabitarte <amaia@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class behat_availability 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 availability', [<<<XPATH
.//li[contains(concat(' ', normalize-space(@class), ' '), ' activity ')][descendant::*[contains(normalize-space(.), %locator%)]]
//div[@data-region='availabilityinfo']
XPATH
]
),
new \behat_component_named_selector(
'Section availability', [<<<XPATH
.//li[@id = %locator%]//div[@data-region='availabilityinfo']
XPATH
]
),
];
}
}
42 changes: 21 additions & 21 deletions availability/tests/behat/display_availability.feature
Expand Up @@ -69,24 +69,24 @@ Feature: display_availability
And I press "Save and return to course"

# Page 1 should show in single-line format, showing the date
Then I should see "Available until" in the "#section-1 .availabilityinfo" "css_element"
And I should see "2013" in the "#section-1 .availabilityinfo" "css_element"
And I should see "2013" in the "#section-1 .availabilityinfo" "css_element"
And "li" "css_element" should not exist in the "#section-1 .availabilityinfo" "css_element"
And "Show more" "button" should not exist in the "#section-1 .availabilityinfo" "css_element"
Then I should see "Available until" in the "Page 1" "core_availability > Activity availability"
And I should see "2013" in the "Page 1" "core_availability > Activity availability"
And I should see "2013" in the "Page 1" "core_availability > Activity availability"
And "li" "css_element" should not exist in the "Page 1" "core_availability > Activity availability"
And "Show more" "button" should not exist in the "Page 1" "core_availability > Activity availability"

# Page 2 should show in list format.
And "li" "css_element" should exist in the "#section-2 .availabilityinfo" "css_element"
And I should see "Not available unless:" in the "#section-2 .availabilityinfo" "css_element"
And I should see "It is before" in the "#section-2 .availabilityinfo" "css_element"
And I should see "hidden otherwise" in the "#section-2 .availabilityinfo" "css_element"
And "li" "css_element" should exist in the "Page 2" "core_availability > Activity availability"
And I should see "Not available unless:" in the "Page 2" "core_availability > Activity availability"
And I should see "It is before" in the "Page 2" "core_availability > Activity availability"
And I should see "hidden otherwise" in the "Page 2" "core_availability > Activity availability"
And I click on "Show more" "button" in the "Page 2" "activity"
And I should see "Email address" in the "#section-2 .availabilityinfo" "css_element"
And I click on "Show less" "button" in the "#section-2 .availabilityinfo" "css_element"
And I should not see "Email address" in the "#section-2 .availabilityinfo" "css_element"
And I should see "Email address" in the "Page 2" "core_availability > Activity availability"
And I click on "Show less" "button" in the "Page 2" "core_availability > Activity availability"
And I should not see "Email address" in the "Page 2" "core_availability > Activity availability"

# Page 3 should not have available info.
And "#section-3 .availabilityinfo" "css_element" should not exist
And "Page 3" "core_availability > Activity availability" should not exist

# Change to student view.
Given I am on the "C1" "Course" page logged in as "student1"
Expand Down Expand Up @@ -139,9 +139,9 @@ Feature: display_availability
And I am on "Course 1" course homepage

# Check display
Then I should see "Not available unless" in the "#section-1 .availabilityinfo" "css_element"
And I should see "Available until" in the "#section-2 .availabilityinfo" "css_element"
And I should see "hidden otherwise" in the "#section-2 .availabilityinfo" "css_element"
Then I should see "Not available unless" in the "section-1" "core_availability > Section availability"
And I should see "Available until" in the "section-2" "core_availability > Section availability"
And I should see "hidden otherwise" in the "section-2" "core_availability > Section availability"

# Change to student view.
Given I am on the "Course 1" "Course" page logged in as "student1"
Expand All @@ -153,11 +153,11 @@ Feature: display_availability

# Section 1 should be visible and show info.
And I should see "Topic 1" in the "region-main" "region"
And I should see "Not available unless" in the "#section-1 .availabilityinfo" "css_element"
And I click on "Show more" "button" in the "#section-1 .availabilityinfo" "css_element"
And I should see "Email address" in the "#section-1 .availabilityinfo" "css_element"
And I click on "Show less" "button" in the "#section-1 .availabilityinfo" "css_element"
And I should not see "Email address" in the "#section-1 .availabilityinfo" "css_element"
And I should see "Not available unless" in the "section-1" "core_availability > Section availability"
And I click on "Show more" "button" in the "section-1" "core_availability > Section availability"
And I should see "Email address" in the "section-1" "core_availability > Section availability"
And I click on "Show less" "button" in the "section-1" "core_availability > Section availability"
And I should not see "Email address" in the "section-1" "core_availability > Section availability"

# Section 2 should not be available at all
And I should not see "Topic 2" in the "region-main" "region"
Expand Up @@ -36,7 +36,7 @@
}}
{{#hasmodavailability}}
{{#info}}
<div class="activity-availability availabilityinfo small {{classes}}">
<div class="activity-availability availabilityinfo small {{classes}}" data-region="availabilityinfo">
{{^isrestricted}}
<span class="badge badge-pill badge-warning">{{{text}}}</span>
{{/isrestricted}}
Expand Down
Expand Up @@ -36,7 +36,7 @@
<div class="section_availability">
{{#hasavailability}}
{{#info}}
<div class="availabilityinfo {{classes}}">
<div class="availabilityinfo {{classes}}" data-region="availabilityinfo">
{{^isrestricted}}
<span class="badge badge-pill badge-warning">{{{text}}}</span>
{{/isrestricted}}
Expand Down
26 changes: 13 additions & 13 deletions course/tests/behat/course_collapse_sections.feature
Expand Up @@ -65,8 +65,8 @@ Feature: Collapse course sections
And I should see "Assignment 2" in the "region-main" "region"
And I should see "Book 2" in the "region-main" "region"
And I should see "Book 3" in the "region-main" "region"
And I should see "Available until" in the "#section-4 .availabilityinfo" "css_element"
And I should see "2013" in the "#section-4 .availabilityinfo" "css_element"
And I should see "Available until" in the "section-4" "core_availability > Section availability"
And I should see "2013" in the "section-4" "core_availability > Section availability"
And I should not see "Forum 4"
And I should see "Not available" in the "#section-5" "css_element"
And I should not see "Forum 5"
Expand All @@ -83,7 +83,7 @@ Feature: Collapse course sections
And I should not see "Assignment 2" in the "region-main" "region"
And I should not see "Book 2" in the "region-main" "region"
And I should not see "Book 3" in the "region-main" "region"
And I should not see "Available until" in the "#section-4 .availabilityinfo" "css_element"
And I should not see "Available until" in the "section-4" "core_availability > Section availability"
And I click on "#collapssesection1" "css_element"
And I click on "#collapssesection2" "css_element"
And I click on "#collapssesection3" "css_element"
Expand All @@ -93,7 +93,7 @@ Feature: Collapse course sections
And I should see "Assignment 2" in the "region-main" "region"
And I should see "Book 2" in the "region-main" "region"
And I should see "Book 3" in the "region-main" "region"
And I should see "Available until" in the "#section-4 .availabilityinfo" "css_element"
And I should see "Available until" in the "section-4" "core_availability > Section availability"

@javascript
Scenario: Expand/collapse sections for Weeks format.
Expand All @@ -107,8 +107,8 @@ Feature: Collapse course sections
And I should see "Assignment 2" in the "region-main" "region"
And I should see "Book 2" in the "region-main" "region"
And I should see "Book 3" in the "region-main" "region"
And I should see "Available until" in the "#section-4 .availabilityinfo" "css_element"
And I should see "2013" in the "#section-4 .availabilityinfo" "css_element"
And I should see "Available until" in the "section-4" "core_availability > Section availability"
And I should see "2013" in the "section-4" "core_availability > Section availability"
And I should see "Forum 4"
And I should see "Hidden from students" in the "#section-5" "css_element"
And I should see "Forum 5"
Expand All @@ -125,7 +125,7 @@ Feature: Collapse course sections
And I should not see "Assignment 2" in the "region-main" "region"
And I should not see "Book 2" in the "region-main" "region"
And I should not see "Book 3" in the "region-main" "region"
And I should not see "Available until" in the "#section-4 .availabilityinfo" "css_element"
And I should not see "Available until" in the "section-4" "core_availability > Section availability"
And I should not see "Not available" in the "#section-5" "css_element"
And I click on "#collapssesection1" "css_element"
And I click on "#collapssesection2" "css_element"
Expand All @@ -136,8 +136,8 @@ Feature: Collapse course sections
And I should see "Assignment 2" in the "region-main" "region"
And I should see "Book 2" in the "region-main" "region"
And I should see "Book 3" in the "region-main" "region"
And I should see "Available until" in the "#section-4 .availabilityinfo" "css_element"
And I should see "2013" in the "#section-4 .availabilityinfo" "css_element"
And I should see "Available until" in the "section-4" "core_availability > Section availability"
And I should see "2013" in the "section-4" "core_availability > Section availability"
And I should see "Forum 4"
And I should see "Hidden from students" in the "#section-5" "css_element"
And I should see "Forum 5"
Expand All @@ -157,8 +157,8 @@ Feature: Collapse course sections
Then "Topic 1" "section" should not exist
And "Topic 3" "section" should not exist
And I am on "Course 1" course homepage with editing mode on
And I should see "Available until" in the "#section-4 .availabilityinfo" "css_element"
And I should see "2013" in the "#section-4 .availabilityinfo" "css_element"
And I should see "Available until" in the "section-4" "core_availability > Section availability"
And I should see "2013" in the "section-4" "core_availability > Section availability"
And I should see "Forum 4"
And I should see "Hidden from students" in the "#section-5" "css_element"
And I should see "Forum 5"
Expand All @@ -179,8 +179,8 @@ Feature: Collapse course sections
Then "1 May - 7 May" "section" should not exist
And "15 May - 21 May" "section" should not exist
And I am on the "Course 1" course page logged in as student1
And I should see "Available until" in the "#section-4 .availabilityinfo" "css_element"
And I should see "2013" in the "#section-4 .availabilityinfo" "css_element"
And I should see "Available until" in the "section-4" "core_availability > Section availability"
And I should see "2013" in the "section-4" "core_availability > Section availability"
And I should not see "Forum 4"
And I should see "Not available" in the "#section-5" "css_element"
And I should not see "Forum 5"
2 changes: 1 addition & 1 deletion lib/templates/availability_info.mustache
Expand Up @@ -52,7 +52,7 @@
}
}}
{{#text}}
<div class="availabilityinfo {{classes}}">
<div class="availabilityinfo {{classes}}" data-region="availabilityinfo">
{{^isrestricted}}
<span class="badge badge-info">{{{text}}}</span>
{{/isrestricted}}
Expand Down

0 comments on commit b9a840f

Please sign in to comment.