Skip to content

Commit

Permalink
tests: Add editing focus test
Browse files Browse the repository at this point in the history
  • Loading branch information
samccone committed Dec 26, 2015
1 parent aa89c29 commit 765e623
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 2 deletions.
10 changes: 9 additions & 1 deletion tests/page.js
Original file line number Diff line number Diff line change
Expand Up @@ -107,9 +107,17 @@ module.exports = function Page(browser) {
};

// ----------------- DOM element access methods
this.getActiveElement = function () {
return browser.switchTo().activeElement();
};

this.getFocussedTagName = function () {
return this.getActiveElement().getTagName();
};

this.getFocussedElementId = function () {
return browser.switchTo().activeElement().getAttribute(!idSelectors ? 'id' : 'class');
return this.getActiveElement()
.getAttribute(!idSelectors ? 'id' : 'class');
};

this.getEditInputForItemAtIndex = function (index) {
Expand Down
5 changes: 5 additions & 0 deletions tests/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,11 @@ module.exports.todoMVCTest = function (frameworkName, baseUrl, speedMode, laxMod
page.doubleClickItemAtIndex(1);
});

test.it('should focus the input', function () {
testOps.assertInputFocused();
testOps.assertNewInputNotFocused();
});

test.it('should hide other controls when editing', function () {
testOps.assertItemToggleIsHidden(1);
testOps.assertItemLabelIsHidden(1);
Expand Down
16 changes: 15 additions & 1 deletion tests/testOperations.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,22 @@ function TestOperations(page) {
});
}

this.assertNewInputNotFocused = function () {
return page.getFocussedElementId()
.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) {
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);
});
};
Expand Down

0 comments on commit 765e623

Please sign in to comment.