Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

improving testFocus and testBlur #29

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions tests/Js/EventsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be added as a separate tests. We want granular tests in that testsuite to make it easier to skip them when needed for unsupported things in each driver.


$focusableAnchor->focus();
// checking that we're on same page
$this->getAssertSession()->addressEquals('/js_test.html');
$this->assertEquals('focused', $focusableAnchor->getText());

}

/**
Expand All @@ -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());
}
Expand Down
15 changes: 12 additions & 3 deletions web-fixtures/js_test.html
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
<input class="input second" type="text" value="" />
<input class="input third" type="text" value="" />
<div class="text-event"></div>
<a href="index.html" id="focusable">no action detected</a>
</div>

<div id="draggable" class="ui-widget-content"></div>
Expand Down Expand Up @@ -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() {
Expand Down