From e14c62ed3a9b324f5a19a5522a7636bf8a730d97 Mon Sep 17 00:00:00 2001 From: Marek Nocon Date: Fri, 26 Oct 2018 18:21:24 +0200 Subject: [PATCH] EZEE-2306: Add new Page Builder tests --- features/ContentTypeFields.feature | 40 +++++++++---------- src/lib/Behat/Helper/UtilityContext.php | 28 ++++++++++++- .../Behat/PageElement/DateAndTimePopup.php | 5 ++- src/lib/Behat/PageElement/ElementFactory.php | 10 ++++- .../PageElement/PlatformElementFactory.php | 14 ++++++- src/lib/Behat/PageObject/FolderPreview.php | 25 ++++++++++++ .../Behat/PageObject/PageObjectFactory.php | 8 ++++ .../PageObject/PlatformPageObjectFactory.php | 12 ++++++ src/lib/Behat/PageObject/PreviewPage.php | 15 +++++++ src/lib/Behat/lib/drag-mock.js | 30 ++++++++++++++ 10 files changed, 162 insertions(+), 25 deletions(-) create mode 100644 src/lib/Behat/PageObject/FolderPreview.php create mode 100644 src/lib/Behat/PageObject/PreviewPage.php create mode 100644 src/lib/Behat/lib/drag-mock.js diff --git a/features/ContentTypeFields.feature b/features/ContentTypeFields.feature index e94b7663b0..233f29d871 100644 --- a/features/ContentTypeFields.feature +++ b/features/ContentTypeFields.feature @@ -20,26 +20,26 @@ Feature: Content fields setting and editing | Field | | | | 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 | diff --git a/src/lib/Behat/Helper/UtilityContext.php b/src/lib/Behat/Helper/UtilityContext.php index 95429a293a..00ac83e2c4 100644 --- a/src/lib/Behat/Helper/UtilityContext.php +++ b/src/lib/Behat/Helper/UtilityContext.php @@ -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); } } @@ -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(); + }); + } } diff --git a/src/lib/Behat/PageElement/DateAndTimePopup.php b/src/lib/Behat/PageElement/DateAndTimePopup.php index 534ad476da..247f8954fa 100644 --- a/src/lib/Behat/PageElement/DateAndTimePopup.php +++ b/src/lib/Behat/PageElement/DateAndTimePopup.php @@ -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', @@ -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); diff --git a/src/lib/Behat/PageElement/ElementFactory.php b/src/lib/Behat/PageElement/ElementFactory.php index 238d4039c9..46c3aacf2e 100644 --- a/src/lib/Behat/PageElement/ElementFactory.php +++ b/src/lib/Behat/PageElement/ElementFactory.php @@ -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: diff --git a/src/lib/Behat/PageElement/PlatformElementFactory.php b/src/lib/Behat/PageElement/PlatformElementFactory.php index ffb510c24f..de1a343b3d 100644 --- a/src/lib/Behat/PageElement/PlatformElementFactory.php +++ b/src/lib/Behat/PageElement/PlatformElementFactory.php @@ -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: @@ -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)); + } + } } diff --git a/src/lib/Behat/PageObject/FolderPreview.php b/src/lib/Behat/PageObject/FolderPreview.php new file mode 100644 index 0000000000..e114862b6d --- /dev/null +++ b/src/lib/Behat/PageObject/FolderPreview.php @@ -0,0 +1,25 @@ +context->findElement('h2')->getText(); + } + + public function verifyElements(): void + { + } +} diff --git a/src/lib/Behat/PageObject/PageObjectFactory.php b/src/lib/Behat/PageObject/PageObjectFactory.php index 55ea29af0c..af8b3b41c8 100644 --- a/src/lib/Behat/PageObject/PageObjectFactory.php +++ b/src/lib/Behat/PageObject/PageObjectFactory.php @@ -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 * diff --git a/src/lib/Behat/PageObject/PlatformPageObjectFactory.php b/src/lib/Behat/PageObject/PlatformPageObjectFactory.php index d9866f48c0..86fb499c13 100644 --- a/src/lib/Behat/PageObject/PlatformPageObjectFactory.php +++ b/src/lib/Behat/PageObject/PlatformPageObjectFactory.php @@ -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)); + } + } } diff --git a/src/lib/Behat/PageObject/PreviewPage.php b/src/lib/Behat/PageObject/PreviewPage.php new file mode 100644 index 0000000000..6a6b8b4176 --- /dev/null +++ b/src/lib/Behat/PageObject/PreviewPage.php @@ -0,0 +1,15 @@ +pageTitle = $title; + } +} diff --git a/src/lib/Behat/lib/drag-mock.js b/src/lib/Behat/lib/drag-mock.js new file mode 100644 index 0000000000..f427c68934 --- /dev/null +++ b/src/lib/Behat/lib/drag-mock.js @@ -0,0 +1,30 @@ +/* drag-mock library +https://github.com/andywer/drag-mock +version 1.4.0 + +The MIT License (MIT) + +Copyright (c) 2015 Andy Wermke + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. + +*/ + + +!function t(e,n,r){function a(i,u){if(!n[i]){if(!e[i]){var s="function"==typeof require&&require;if(!u&&s)return s(i,!0);if(o)return o(i,!0);var c=new Error("Cannot find module '"+i+"'");throw c.code="MODULE_NOT_FOUND",c}var f=n[i]={exports:{}};e[i][0].call(f.exports,function(t){var n=e[i][1][t];return a(n?n:t)},f,f.exports,t,e,n,r)}return n[i].exports}for(var o="function"==typeof require&&require,i=0;i=0&&t.splice(n,1)}var r=function(){this.dataByFormat={},this.dropEffect="none",this.effectAllowed="all",this.files=[],this.types=[]};r.prototype.clearData=function(t){t?(delete this.dataByFormat[t],n(this.types,t)):(this.dataByFormat={},this.types=[])},r.prototype.getData=function(t){return this.dataByFormat[t]},r.prototype.setData=function(t,e){return this.dataByFormat[t]=e,this.types.indexOf(t)<0&&this.types.push(t),!0},r.prototype.setDragImage=function(){},e.exports=r},{}],3:[function(t,e){function n(){}function r(t,e,r){if("function"==typeof e&&(r=e,e=null),!t||"object"!=typeof t)throw new Error("Expected first parameter to be a targetElement. Instead got: "+t);return{targetElement:t,eventProperties:e||{},configCallback:r||n}}function a(t,e,n){e&&(e.length<2?n&&e(t):e(t,t.type))}function o(t,e,n,r,o,u){e.forEach(function(e){var s=i.createEvent(e,o,r),c=e===n;a(s,u,c),t.dispatchEvent(s)})}var i=t("./eventFactory"),u=t("./DataTransfer"),s=function(){this.lastDragSource=null,this.lastDataTransfer=null,this.pendingActionsQueue=[]};s.prototype._queue=function(t){this.pendingActionsQueue.push(t),1===this.pendingActionsQueue.length&&this._queueExecuteNext()},s.prototype._queueExecuteNext=function(){if(0!==this.pendingActionsQueue.length){var t=this,e=this.pendingActionsQueue[0],n=function(){t.pendingActionsQueue.shift(),t._queueExecuteNext()};0===e.length?(e.call(this),n()):e.call(this,n)}},s.prototype.dragStart=function(t,e,n){var a=r(t,e,n),i=["mousedown","dragstart","drag"],s=new u;return this._queue(function(){o(a.targetElement,i,"drag",s,a.eventProperties,a.configCallback),this.lastDragSource=t,this.lastDataTransfer=s}),this},s.prototype.dragOver=function(t,e,n){var a=r(t,e,n),i=["mousemove","mouseover","dragover"];return this._queue(function(){o(a.targetElement,i,"drag",this.lastDataTransfer,a.eventProperties,a.configCallback)}),this},s.prototype.dragLeave=function(t,e,n){var a=r(t,e,n),i=["mousemove","mouseover","dragleave"];return this._queue(function(){o(a.targetElement,i,"dragleave",this.lastDataTransfer,a.eventProperties,a.configCallback)}),this},s.prototype.drop=function(t,e,n){var a=r(t,e,n),i=["mousemove","mouseup","drop"],u=["dragend"];return this._queue(function(){o(a.targetElement,i,"drop",this.lastDataTransfer,a.eventProperties,a.configCallback),this.lastDragSource&&o(this.lastDragSource,u,"drop",this.lastDataTransfer,a.eventProperties,a.configCallback)}),this},s.prototype.then=function(t){return this._queue(function(){t.call(this)}),this},s.prototype.delay=function(t){return this._queue(function(e){window.setTimeout(e,t)}),this},e.exports=s},{"./DataTransfer":2,"./eventFactory":4}],4:[function(t,e){function n(t,e){for(var n in e)e.hasOwnProperty(n)&&(t[n]=e[n]);return t}function r(t,e,r){"DragEvent"===e&&(e="CustomEvent");var a=window[e],o={view:window,bubbles:!0,cancelable:!0};n(o,r);var i=new a(t,o);return n(i,r),i}function a(t,e,r){var a;switch(e){case"MouseEvent":a=document.createEvent("MouseEvent"),a.initEvent(t,!0,!0);break;default:a=document.createEvent("CustomEvent"),a.initCustomEvent(t,!0,!0,0)}return r&&n(a,r),a}function o(t,e,n){try{return r(t,e,n)}catch(o){return a(t,e,n)}}var i=t("./DataTransfer"),u=["drag","dragstart","dragover","dragend","drop","dragleave"],s={createEvent:function(t,e,n){var r="CustomEvent";t.match(/^mouse/)&&(r="MouseEvent");var a=o(t,r,e);return u.indexOf(t)>-1&&(a.dataTransfer=n||new i),a}};e.exports=s},{"./DataTransfer":2}],5:[function(t,e){function n(t,e,n){return t[e].apply(t,n)}var r=t("./DragDropAction"),a={dragStart:function(){return n(new r,"dragStart",arguments)},dragOver:function(){return n(new r,"dragOver",arguments)},dragLeave:function(){return n(new r,"dragLeave",arguments)},drop:function(){return n(new r,"drop",arguments)},delay:function(){return n(new r,"delay",arguments)},DataTransfer:t("./DataTransfer"),DragDropAction:t("./DragDropAction"),eventFactory:t("./eventFactory")};e.exports=a},{"./DataTransfer":2,"./DragDropAction":3,"./eventFactory":4}]},{},[1]); \ No newline at end of file