Issue #46 - Added behat scenarios to test manage page.

This commit is contained in:
Daniel Thee Roperto
2016-09-25 18:41:51 +10:00
parent b7a4aa4a9a
commit a49693b7d2
2 changed files with 124 additions and 6 deletions

View File

@@ -25,8 +25,11 @@
// NOTE: no MOODLE_INTERNAL test here, this file may be required by behat before including /config.php.
use auth_outage\dml\outagedb;
use auth_outage\local\outage;
use Behat\Behat\Tester\Exception\PendingException;
use Behat\Gherkin\Node\TableNode;
use Behat\Mink\Exception\ElementNotFoundException;
use Behat\Mink\Exception\ExpectationException;
require_once(__DIR__.'/../../../../lib/behat/behat_base.php');
@@ -69,4 +72,72 @@ class behat_auth_outage extends behat_base {
public function i_visit_the_create_outage_page() {
$this->getSession()->visit($this->locate_path('/auth/outage/new.php'));
}
/**
* @Given there is a :type outage
*/
public function there_is_a_outage($type) {
$data = [
'autostart' => false,
'finished' => null,
'title' => 'Example of '.$type.' outage',
'description' => 'An outage: '.$type,
];
switch ($type) {
case 'waiting':
$data['starttime'] = time() + (60 * 60 * 24 * 7); // Starts in 1 week.
$data['warntime'] = $data['starttime'] - 60;
$data['stoptime'] = $data['starttime'] + 120;
break;
case 'warning':
$data['starttime'] = time() + (60 * 60); // Starts in 1 hour.
$data['warntime'] = $data['starttime'] - (60 * 60 * 2); // Warns before 2 hours.
$data['stoptime'] = $data['starttime'] + (60 * 60 * 24 * 7); // Ends after 1 week.
break;
case 'ongoing':
$data['starttime'] = time() - (60 * 60); // Started 1 hour ago.
$data['warntime'] = $data['starttime'] - 60;
$data['stoptime'] = $data['starttime'] + (60 * 60 * 24 * 7); // Ends after 1 week.
break;
case 'finished':
$data['starttime'] = time() - (60 * 60); // Started 1 hour ago.
$data['warntime'] = $data['starttime'] - 60;
$data['finished'] = time() - 60; // Finished 1 minute ago.
$data['stoptime'] = $data['starttime'] + (60 * 60 * 24 * 7); // Ends after 1 week.
break;
case 'stopped':
$data['starttime'] = time() - (60 * 60 * 2); // Started 2 hour ago.
$data['warntime'] = $data['starttime'] - 60;
$data['stoptime'] = time() - (60 * 60 * 2); // Stopped 1 hour ago.
break;
default:
throw new InvalidArgumentException('$type='.$type.' is not valid.');
}
outagedb::save(new outage($data));
}
/**
* @Then I should see the action :action
*/
public function i_should_see_the_action($action) {
if (!$this->can_i_see_action($action)) {
throw new ExpectationException('"'.$action.'" action was not found', $this->getSession());
}
}
/**
* @Then I should not see the action :action
*/
public function iShouldNotSeeTheAction($action) {
if ($this->can_i_see_action($action)) {
throw new ExpectationException('"'.$action.'" action was found', $this->getSession());
}
}
private function can_i_see_action($action) {
$selector = 'css';
$locator = "div[role='main'] a[title='${action}']";
$items = $this->getSession()->getPage()->findAll($selector, $locator);
return (count($items) > 0);
}
}

View File

@@ -1,20 +1,67 @@
@auth @auth_outage @javascript
@dev @auth @auth_outage @javascript
Feature: Test the outage management functionality.
In order to check if I can manage outages
As an admin
I need to create, edit, delete, clone and finish an outage.
Outage stage terminology:
- waiting is an outage in the future, not yet in the warning period.
- warning is an outage in the future but already in the warning period.
- ongoing is an outage that has started, but not yet reached the stop time nor is marked as finished.
- finished is an outage that has explicitly been marked as finished.
- stopped is an outage that has already ended but not explicitly marked as finished.
Background: Always login as admin, enable the auth_outage plugin and go to the outage management page.
Given The authentication plugin "outage" is enabled
Given the authentication plugin "outage" is enabled
And I log in as "admin"
Scenario: Check if I can navigate to management page.
Given I am on homepage
When I navigate to "Manage" node in "Site administration > Plugins > Authentication > Outage manager"
Then I should see "Create Outage"
Then I should see "Planned outages"
Then I should see "Outage history"
And I should see "No outages found." in the "#section_planned_outages" "css_element"
And I should see "Outage history"
And I should see "No outages found." in the "#section_outage_history" "css_element"
Scenario: Check if creating outages uses the configured defaults.
Scenario Outline: Planned outages should include all outages not finished or stopped.
Given there is a <type> outage
When I am on Outage Management Page
Then I should see "Example of <type> outage" in the "#section_<section>" "css_element"
Examples:
| type | section |
| waiting | planned_outages |
| warning | planned_outages |
| ongoing | planned_outages |
| finished | outage_history |
| stopped | outage_history |
Scenario Outline: Planned and history outages have different actions.
Given there is a <type> outage
When I am on Outage Management Page
Then I should see "Example of <type> outage"
And I should <view> the action "View"
And I should <clone> the action "Clone"
And I should <edit> the action "Edit"
And I should <delete> the action "Delete"
And I should <finish> the action "Finish"
Examples:
| type | view | clone | edit | delete | finish |
| waiting | see | see | see | see | not see |
| warning | see | see | see | see | not see |
| ongoing | see | see | see | see | see |
| finished | see | see | not see | not see | not see |
| stopped | see | see | not see | not see | not see |
Scenario: Create an outage using defaults.
Given I am on Outage Management Page
When I click on "([^"]|\"*)" "<string>"
When I press "Create Outage"
And I press "Save changes"
And I should not see "No outages found." in the "#section_planned_outages" "css_element"
And I should see "No outages found." in the "#section_outage_history" "css_element"