Skip to content

Commit

Permalink
more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jackocnr committed Jul 13, 2014
1 parent 577b5ec commit dc9ab6f
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/spec/helpers/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,11 @@ var selectFlag = function(countryCode, i) {

var putCursorAtEnd = function() {
var len = input.val().length;
input[0].setSelectionRange(len, len);
selectInputChars(len, len);
};

var selectInputChars = function(start, end) {
input[0].setSelectionRange(start, end);
};

var getKeyEvent = function(key, type) {
Expand Down
29 changes: 29 additions & 0 deletions src/spec/tests/options/autoFormat.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,35 @@ describe("testing autoFormat option", function() {
});

});



describe("selecting some chars", function() {

var cursorStart = 4,
cursorEnd = 7;

beforeEach(function() {
// formatted number is "+1 (702) 418-1234" so this will be "702"
selectInputChars(cursorStart, cursorEnd);
});

it("hitting a non-number char doesn't do anything", function() {
triggerKeyOnInput(" ");
expect(input.val()).toEqual(formattedNumber);
// check selection remains
expect(input[0].selectionStart).toEqual(cursorStart);
expect(input[0].selectionEnd).toEqual(cursorEnd);
});

it("hitting a number char will replace the selection, reformat, and put the cursor in the right place", function() {
triggerKeyOnInput("9");
expect(input.val()).toEqual("+1 (941) 812-34");
// cursor
expect(input[0].selectionStart).toEqual(cursorStart+1);
});

});

});

Expand Down

0 comments on commit dc9ab6f

Please sign in to comment.