summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVladislav Zarakovsky <vlad.zar@gmail.com>2016-01-30 14:56:00 +0300
committerVladislav Zarakovsky <vlad.zar@gmail.com>2016-01-30 14:56:00 +0300
commitdd4db9083127c70e9e71822a9e75cdcf48e54601 (patch)
tree1ea93b704383233e0db3d523a5b133a298baff6d
parent0248c50f059becf8f2af5fa7ef2147678c94451a (diff)
parent35fe8c1f187c7a8f9627142bac63dcc4ad054bf4 (diff)
downloadawesomplete-dd4db9083127c70e9e71822a9e75cdcf48e54601.zip
awesomplete-dd4db9083127c70e9e71822a9e75cdcf48e54601.tar.gz
awesomplete-dd4db9083127c70e9e71822a9e75cdcf48e54601.tar.bz2
Merge pull request #16834 from vlazar/feature/item-and-replace-tests
Tests for Awesomplete.ITEM and Awesomplete.REPLACE
-rw-r--r--test/init/optionsSpec.js8
-rw-r--r--test/static/itemSpec.js50
-rw-r--r--test/static/replaceSpec.js11
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");
+ });
+});