Skip to content

Commit

Permalink
Update test; improve test file
Browse files Browse the repository at this point in the history
  • Loading branch information
uuf6429 committed Jul 9, 2023
1 parent 93d4eaf commit 7453900
Showing 1 changed file with 33 additions and 12 deletions.
45 changes: 33 additions & 12 deletions tests/Js/WindowTest.php
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
<?php

/**
* @noinspection PhpUnhandledExceptionInspection
* @noinspection PhpRedundantOptionalArgumentInspection
*/

namespace Behat\Mink\Tests\Driver\Js;

use Behat\Mink\Tests\Driver\TestCase;

final class WindowTest extends TestCase
{
public function testWindow()
public function testWindow(): void
{
$this->getSession()->visit($this->pathTo('/window.html'));
$session = $this->getSession();
Expand Down Expand Up @@ -47,7 +52,7 @@ public function testWindowName(): void
$this->assertContains($windowName, $windowNames, 'The current window name should be one of the available window names.');
}

public function testGetWindowNames()
public function testGetWindowNames(): void
{
$this->getSession()->visit($this->pathTo('/window.html'));
$session = $this->getSession();
Expand All @@ -67,7 +72,7 @@ public function testGetWindowNames()
$this->assertNotNull($windowNames[2]);
}

public function testResizeWindow()
public function testResizeWindow(): void
{
$this->getSession()->visit($this->pathTo('/index.html'));
$session = $this->getSession();
Expand All @@ -94,17 +99,33 @@ public function testResizeWindow()
$this->assertTrue($session->evaluateScript($jsWindowSizeScript));
}

public function testWindowMaximize()
public function testWindowMaximize(): void
{
$this->getSession()->visit($this->pathTo('/index.html'));
$session = $this->getSession();

$session->maximizeWindow();
$session->wait(1000, 'false');

$unusedWidth = $session->evaluateScript('screen.availWidth - window.outerWidth');
$unusedHeight = $session->evaluateScript('screen.availHeight - window.outerHeight');
$this->assertLessThanOrEqual(0, $unusedWidth);
$this->assertLessThanOrEqual(0, $unusedHeight);
$popupName = 'testPopup';
$createWindowJs = "window.open('about:blank', '$popupName', 'left=20,top=40,width=300,height=200')";
$getWindowPosJs = '
return {
top: window.screenY,
left: window.screenX,
right: window.screenX + window.innerWidth,
bottom: window.screenX + window.innerHeight
}
';
$session->executeScript($createWindowJs);
$session->switchToWindow($popupName);
$oldDim = (array)$session->evaluateScript($getWindowPosJs);

$session->maximizeWindow($popupName);
$newDim = (array)$session->evaluateScript($getWindowPosJs);

foreach (array_keys($oldDim) as $name) {
$this->assertNotEquals(
$oldDim[$name],
$newDim[$name],
"The popup's $name position should not be the same after maximizing"
);
}
}
}

0 comments on commit 7453900

Please sign in to comment.