From 6e7e0ab8de08307f38394757ebe3d94296da8875 Mon Sep 17 00:00:00 2001 From: Alex Skrypnyk Date: Wed, 5 Jul 2017 20:24:18 +1000 Subject: [PATCH 1/3] Fixed step definitions to support hyphen in the componenet names. --- .../Context/RelativityContext.php | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/IntegratedExperts/BehatRelativityExtension/Context/RelativityContext.php b/src/IntegratedExperts/BehatRelativityExtension/Context/RelativityContext.php index c44b739..fc854db 100644 --- a/src/IntegratedExperts/BehatRelativityExtension/Context/RelativityContext.php +++ b/src/IntegratedExperts/BehatRelativityExtension/Context/RelativityContext.php @@ -197,7 +197,7 @@ public function init(BeforeScenarioScope $scope) * @param string $subject Subject as a string. * @param string $others Others as a string. * - * @Then /^I see ([a-zA-Z0-9\s,]+) above ([a-zA-Z0-9\s,\-]+)$/ + * @Then /^I see ([a-zA-Z0-9\s,\-]+) above ([a-zA-Z0-9\s,\-]+)$/ */ public function assertAbove($subject, $others) { @@ -210,7 +210,7 @@ public function assertAbove($subject, $others) * @param string $subject Subject as a string. * @param string $others Others as a string. * - * @Then /^I see ([a-zA-Z0-9\s,]+) below ([a-zA-Z0-9\s,\-]+)$/ + * @Then /^I see ([a-zA-Z0-9\s,\-]+) below ([a-zA-Z0-9\s,\-]+)$/ */ public function assertBelow($subject, $others) { @@ -223,7 +223,7 @@ public function assertBelow($subject, $others) * @param string $subject Subject as a string. * @param string $others Others as a string. * - * @Then /^I see ([a-zA-Z0-9\s,]+) to (?:|the\s)left of ([a-zA-Z0-9\s,]+)$/ + * @Then /^I see ([a-zA-Z0-9\s,\-]+) to (?:|the\s)left of ([a-zA-Z0-9\s,]+)$/ */ public function assertLeft($subject, $others) { @@ -236,7 +236,7 @@ public function assertLeft($subject, $others) * @param string $subject Subject as a string. * @param string $others Others as a string. * - * @Then /^I see ([a-zA-Z0-9\s,]+) to (?:|the\s)right of ([a-zA-Z0-9\s,]+)$/ + * @Then /^I see ([a-zA-Z0-9\s,\-]+) to (?:|the\s)right of ([a-zA-Z0-9\s,\-]+)$/ */ public function assertRight($subject, $others) { @@ -249,7 +249,7 @@ public function assertRight($subject, $others) * @param string $subject Subject as a string. * @param string $others Others as a string. * - * @Then /^I see ([a-zA-Z0-9\s,]+) inside of ([a-zA-Z0-9\s,]+)$/ + * @Then /^I see ([a-zA-Z0-9\s,\-]+) inside of ([a-zA-Z0-9\s,\-]+)$/ */ public function assertInside($subject, $others) { @@ -262,7 +262,7 @@ public function assertInside($subject, $others) * @param string $subject Subject as a string. * @param string $others Others as a string. * - * @Then /^I see ([a-zA-Z0-9\s,]+) outside of ([a-zA-Z0-9\s,]+)$/ + * @Then /^I see ([a-zA-Z0-9\s,\-]+) outside of ([a-zA-Z0-9\s,\-]+)$/ */ public function assertOutside($subject, $others) { From fca8e641e1dba6c92beb1a69e91f2940be8a2fc6 Mon Sep 17 00:00:00 2001 From: Alex Skrypnyk Date: Wed, 5 Jul 2017 20:25:14 +1000 Subject: [PATCH 2/3] Added support for geometry retrieval from fixed components. --- behat.yml | 8 + .../Context/RelativityContext.php | 27 +- tests/behat/features/fixtures/relative.html | 857 +++++++++++------- tests/behat/features/positioning.feature | 25 + 4 files changed, 564 insertions(+), 353 deletions(-) diff --git a/behat.yml b/behat.yml index b5b63e9..3cab290 100644 --- a/behat.yml +++ b/behat.yml @@ -79,3 +79,11 @@ default: 'over-fixed inner': "#over-fixed-inner" 'over-under': "#over-under" 'over-under inner': "#over-under-inner" + 'fixed-scrolled': "#fixed-scrolled" + 'fixed-scrolled-item-1': "#fixed-scrolled-item-1" + 'fixed-scrolled-item-2': "#fixed-scrolled-item-2" + 'fixed-scrolled-item-3': "#fixed-scrolled-item-3" + 'fixed-scrolled-item-31': "#fixed-scrolled-item-31" + 'fixed-scrolled-item-311': "#fixed-scrolled-item-311" + 'fixed-scrolled-item-312': "#fixed-scrolled-item-312" + 'fixed-scrolled-item-32': "#fixed-scrolled-item-32" diff --git a/src/IntegratedExperts/BehatRelativityExtension/Context/RelativityContext.php b/src/IntegratedExperts/BehatRelativityExtension/Context/RelativityContext.php index fc854db..92e904a 100644 --- a/src/IntegratedExperts/BehatRelativityExtension/Context/RelativityContext.php +++ b/src/IntegratedExperts/BehatRelativityExtension/Context/RelativityContext.php @@ -606,14 +606,35 @@ protected function resizeViewport($width, $height) */ protected function getComponentGeometry($selector, $doScroll = true) { - $script = "return (function(el) { - if (el.length) {".($doScroll ? "jQuery(window).scrollTop(el.offset().top);" : "")." + $script = "return (function(el) { + function scrollToEl(el) { + el.parents().each(function () { + var parent = $(this); + parent.scrollTop(0); + var delta = el.offset().top - parent.offset().top; + parent.scrollTop(delta); + }); + } + + function findTop(el) { + var top = el.offset().top; + el.parents().each(function () { + var parent = jQuery(this); + if (parent.css('position') === 'fixed') { + top = top - parent.parent().scrollTop(); + el = parent; + } + }); + return top; + } + + if (el.length) {".($doScroll ? "scrollToEl(el);" : "")." function zIndex(el) { var z = 0; el.add(el.parents()).each(function () { if ((jQuery(this).css('position') == 'absolute') && jQuery(this).css('z-index') != 'auto') { z = parseInt(jQuery(this).css('z-index'), 10); } }); return z; } if (el.is(':visible') && el.height() > 1 && !(el.css('clip') == 'rect(0px 0px 0px 0px)' && el.css('position') == 'absolute')){ return { width: el.outerWidth(), height: el.outerHeight(), - top: Math.ceil(el.offset().top), + top: Math.ceil(findTop(el)), left: Math.ceil(el.offset().left), zIndex: zIndex(el), position: el.css('position') diff --git a/tests/behat/features/fixtures/relative.html b/tests/behat/features/fixtures/relative.html index 8b2cd70..17db15d 100644 --- a/tests/behat/features/fixtures/relative.html +++ b/tests/behat/features/fixtures/relative.html @@ -1,429 +1,586 @@ - - - - + +
- Top content -
- inner Top content -
+ Top content +
+ inner Top content +
- Main content -
- inner Main content -
- inner Main content custom -
+ Main content +
+ inner Main content +
+ inner Main content custom
+
- Left content -
- inner Left content -
+ Left content +
+ inner Left content +
- Bottom content -
- inner Bottom content -
+ Bottom content +
+ inner Bottom content +
Text for custom viewport
- Off-canvas left content + Off-canvas left content
- Off-canvas right content + Off-canvas right content
- Off-canvas top content + Off-canvas top content
- Off-canvas bottom content + Off-canvas bottom content
- Hidden content + Hidden content
- Hidden content, but accessible for screen readers + Hidden content, but accessible for screen readers
- Hidden content that is accessible for screen readers, but shown after being hidden + Hidden content that is accessible for screen readers, but shown after being hidden
-
- Text COVER over -
- Text inner COVER over -
+
+ Text COVER over +
+ Text inner COVER over
+
-
- Text INSIDE over -
- Text inner INSIDE over -
+
+ Text INSIDE over +
+ Text inner INSIDE over
+
-
- Text OUTSIDE over -
- Text inner OUTSIDE over -
+
+ Text OUTSIDE over +
+ Text inner OUTSIDE over
+
-
- Text INTERSECT over -
- Text inner INTERSECT over -
+
+ Text INTERSECT over +
+ Text inner INTERSECT over
+
-
- Text FIXED over -
- Text inner FIXED over -
+
+ Text FIXED over +
+ Text inner FIXED over
+
-
- Text UNDER over -
- Text inner UNDER over -
+
+ Text UNDER over +
+ Text inner UNDER over
+
+ +
Text for over bottom
+
-
Text for over bottom
+
+
+ Item 1 +
+
+ Item 2 +
+
+ Item 3 +
+ Item 31 +
+ Item 311 +
+
+ Item 312 +
+
+
+ Item 32 +
+
diff --git a/tests/behat/features/positioning.feature b/tests/behat/features/positioning.feature index 792c23f..f1153e7 100644 --- a/tests/behat/features/positioning.feature +++ b/tests/behat/features/positioning.feature @@ -145,3 +145,28 @@ Feature: Behat relative assertions work Given I am on the test page Then I see top, main and left above bottom And I save screenshot + + @javascript @phpserver + Scenario: Assert that elements with fixed position work correctly + Given I am on the test page + # Assert that first level fixed container works as expected relatively to + # other static elements on the page. + Then I see fixed-scrolled below top + And I save screenshot + And I see fixed-scrolled above bottom + And I save screenshot + And I see top above fixed-scrolled + And I save screenshot + And I see bottom below fixed-scrolled + And I save screenshot + # Assert that static and fixed children and grand-children of first level + # fixed container work as expected relatively to other static elements on + # the page. + And I see fixed-scrolled-item-1, fixed-scrolled-item-2, fixed-scrolled-item-3, fixed-scrolled-item-31, fixed-scrolled-item-311, fixed-scrolled-item-312, fixed-scrolled-item-32 below top + And I save screenshot + And I see fixed-scrolled-item-1, fixed-scrolled-item-2, fixed-scrolled-item-3, fixed-scrolled-item-31, fixed-scrolled-item-311, fixed-scrolled-item-312, fixed-scrolled-item-32 above bottom + And I save screenshot + # Assert that static elements within fixed container work correctly with + # grand-children within previous sibling fixed container. + And I see fixed-scrolled-item-311 above fixed-scrolled-item-32 + And I save screenshot From 97e74760f8385f09c26b3ff7f053ffb2674d223c Mon Sep 17 00:00:00 2001 From: Alex Skrypnyk Date: Wed, 5 Jul 2017 21:47:08 +1000 Subject: [PATCH 3/3] Fixed init() being called for non-JS tests. --- .../BehatRelativityExtension/Context/RelativityContext.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/IntegratedExperts/BehatRelativityExtension/Context/RelativityContext.php b/src/IntegratedExperts/BehatRelativityExtension/Context/RelativityContext.php index 92e904a..d45be41 100644 --- a/src/IntegratedExperts/BehatRelativityExtension/Context/RelativityContext.php +++ b/src/IntegratedExperts/BehatRelativityExtension/Context/RelativityContext.php @@ -172,7 +172,7 @@ public function assertClick($subjects) * * @param \Behat\Behat\Hook\Scope\BeforeScenarioScope $scope Scenario scope. * - * @BeforeScenario + * @BeforeScenario @javascript */ public function init(BeforeScenarioScope $scope) {