Skip to content

Commit

Permalink
EZEE-2306: Add new Page Builder tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Marek Nocon committed Nov 12, 2018
1 parent e2d8959 commit be655d6
Show file tree
Hide file tree
Showing 11 changed files with 171 additions and 25 deletions.
40 changes: 20 additions & 20 deletions features/ContentTypeFields.feature
Original file line number Diff line number Diff line change
Expand Up @@ -20,26 +20,26 @@ Feature: Content fields setting and editing
| Field | <value1> | <value2> | <value3> |

Examples:
| fieldInternalName | fieldName | label1 | value1 | label2 | value2 | label3 | value3 | contentItemName |
| ezselection | Selection | value | Test-value | | | | | Test-value |
| ezgmaplocation | Map location | latitude | 32 | longitude | 132 | address | Acapulco | Acapulco |
| ezauthor | Authors | name | Test Name | email | email@example.com | | | Test Name |
| ezboolean | Checkbox | value | true | | | | | 1 |
| ezobjectrelation | Content relation (single) | value | Media/Images | | | | | Images |
| ezobjectrelationlist | Content relations (multiple) | firstItem | Media/Images | secondItem | Media/Files | | | Images Files |
| ezcountry | Country | value | Poland | | | | | Poland |
| ezdate | Date | value | 11/23/2019 | | | | | Saturday 23 November 2019 |
| ezdatetime | Date and time | date | 11/23/2019 | time | 14:45 | | | Sat 2019-23-11 14:45:00 |
| ezemail | Email address | value | email@example.com | | | | | email@example.com |
| ezfloat | Float | value | 11.11 | | | | | 11.11 |
| ezisbn | ISBN | value | 978-3-16-148410-0 | | | | | 978-3-16-148410-0 |
| ezinteger | Integer | value | 1111 | | | | | 1111 |
| ezkeyword | Keywords | value | first keyword, second | | | | | first keyword, second |
| ezrichtext | Rich text | value | Lorem ipsum dolor sit | | | | | Lorem ipsum dolor sit |
| eztext | Text block | value | Lorem ipsum dolor | | | | | Lorem ipsum dolor |
| ezstring | Text line | value | Lorem ipsum | | | | | Lorem ipsum |
| eztime | Time | value | 14:45 | | | | | 2:45:00 pm |
| ezurl | URL | text | Test URL | url | http://www.google.com | | | Test URL |
| fieldInternalName | fieldName | label1 | value1 | label2 | value2 | label3 | value3 | contentItemName |
| ezselection | Selection | value | Test-value | | | | | Test-value |
| ezgmaplocation | Map location | latitude | 32 | longitude | 132 | address | Acapulco | Acapulco |
| ezauthor | Authors | name | Test Name | email | email@example.com | | | Test Name |
| ezboolean | Checkbox | value | true | | | | | 1 |
| ezobjectrelation | Content relation (single) | value | Media/Images | | | | | Images |
| ezobjectrelationlist | Content relations (multiple) | firstItem | Media/Images | secondItem | Media/Files | | | Images Files |
| ezcountry | Country | value | Poland | | | | | Poland |
| ezdate | Date | value | 11/23/2019 | | | | | Saturday 23 November 2019 |
| ezdatetime | Date and time | date | 11/23/2019 | time | 14:45 | | | Sat 2019-23-11 14:45:00 |
| ezemail | Email address | value | email@example.com | | | | | email@example.com |
| ezfloat | Float | value | 11.11 | | | | | 11.11 |
| ezisbn | ISBN | value | 978-3-16-148410-0 | | | | | 978-3-16-148410-0 |
| ezinteger | Integer | value | 1111 | | | | | 1111 |
| ezkeyword | Keywords | value | first keyword, second | | | | | first keyword, second |
| ezrichtext | Rich text | value | Lorem ipsum dolor sit | | | | | Lorem ipsum dolor sit |
| eztext | Text block | value | Lorem ipsum dolor | | | | | Lorem ipsum dolor |
| ezstring | Text line | value | Lorem ipsum | | | | | Lorem ipsum |
| eztime | Time | value | 14:45 | | | | | 2:45:00 pm |
| ezurl | URL | text | Test URL | url | http://www.google.com | | | Test URL |
| ezmedia | Media | value | video1.mp4.zip | | | | | video1.mp4 |
| ezimage | Image | value | image1.png.zip | | | | | image1.png |
| ezbinaryfile | File | value | binary1.txt.zip | | | | | binary1.txt |
Expand Down
9 changes: 9 additions & 0 deletions src/lib/Behat/BusinessContext/NotificationContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,15 @@ public function copiedToRootAppears(string $content): void
$this->specificNotificationAppears($expectedMessage);
}

/**
* @Then success notification that :locationName has been moved to trash appears
*/
public function locationMovedToTrash(string $locationName): void
{
$expectedMessage = sprintf("Location '%s' moved to trash.", $locationName);
$this->specificNotificationAppears($expectedMessage);
}

/**
* @Then error notification that :message appears
*/
Expand Down
28 changes: 27 additions & 1 deletion src/lib/Behat/Helper/UtilityContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ function () use ($selector, $baseElement) {
return $baseElement->find('css', $selector);
});
} catch (Exception $e) {
throw new ElementNotFoundException($this->getSession()->getDriver());
throw new ElementNotFoundException($this->getSession()->getDriver(), null, 'css', $selector);
}
}

Expand Down Expand Up @@ -291,4 +291,30 @@ public function uploadFileToRemoteSpace(string $localFileName): string
'file' => base64_encode(file_get_contents($localFile)),
]);
}

private function isDraggingLibraryLoaded(): bool
{
return $this->getSession()->getDriver()->evaluateScript("typeof(dragMock) !== 'undefined'");
}

public function moveWithHover(string $startExpression, string $hoverExpression, string $placeholderExpression): void
{
$this->loadDraggingLibrary();

$movingScript = sprintf('dragMock.dragStart(%s).dragOver(%s).delay(100).drop(%s);', $startExpression, $hoverExpression, $placeholderExpression);
$this->getSession()->getDriver()->executeScript($movingScript);
}

private function loadDraggingLibrary(): void
{
if ($this->isDraggingLibraryLoaded()) {
return;
}

$script = file_get_contents(__DIR__ . '/../lib/drag-mock.js');
$this->getSession()->getDriver()->executeScript($script);
$this->waitUntil(10, function () {
return $this->isDraggingLibraryLoaded();
});
}
}
5 changes: 3 additions & 2 deletions src/lib/Behat/PageElement/DateAndTimePopup.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@ class DateAndTimePopup extends Element

private const DATETIME_FORMAT = 'm/d/Y, g:i:s a';

public function __construct(UtilityContext $context, bool $isInline = false)
public function __construct(UtilityContext $context, bool $isInline = false, $containerSelector = '')
{
parent::__construct($context);
$calendarSelector = $isInline ? '.flatpickr-calendar.inline' : '.flatpickr-calendar.open';
$this->fields = [
'openedCalendar' => $calendarSelector,
'openedCalendar' => sprintf('%s %s', $containerSelector, $calendarSelector),
'pickerDaySelector' => '.flatpickr-day:not(.prevMonthDay):not(.nextMonthDay)',
'pickerDayValue' => 'aria-label',
'hourSelector' => '.flatpickr-hour',
Expand All @@ -43,6 +43,7 @@ public function setDate(DateTime $date, string $dateFormat = self::DATETIME_FORM
} else {
$referenceDateElement = $this->context->findElement(sprintf('%s %s', $this->fields['openedCalendar'], $this->fields['selectedDaySelector']));
}

$currentDate = DateTime::createFromFormat($dateFormat, $referenceDateElement->getAttribute($this->fields['pickerDayValue']));

$dateToDiff = $this->deleteDayFromDate($date);
Expand Down
10 changes: 9 additions & 1 deletion src/lib/Behat/PageElement/ElementFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,20 @@ public static function setInstallType(int $installType)
self::$installType = $installType;
}

public static function getPreviewType(string $contentType)
{
/* Note: no return type to enable type-hinting */
$factory = self::getFactory(self::$installType);

return $factory::getPreviewType($contentType);
}

/**
* @param int $installType
*
* @return EnterpriseElementFactory|PlatformElementFactory
*/
private static function getFactory(int $installType): ElementFactory
private static function getFactory(int $installType): PlatformElementFactory
{
switch ($installType) {
case InstallType::PLATFORM:
Expand Down
14 changes: 13 additions & 1 deletion src/lib/Behat/PageElement/PlatformElementFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,11 @@ public static function createElement(UtilityContext $context, string $elementNam
return new DateAndTimePopup($context);
}

return new DateAndTimePopup($context, $parameters[0]);
if (!array_key_exists(1, $parameters)) {
return new DateAndTimePopup($context, $parameters[0]);
}

return new DateAndTimePopup($context, $parameters[0], $parameters[1]);
case ContentTypePicker::ELEMENT_NAME:
return new ContentTypePicker($context);
case UniversalDiscoveryWidget::ELEMENT_NAME:
Expand All @@ -170,4 +174,12 @@ public static function createElement(UtilityContext $context, string $elementNam
throw new \InvalidArgumentException(sprintf('Unrecognized element name: %s', $elementName));
}
}

public static function getPreviewType(string $elementName)
{
switch ($elementName) {
default:
throw new \InvalidArgumentException(sprintf('Unrecognized preview for element name: %s', $elementName));
}
}
}
25 changes: 25 additions & 0 deletions src/lib/Behat/PageObject/FolderPreview.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php

/**
* @copyright Copyright (C) eZ Systems AS. All rights reserved.
* @license For full copyright and license information view LICENSE file distributed with this source code.
*/
namespace EzSystems\EzPlatformAdminUi\Behat\PageObject;

class FolderPreview extends PreviewPage
{
/** @var string Name by which Page is recognised */
public const PAGE_NAME = 'Folder Preview';

/** @var string Name of Content Type this Preview is for */
public const CONTENT_TYPE = 'Folder';

public function getPageTitle(): string
{
return $this->context->findElement('h2')->getText();
}

public function verifyElements(): void
{
}
}
8 changes: 8 additions & 0 deletions src/lib/Behat/PageObject/PageObjectFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,14 @@ public static function setInstallType(int $installType)
self::$installType = $installType;
}

public static function getPreviewType(string $contentType)
{
/* Note: no return type to enable type-hinting */
$factory = self::getFactory(self::$installType);

return $factory::getPreviewType($contentType);
}

/**
* @param int $installType
*
Expand Down
12 changes: 12 additions & 0 deletions src/lib/Behat/PageObject/PlatformPageObjectFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,20 @@ public static function createPage(UtilityContext $context, string $pageName, ?st
return new ContentPreviewPage($context, $parameters[0]);
case TrashPage::PAGE_NAME:
return new TrashPage($context);
case FolderPreview::PAGE_NAME:
return new FolderPreview($context);
default:
throw new \InvalidArgumentException(sprintf('Unrecognised page name: %s', $pageName));
}
}

public static function getPreviewType(string $contentType): string
{
switch ($contentType) {
case FolderPreview::CONTENT_TYPE:
return FolderPreview::PAGE_NAME;
default:
throw new \InvalidArgumentException(sprintf('Unrecognised preview for content type: %s', $contentType));
}
}
}
15 changes: 15 additions & 0 deletions src/lib/Behat/PageObject/PreviewPage.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php

/**
* @copyright Copyright (C) eZ Systems AS. All rights reserved.
* @license For full copyright and license information view LICENSE file distributed with this source code.
*/
namespace EzSystems\EzPlatformAdminUi\Behat\PageObject;

abstract class PreviewPage extends Page
{
public function setTitle(string $title): void
{
$this->pageTitle = $title;
}
}
Loading

0 comments on commit be655d6

Please sign in to comment.