From 4183c477694764d0354613d746d0b5f4966ccf47 Mon Sep 17 00:00:00 2001 From: Christian Sciberras Date: Sun, 9 Jul 2023 21:15:12 +0200 Subject: [PATCH] Update test; improve test file --- tests/Js/WindowTest.php | 45 ++++++++++++++++++++++++++++++----------- 1 file changed, 33 insertions(+), 12 deletions(-) diff --git a/tests/Js/WindowTest.php b/tests/Js/WindowTest.php index cdf67ab..1b23d4a 100644 --- a/tests/Js/WindowTest.php +++ b/tests/Js/WindowTest.php @@ -1,12 +1,17 @@ getSession()->visit($this->pathTo('/window.html')); $session = $this->getSession(); @@ -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(); @@ -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(); @@ -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" + ); + } } }