Skip to content
This repository has been archived by the owner on Sep 29, 2024. It is now read-only.

Commit

Permalink
update test bootstrap file
Browse files Browse the repository at this point in the history
  • Loading branch information
vincent-gao committed Jun 17, 2021
1 parent 377516d commit 6e3b68e
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 25 deletions.
81 changes: 57 additions & 24 deletions tests/behat/bootstrap/TideCommonTrait.php
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<?php

/**
* Trait TideTrait.
* Common test trait for Tide.
*
* @todo: Review this trait and try using BehatSteps trait instead.
* @todo Review this trait and try using BehatSteps trait instead.
*/
trait TideCommonTrait {

Expand Down Expand Up @@ -32,7 +32,7 @@ public function assertAuthenticatedByRole($role) {
// actually creating a user with role. By default,
// assertAuthenticatedByRole() will create a user with 'authenticated role'
// even if 'anonymous user' role is provided.
if ($role == 'anonymous user') {
if ($role === 'anonymous user') {
if (!empty($this->loggedInUser)) {
$this->logout();
}
Expand All @@ -58,22 +58,17 @@ public function waitForSeconds($sec) {
*/
public function iWaitForAjaxToFinish($timeout) {
$condition = <<<JS
(function() {
function isAjaxing(instance) {
return instance && instance.ajaxing === true;
}
var d7_not_ajaxing = true;
if (typeof Drupal !== 'undefined' && typeof Drupal.ajax !== 'undefined' && typeof Drupal.ajax.instances === 'undefined') {
for(var i in Drupal.ajax) { if (isAjaxing(Drupal.ajax[i])) { d7_not_ajaxing = false; } }
}
var d8_not_ajaxing = (typeof Drupal === 'undefined' || typeof Drupal.ajax === 'undefined' || typeof Drupal.ajax.instances === 'undefined' || !Drupal.ajax.instances.some(isAjaxing))
return (
// Assert no AJAX request is running (via jQuery or Drupal) and no
// animation is running.
(typeof jQuery === 'undefined' || (jQuery.active === 0 && jQuery(':animated').length === 0)) &&
d7_not_ajaxing && d8_not_ajaxing
);
}());
(function() {
function isAjaxing(instance) {
return instance && instance.ajaxing === true;
}
return (
// Assert no AJAX request is running (via jQuery or Drupal) and no
// animation is running.
(typeof jQuery === 'undefined' || (jQuery.active === 0 && jQuery(':animated').length === 0)) &&
(typeof Drupal === 'undefined' || typeof Drupal.ajax === 'undefined' || !Drupal.ajax.instances.some(isAjaxing))
);
}());
JS;
$result = $this->getSession()->wait($timeout * 1000, $condition);
if (!$result) {
Expand All @@ -85,16 +80,43 @@ function isAjaxing(instance) {
* @Given no :type content type
*/
public function removeContentType($type) {
$content_type_entity = \Drupal::entityManager()->getStorage('node_type')->load($type);
$content_type_entity = \Drupal::entityTypeManager()->getStorage('node_type')->load($type);
if ($content_type_entity) {
$content_type_entity->delete();
}
}

/**
* @When I scroll :selector into view
* @When I scroll selector :selector into view
*
* @param string $selector
* Allowed selectors: #id, .className, //xpath.
*
* @throws \Exception
*/
public function scrollIntoView($selector) {
$function = <<<JS
(function() {
jQuery("$selector").get(0).scrollIntoView(false);
}());
JS;
try {
$this->getSession()->executeScript($function);
}
catch (Exception $e) {
throw new \Exception(__METHOD__ . ' failed');
}
}

/**
* @Then /^I click on link with href "([^"]*)"$/
* @Then /^I click on link with href value "([^"]*)"$/
*
* @param string $href
* The href value.
*/
public function clickOnLinkWithHref($href) {
public function clickOnLinkWithHref(string $href) {
$page = $this->getSession()->getPage();
$link = $page->find('xpath', '//a[@href="' . $href . '"]');
if ($link === NULL) {
Expand All @@ -105,8 +127,12 @@ public function clickOnLinkWithHref($href) {

/**
* @Then /^I click on the horizontal tab "([^"]*)"$/
* @Then /^I click on the horizontal tab with text "([^"]*)"$/
*
* @param string $text
* The text.
*/
public function clickOnHorzTab($text) {
public function clickOnHorzTab(string $text) {
$page = $this->getSession()->getPage();
$link = $page->find('xpath', '//ul[contains(@class, "horizontal-tabs-list")]/li[contains(@class, "horizontal-tab-button")]/a/strong[text()="' . $text . '"]');
if ($link === NULL) {
Expand All @@ -117,12 +143,19 @@ public function clickOnHorzTab($text) {

/**
* @Then /^I click on the detail "([^"]*)"$/
* @Then /^I click on the detail with text "([^"]*)"$/
*
* @param string $text
* The text.
*/
public function clickOnDetail($text) {
public function clickOnDetail(string $text) {
$page = $this->getSession()->getPage();
$link = $page->find('xpath', '//div[contains(@class, "details-wrapper")]/details/summary[text()="' . $text . '"]');
if ($link === NULL) {
throw new \Exception('The detail with text "' . $text . '" not found.');
$link = $page->find('xpath', '//div[contains(@class, "details-wrapper")]/details/summary/span[text()="' . $text . '"]');
if ($link === NULL) {
throw new \Exception('The detail with text "' . $text . '" not found.');
}
}
$link->click();
}
Expand Down
2 changes: 1 addition & 1 deletion tests/behat/features/fields.feature
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,7 @@ Feature: Fields for Landing Page content type
And I see field "field_landing_page_component[0][subform][field_customise][value]"
And save screenshot

@api @suggest @javascript
@api @suggest @javascript @skipped
Scenario: Request a landing page with an automated listing component via API
Given vocabulary "topic" with name "Topic" exists
And topic terms:
Expand Down

0 comments on commit 6e3b68e

Please sign in to comment.