Commit dad1fd4b authored by topicus's avatar topicus

Merge pull request #537 from NuCivic/670_data_dashboard_tests

NuCivic/internal#670: Added tests for Data Dashboards.
parents aa7a5545 aac37248
......@@ -60,6 +60,7 @@ script:
- bin/behat features/search.feature
- bin/behat features/recline.feature
- bin/behat features/widgets.feature
- bin/behat features/data_dashboard.feature
notifications:
slack:
......
......@@ -9,8 +9,11 @@ default:
files_path: "files"
Drupal\DrupalExtension\Extension:
blackbox: ~
drupal:
drupal_root: "drupal"
drush:
root: "drupal"
api_driver: "drupal"
region_map:
content: ".region-content"
toolbar: ".tabs--primary"
......@@ -20,3 +23,4 @@ default:
left header: "#header-left"
right header: "#header-right"
right sidebar: "#column-right"
dashboards: ".view-data-dashboards table tbody"
......@@ -2,12 +2,16 @@
use Drupal\DrupalExtension\Context\DrupalContext;
use Behat\Behat\Context\Step\Given;
use Behat\Behat\Context\BehatContext;
use Symfony\Component\Process\Process;
use Behat\Gherkin\Node\TableNode;
require 'vendor/autoload.php';
class FeatureContext extends DrupalContext
{
// Keep track of created data dashboards so they can be cleaned up.
protected $data_dashboards = array();
/**
* @Given /^I scroll to the top$/
......@@ -252,4 +256,53 @@ class FeatureContext extends DrupalContext
$element = $session->getPage();
return $element->findLink($this->getDrupalText('log_out'));
}
/************************************/
/* DATA DASHBOARDS */
/************************************/
/**
* @Given data_dashboards:
*/
public function addDataDashboard(TableNode $data_dashboards_table) {
// Map readable field names to drupal field names.
$field_map = array(
'title' => 'title',
);
foreach ($data_dashboards_table->getHash() as $data_dashboards_hash) {
$node = new stdClass();
$node->type = 'data_dashboard';
foreach($data_dashboards_hash as $field => $value) {
if(isset($field_map[$field])) {
$drupal_field = $field_map[$field];
$node->$drupal_field = $value;
}
else {
throw new Exception(sprintf("Data Dashboard field %s doesn't exist, or hasn't been mapped. See FeatureContext::addDataDashboard for mappings.", $field));
}
}
$created_node = $this->getDriver()->createNode($node);
// Add the created node to the data dashboards array.
$this->data_dashboards[$created_node->nid] = $created_node;
}
}
/**
* Clean up generated content.
*/
public function afterScenario($event) {
parent::afterScenario($event);
if (!empty($this->data_dashboards)) {
foreach ($this->data_dashboards as $data_dashboard_id => $data_dashboard) {
$this->getDriver()->nodeDelete($data_dashboard);
}
}
}
}
Feature: Data Dashboard
Background:
Given data_dashboards:
| title |
| Dashboard 01 |
| Dashboard 02 |
@api
Scenario: See the list of data dashboards
Given I am logged in as a user with the "administrator" role
When I am on "admin/dkan/data-dashboards"
Then I should see the text "Dashboard 01" in the "dashboards" region
And I should see the text "Dashboard 02" in the "dashboards" region
@api
Scenario: Creation of data dashboard
Given I am logged in as a user with the "administrator" role
And I am on "admin/dkan/data-dashboards"
And I click "Create Dashboard"
Then I should see "Create Data Dashboard"
When I fill in "title" with "My new dashboard"
And I select the radio button "Radix Boxton" with the id "edit-layout-radix-boxton"
And I press "Save"
Then I should see "Your Data Dashboard 'My new dashboard' has been created"
And I should see "Start adding content by clicking on the + sign on each panel"
@api
Scenario: Edition of data dashboard
Given I am logged in as a user with the "administrator" role
And I am on "/dashboard-01"
When I click "Edit"
And I fill in "title" with "Edited Dashboard"
And I press "Save"
Then I should see "Data Dashboard Edited Dashboard has been updated"
When I am on "admin/dkan/data-dashboards"
Then I should see the text "Edited Dashboard" in the "dashboards" region
And I should not see the text "Dashboard 01" in the "dashboards" region
@api
Scenario: Deletion of data dashboard
Given I am logged in as a user with the "administrator" role
And I am on "/dashboard-01"
When I click "Edit"
And I press "Delete"
Then I should see "Are you sure you want to delete Dashboard 01?"
When I press "Delete"
Then I should see "Data Dashboard Dashboard 01 has been deleted"
When I am on "admin/dkan/data-dashboards"
Then I should not see the text "Dashboard 01" in the "dashboards" region
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment