Commit 54849985 authored by Sam Saccone's avatar Sam Saccone

Merge pull request #1564 from tastejs/sjs/double-click-focus

Add test to verify correct double click focus
parents 80b3bba5 cdd17df6
...@@ -6,8 +6,6 @@ The TodoMVC project has a great many implementations of exactly the same app usi ...@@ -6,8 +6,6 @@ The TodoMVC project has a great many implementations of exactly the same app usi
## Todo ## Todo
- [ ] Complete the test implementation (27 out of 28 are now complete). The only test that I am struggling with is to test that the delete button becomes visible on hover. - [ ] Complete the test implementation (27 out of 28 are now complete). The only test that I am struggling with is to test that the delete button becomes visible on hover.
- [ ] Find a more elegant solution for TodoMVC apps that use RequireJS, currently there is a short 'sleep' statement in order to give the browser time to load dependencies. Yuck!
- [ ] Run JSHint over my code ;-)
- [ ] Make it work with PhantomJS. In practice, Phantom is only a little bit faster, but it should work. Currently there are a few Phantom specific failures. - [ ] Make it work with PhantomJS. In practice, Phantom is only a little bit faster, but it should work. Currently there are a few Phantom specific failures.
- [ ] Allow testing of apps that require a server (see: https://github.com/tastejs/todomvc/pull/821/files#r9377070) - [ ] Allow testing of apps that require a server (see: https://github.com/tastejs/todomvc/pull/821/files#r9377070)
......
...@@ -107,9 +107,17 @@ module.exports = function Page(browser) { ...@@ -107,9 +107,17 @@ module.exports = function Page(browser) {
}; };
// ----------------- DOM element access methods // ----------------- DOM element access methods
this.getActiveElement = function () {
return browser.switchTo().activeElement();
};
this.getFocussedTagName = function () {
return this.getActiveElement().getTagName();
};
this.getFocussedElementId = function () { this.getFocussedElementName = function () {
return browser.switchTo().activeElement().getAttribute(!idSelectors ? 'id' : 'class'); return this.getActiveElement()
.getAttribute(!idSelectors ? 'id' : 'class');
}; };
this.getEditInputForItemAtIndex = function (index) { this.getEditInputForItemAtIndex = function (index) {
......
...@@ -216,6 +216,11 @@ module.exports.todoMVCTest = function (frameworkName, baseUrl, speedMode, laxMod ...@@ -216,6 +216,11 @@ module.exports.todoMVCTest = function (frameworkName, baseUrl, speedMode, laxMod
page.doubleClickItemAtIndex(1); page.doubleClickItemAtIndex(1);
}); });
test.it('should focus the input', function () {
testOps.assertInputFocused();
testOps.assertNewInputNotFocused();
});
test.it('should hide other controls when editing', function () { test.it('should hide other controls when editing', function () {
testOps.assertItemToggleIsHidden(1); testOps.assertItemToggleIsHidden(1);
testOps.assertItemLabelIsHidden(1); testOps.assertItemLabelIsHidden(1);
......
...@@ -21,8 +21,22 @@ function TestOperations(page) { ...@@ -21,8 +21,22 @@ function TestOperations(page) {
}); });
} }
this.assertNewInputNotFocused = function () {
return page.getFocussedElementName()
.then(function(name) {
assert.notEqual(name, 'new-todo');
});
};
this.assertInputFocused = function () {
return page.getFocussedTagName()
.then(function (name) {
assert.equal(name, 'input', 'input does not have focus');
});
};
this.assertFocussedElementId = function (expectedId) { this.assertFocussedElementId = function (expectedId) {
page.getFocussedElementId().then(function (id) { page.getFocussedTagName().then(function (id) {
assert.notEqual(id.indexOf(expectedId), -1, 'The focused element did not have the expected id ' + expectedId); assert.notEqual(id.indexOf(expectedId), -1, 'The focused element did not have the expected id ' + expectedId);
}); });
}; };
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment