From b23c737511d1d77933efdcf750a69d4d19f922f3 Mon Sep 17 00:00:00 2001 From: Christian Sciberras Date: Wed, 27 Sep 2023 09:11:09 +0200 Subject: [PATCH 1/2] Refactor testResizeWindow; increase window size for edge --- tests/Js/WindowTest.php | 33 ++++++++++++++++++--------------- 1 file changed, 18 insertions(+), 15 deletions(-) diff --git a/tests/Js/WindowTest.php b/tests/Js/WindowTest.php index e667600..1b22ddc 100644 --- a/tests/Js/WindowTest.php +++ b/tests/Js/WindowTest.php @@ -71,23 +71,26 @@ public function testResizeWindow(): void { $this->getSession()->visit($this->pathTo('/index.html')); $session = $this->getSession(); + $testWidth = 640; + $testHeight = 480; - $session->resizeWindow(400, 300); + $session->resizeWindow($testWidth, $testHeight); $session->wait(1000, 'false'); - $jsWindowSizeScript = <<<'JS' - (function(){ - var boolSizeCheck = Math.abs(window.outerHeight - 300) <= 100 && Math.abs(window.outerWidth - 400) <= 100; - if (boolSizeCheck){ - return true; - } - var w = window, - d = document, - e = d.documentElement, - g = d.getElementsByTagName('body')[0], - x = w.innerWidth || e.clientWidth || g.clientWidth, - y = w.innerHeight|| e.clientHeight|| g.clientHeight; - boolSizeCheck = Math.abs(y - 300) <= 100 && Math.abs(x - 400) <= 100; - return boolSizeCheck; + $jsWindowSizeScript = <<<"JS" + (function () { + var check = + function(w, h){ + return Math.abs(w - $testWidth) <= 100 + && Math.abs(h - $testHeight) <= 100; + }, + htmlElem = document.documentElement, + bodyElem = document.getElementsByTagName('body')[0]; + + return check(window.outerWidth, window.outerHeight) + || check( + window.innerWidth || htmlElem.clientWidth || bodyElem.clientWidth, + window.innerHeight || htmlElem.clientHeight || bodyElem.clientHeight + ); })(); JS; From 4fb1462c5c0b4880be8a900989cbfc02e43cb686 Mon Sep 17 00:00:00 2001 From: Christian Sciberras Date: Wed, 27 Sep 2023 09:18:29 +0200 Subject: [PATCH 2/2] Tiny CS fix --- tests/Js/WindowTest.php | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/tests/Js/WindowTest.php b/tests/Js/WindowTest.php index 1b22ddc..2a526ba 100644 --- a/tests/Js/WindowTest.php +++ b/tests/Js/WindowTest.php @@ -71,18 +71,18 @@ public function testResizeWindow(): void { $this->getSession()->visit($this->pathTo('/index.html')); $session = $this->getSession(); - $testWidth = 640; - $testHeight = 480; + $expectedWidth = 640; + $expectedHeight = 480; - $session->resizeWindow($testWidth, $testHeight); + $session->resizeWindow($expectedWidth, $expectedHeight); $session->wait(1000, 'false'); + $jsWindowSizeScript = <<<"JS" (function () { - var check = - function(w, h){ - return Math.abs(w - $testWidth) <= 100 - && Math.abs(h - $testHeight) <= 100; - }, + var check = function (actualWidth, actualHeight) { + return Math.abs(actualWidth - $expectedWidth) <= 100 + && Math.abs(actualHeight - $expectedHeight) <= 100; + }, htmlElem = document.documentElement, bodyElem = document.getElementsByTagName('body')[0]; @@ -93,7 +93,6 @@ function(w, h){ ); })(); JS; - $this->assertTrue($session->evaluateScript($jsWindowSizeScript)); }