Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Cleaning up focus tests.

  • Loading branch information...
commit 7ad0ccb6fa3a9fdb14a504510debd6fb57ecb9f3 1 parent 7413f46
@digitalBush authored
Showing with 86 additions and 68 deletions.
  1. +86 −68 spec/Focus.Spec.js
View
154 spec/Focus.Spec.js
@@ -1,71 +1,89 @@
-describe("Focus Specifications", function() {
- var input;
-
- beforeEach(function(){
- input =
- $("<input />")
- .appendTo("body");
+feature("Focusing A Masked Input",function(){
+ scenario("Mask starts with a placeholder",function(){
+ given("a mask beginning with a placeholder",function(){
+ input.mask("9");
+ });
+ when("focusing",function(){
+ input.focus();
+ });
+ waits(1);
+ then("placeholder text should be correct",function(){
+ expect(input).toHaveValue('_');
+ });
+ and("caret position should be correct",function(){
+ var caret=input.caret();
+ expect(caret.begin).toEqual(0);
+ expect(caret.end).toEqual(0);
+ });
});
-
- afterEach(function(){
- input.remove();
- });
-
- describe("when focusing with a mask that starts with a placeholder", function(){
- beforeEach(function(){
- input.mask("9").focus();
- });
-
- it("should have the correct placeholder text", function(){
- expect(input).toHaveValue('_');
- });
-
- it("should have the correct caret position", function(){
- waits(1);
- runs(function(){
- var caret=input.caret();
- expect(caret.begin).toEqual(0);
- expect(caret.end).toEqual(0);
- });
- });
-
- describe("when blurring", function(){
- beforeEach(function(){
- input.blur();
- });
-
- it("should have an empty value", function(){
- expect(input).toHaveValue('');
- });
- });
+
+ scenario("Mask starts with a literal",function(){
+ given("a mask beginning with a literal",function(){
+ input.mask("(9)");
+ });
+ when("focusing",function(){
+ input.focus();
+ });
+ waits(1);
+ then("placeholder text should be correct",function(){
+ expect(input).toHaveValue('(_)');
+ });
+ and("caret position should be correct",function(){
+ var caret=input.caret();
+ expect(caret.begin).toEqual(1);
+ expect(caret.end).toEqual(1);
+ });
});
-
- describe("when focusing with a mask that starts with a literal", function(){
- beforeEach(function(){
- input.mask("(9)").focus();
- });
-
- it("should have the correct placeholder text", function(){
- expect(input).toHaveValue('(_)');
- });
-
- it("should have the correct caret position", function(){
- waits(1);
- runs(function(){
- var caret=input.caret();
- expect(caret.begin).toEqual(1);
- expect(caret.end).toEqual(1);
- });
- });
-
- describe("when blurring", function(){
- beforeEach(function(){
- input.blur();
- });
-
- it("should have an empty value", function(){
- expect(input).toHaveValue('');
- });
- });
+});
+
+feature("Leaving A Masked Input",function(){
+ scenario("All placeholders filled",function(){
+ given("a mask with two placeholders",function(){
+ input.mask("99");
+ });
+ when("typing two characters and blurring",function(){
+ input.mashKeys("12").blur();
+ });
+ then("value should be correct",function(){
+ expect(input).toHaveValue("12");
+ });
});
-});
+
+ scenario("Empty placeholders remaining",function(){
+ given("a mask with two placeholders",function(){
+ input.mask("99");
+ });
+ when("typing one character and blurring",function(){
+ input.mashKeys("1").blur();
+ });
+ then("value should be empty",function(){
+ expect(input).toHaveValue("");
+ });
+ });
+});
+
+feature("Optional marker",function(){
+ scenario("Placeholders not filled to marker",function(){
+ given("a mask with an optional marker",function(){
+ input.mask("99?99");
+ });
+ when("typing one character and leaving",function(){
+ input.mashKeys("1").blur();
+ });
+ then("value should be empty",function(){
+ expect(input).toHaveValue("");
+ });
+ });
+
+ scenario("Placeholders filled to marker",function(){
+ given("a mask with an optional marker",function(){
+ input.mask("99?99");
+ });
+ when("typing two characters and leaving",function(){
+ input.mashKeys("12").blur();
+ });
+ then("value should remain",function(){
+ expect(input).toHaveValue("12");
+ });
+ });
+});
Please sign in to comment.
Something went wrong with that request. Please try again.