diff options
-rw-r--r-- | test/init/optionsSpec.js | 8 | ||||
-rw-r--r-- | test/static/itemSpec.js | 50 | ||||
-rw-r--r-- | test/static/replaceSpec.js | 11 |
3 files changed, 65 insertions, 4 deletions
diff --git a/test/init/optionsSpec.js b/test/init/optionsSpec.js index 9dab9ae..40153c1 100644 --- a/test/init/optionsSpec.js +++ b/test/init/optionsSpec.js @@ -27,12 +27,12 @@ describe("Constructor options", function () { expect(this.subject.sort).toBe(Awesomplete.SORT_BYLENGTH); }); - it("generates each completer item with built-in function", function () { - expect(this.subject.item).toEqual(jasmine.any(Function)); + it("creates item with ITEM", function () { + expect(this.subject.item).toEqual(Awesomplete.ITEM); }); - it("mirrors found item into input with built-in function", function () { - expect(this.subject.replace).toEqual(jasmine.any(Function)); + it("replaces input value with REPLACE", function () { + expect(this.subject.replace).toEqual(Awesomplete.REPLACE); }); }); diff --git a/test/static/itemSpec.js b/test/static/itemSpec.js new file mode 100644 index 0000000..95ae2a8 --- /dev/null +++ b/test/static/itemSpec.js @@ -0,0 +1,50 @@ +describe("Awesomplete.ITEM", function () { + + subject(function () { return Awesomplete.ITEM }); + + def("element", function () { return this.subject("JavaScript", this.input || "") }); + + it("creates DOM element", function () { + expect(this.element instanceof HTMLElement).toBe(true); + }); + + it("creates LI element", function () { + expect(this.element.tagName).toBe("LI"); + }); + + it("sets aria-selected to false", function () { + expect(this.element.getAttribute("aria-selected")).toBe("false"); + }); + + describe("with matched input", function () { + def("input", "jav"); + + it("marks the match", function () { + expect(this.element.innerHTML).toBe("<mark>Jav</mark>aScript"); + }); + }); + + describe("with multiple matches", function () { + def("input", "a"); + + it("marks all matches", function () { + expect(this.element.innerHTML).toBe("J<mark>a</mark>v<mark>a</mark>Script"); + }); + }); + + describe("with no match", function () { + def("input", "foo"); + + it("does not mark anything", function () { + expect(this.element.innerHTML).toBe("JavaScript"); + }); + }); + + describe("with empty input", function () { + def("input", ""); + + it("does not mark anything", function () { + expect(this.element.innerHTML).toBe("JavaScript"); + }); + }); +}); diff --git a/test/static/replaceSpec.js b/test/static/replaceSpec.js new file mode 100644 index 0000000..4339ff2 --- /dev/null +++ b/test/static/replaceSpec.js @@ -0,0 +1,11 @@ +describe("Awesomplete.REPLACE", function () { + + subject(function () { return Awesomplete.REPLACE }); + + def("instance", function() { return { input: { value: "initial" } } }); + + it("replaces input value", function () { + this.subject.call(this.instance, "JavaScript"); + expect(this.instance.input.value).toBe("JavaScript"); + }); +}); |