ResponsivePreview.php in Thunder 6.2.x
File
tests/src/FunctionalJavascript/Integration/ResponsivePreview.php
View source
<?php
namespace Drupal\Tests\thunder\FunctionalJavascript\Integration;
use Drupal\Tests\thunder\FunctionalJavascript\ThunderJavascriptTestBase;
class ResponsivePreview extends ThunderJavascriptTestBase {
public function testDevicePreview() {
$assert_session = $this
->assertSession();
$session = $this
->getSession();
$this
->drupalGet('news');
$this
->selectDevice('(//*[@id="responsive-preview-toolbar-tab"]//button[@data-responsive-preview-name])[1]');
$assert_session
->elementNotExists('xpath', '//*[@id="responsive-preview-orientation" and contains(@class, "rotated")]');
$this
->assertTrue($session
->evaluateScript("jQuery('#responsive-preview-frame')[0].contentWindow.location.href.endsWith('/news')"));
$current_width = $session
->evaluateScript("jQuery('#responsive-preview-frame').width()");
$current_height = $session
->evaluateScript("jQuery('#responsive-preview-frame').height()");
$this
->changeDeviceRotation();
$assert_session
->elementExists('xpath', '//*[@id="responsive-preview-orientation" and contains(@class, "rotated")]');
$this
->assertEquals($current_height, $session
->evaluateScript("jQuery('#responsive-preview-frame').width()"));
$this
->assertEquals($current_width, $session
->evaluateScript("jQuery('#responsive-preview-frame').height()"));
$this
->selectDevice('(//*[@id="responsive-preview-toolbar-tab"]//button[@data-responsive-preview-name])[last()]');
$assert_session
->elementExists('xpath', '//*[@id="responsive-preview-orientation" and contains(@class, "rotated")]');
$this
->changeDeviceRotation();
$assert_session
->elementNotExists('xpath', '//*[@id="responsive-preview-orientation" and contains(@class, "rotated")]');
$this
->getSession()
->getPage()
->find('xpath', '//*[@id="responsive-preview-close"]')
->click();
$this
->getSession()
->wait(5000, "jQuery('#responsive-preview').length === 0");
$assert_session
->elementNotExists('xpath', '//*[@id="responsive-preview"]');
$node = $this
->loadNodeByUuid('bbb1ee17-15f8-46bd-9df5-21c58040d741');
$this
->drupalGet($node
->toUrl('edit-form'));
$this
->selectDevice('(//*[@id="responsive-preview-toolbar-tab"]//button[@data-responsive-preview-name])[1]');
$this
->assertNotEquals(-1, $session
->evaluateScript("jQuery('#responsive-preview-frame')[0].contentWindow.location.href.indexOf('/node/preview/')"));
$this
->changeDeviceRotation();
$this
->selectDevice('(//*[@id="responsive-preview-toolbar-tab"]//button[@data-responsive-preview-name])[1]');
$this
->getSession()
->wait(5000, "jQuery('#responsive-preview').length === 0");
$assert_session
->elementNotExists('xpath', '//*[@id="responsive-preview"]');
}
protected function changeDeviceRotation() {
$this
->getSession()
->getPage()
->find('xpath', '//*[@id="responsive-preview-orientation"]')
->click();
$this
->assertWaitOnAjaxRequest();
}
protected function selectDevice($xpath_device_button) {
$page = $this
->getSession()
->getPage();
$page
->find('xpath', '//*[@id="responsive-preview-toolbar-tab"]/button')
->click();
$this
->assertWaitOnAjaxRequest();
$page
->find('xpath', $xpath_device_button)
->click();
$this
->assertWaitOnAjaxRequest();
}
}