diff --git a/tests/Js/EventsTest.php b/tests/Js/EventsTest.php index f06999b..3e3a618 100644 --- a/tests/Js/EventsTest.php +++ b/tests/Js/EventsTest.php @@ -56,6 +56,15 @@ public function testFocus() $focusBlurDetector->focus(); $this->assertEquals('focused', $focusBlurDetector->getValue()); + + $focusableAnchor = $this->getAssertSession()->elementExists('css', '.elements a#focusable'); + $this->assertEquals('no action detected', $focusableAnchor->getText()); + + $focusableAnchor->focus(); + // checking that we're on same page + $this->getAssertSession()->addressEquals('/js_test.html'); + $this->assertEquals('focused', $focusableAnchor->getText()); + } /** @@ -68,6 +77,8 @@ public function testBlur() $focusBlurDetector = $this->getAssertSession()->elementExists('css', '.elements input#focus-blur-detector'); $this->assertEquals('no action detected', $focusBlurDetector->getValue()); + // focusing before, because blur won't be triggered if HTMLElement is not focused + $focusBlurDetector->focus(); $focusBlurDetector->blur(); $this->assertEquals('blured', $focusBlurDetector->getValue()); } diff --git a/web-fixtures/js_test.html b/web-fixtures/js_test.html index 6285455..3c40871 100644 --- a/web-fixtures/js_test.html +++ b/web-fixtures/js_test.html @@ -30,6 +30,7 @@
+ no action detected
@@ -58,14 +59,22 @@ $(this).text('right clicked'); }); - var $focusDetector = $('#focus-blur-detector'); + var $focusDetector = $('#focus-blur-detector, #focusable'); $focusDetector.focus(function() { - $(this).val('focused'); + if (this.nodeName === 'A') { + $(this).text('focused'); + } else { + $(this).val('focused'); + } }); $focusDetector.blur(function() { - $(this).val('blured'); + if (this.nodeName === 'A') { + $(this).text('blured'); + } else { + $(this).val('blured'); + } }); $('#mouseover-detector').mouseover(function() {