summaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorVladislav Zarakovsky <vlad.zar@gmail.com>2016-03-12 14:25:05 +0300
committerVladislav Zarakovsky <vlad.zar@gmail.com>2016-03-12 14:25:05 +0300
commitd276bb2ee7fe68d020bd4ba0da3b5677f3e649e2 (patch)
tree8ac2ae23f70843630bb1301c781eacf6430413fa /test
parent2cd7fada2cf2fcd1c2048ab7ed862f349863a1bb (diff)
parent539fbf5c0b7adc73c22b6b10f9742a5e46170707 (diff)
downloadawesomplete-d276bb2ee7fe68d020bd4ba0da3b5677f3e649e2.zip
awesomplete-d276bb2ee7fe68d020bd4ba0da3b5677f3e649e2.tar.gz
awesomplete-d276bb2ee7fe68d020bd4ba0da3b5677f3e649e2.tar.bz2
Merge pull request #16866 from vlazar/feature/separate-label-value
Separate label/value
Diffstat (limited to 'test')
-rw-r--r--test/api/selectSpec.js4
-rw-r--r--test/init/listSpec.js35
-rw-r--r--test/init/optionsSpec.js4
-rw-r--r--test/static/dataSpec.js19
-rw-r--r--test/static/replaceSpec.js2
5 files changed, 55 insertions, 9 deletions
diff --git a/test/api/selectSpec.js b/test/api/selectSpec.js
index 84895b1..9a1214e 100644
--- a/test/api/selectSpec.js
+++ b/test/api/selectSpec.js
@@ -46,8 +46,8 @@ describe("awesomplete.select", function () {
expect(handler).toHaveBeenCalledWith(
jasmine.objectContaining({
- text: expectedTxt,
- data: expectedTxt,
+ text: jasmine.objectContaining({ label: expectedTxt, value: expectedTxt }),
+ data: jasmine.objectContaining({ label: expectedTxt, value: expectedTxt }),
origin: this.selectArgument || this.subject.ul.children[0]
})
);
diff --git a/test/init/listSpec.js b/test/init/listSpec.js
index 6f95ff0..eff78d6 100644
--- a/test/init/listSpec.js
+++ b/test/init/listSpec.js
@@ -23,12 +23,20 @@ describe("Awesomplete list", function () {
it("assigns from element specified by selector", function () {
this.subject.list = "#data-list";
- expect(this.subject._list).toEqual([ "With", "Data", "List" ]);
+ expect(this.subject._list).toEqual([
+ { label: "With", value: "With" },
+ { label: "Data", value: "Data" },
+ { label: "List", value: "List" }
+ ]);
});
it("assigns from element", function () {
this.subject.list = $("#data-list");
- expect(this.subject._list).toEqual([ "With", "Data", "List" ]);
+ expect(this.subject._list).toEqual([
+ { label: "With", value: "With" },
+ { label: "Data", value: "Data" },
+ { label: "List", value: "List" }
+ ]);
});
it("does not assigns from not found list", function () {
@@ -68,12 +76,20 @@ describe("Awesomplete list", function () {
it("assigns from element specified by selector", function () {
this.options = { list: "#data-list" };
- expect(this.subject._list).toEqual([ "With", "Data", "List" ]);
+ expect(this.subject._list).toEqual([
+ { label: "With", value: "With" },
+ { label: "Data", value: "Data" },
+ { label: "List", value: "List" }
+ ]);
});
it("assigns from list specified by element", function () {
this.options = { list: $("#data-list") };
- expect(this.subject._list).toEqual([ "With", "Data", "List" ]);
+ expect(this.subject._list).toEqual([
+ { label: "With", value: "With" },
+ { label: "Data", value: "Data" },
+ { label: "List", value: "List" }
+ ]);
});
});
@@ -85,14 +101,21 @@ describe("Awesomplete list", function () {
it("assigns from element referenced by selector", function () {
this.element = "#with-data-list";
- expect(this.subject._list).toEqual(["With", "Data", "List"]);
+ expect(this.subject._list).toEqual([
+ { label: "With", value: "With" },
+ { label: "Data", value: "Data" },
+ { label: "List", value: "List" }
+ ]);
});
});
describe("list html attribute", function () {
it("assigns from element referenced by id", function () {
this.element = "#with-list";
- expect(this.subject._list).toEqual(["With", "List"]);
+ expect(this.subject._list).toEqual([
+ { label: "With", value: "With" },
+ { label: "List", value: "List" }
+ ]);
});
});
});
diff --git a/test/init/optionsSpec.js b/test/init/optionsSpec.js
index 40153c1..fc60997 100644
--- a/test/init/optionsSpec.js
+++ b/test/init/optionsSpec.js
@@ -19,6 +19,10 @@ describe("Constructor options", function () {
expect(this.subject.autoFirst).toBe(false);
});
+ it("modifies list item with DATA", function () {
+ expect(this.subject.data).toBe(Awesomplete.DATA);
+ });
+
it("filters with FILTER_CONTAINS", function () {
expect(this.subject.filter).toBe(Awesomplete.FILTER_CONTAINS);
});
diff --git a/test/static/dataSpec.js b/test/static/dataSpec.js
new file mode 100644
index 0000000..311c6eb
--- /dev/null
+++ b/test/static/dataSpec.js
@@ -0,0 +1,19 @@
+describe("Awesomplete.DATA", function () {
+
+ subject(function () { return Awesomplete.DATA(this.item) });
+
+ it("returns original String", function () {
+ this.item = "JavaScript";
+ expect(this.subject).toEqual("JavaScript");
+ });
+
+ it("returns original Object", function () {
+ this.item = { label: "JavaScript", value: "JS" };
+ expect(this.subject).toEqual({ label: "JavaScript", value: "JS" });
+ });
+
+ it("returns original Array", function () {
+ this.item = [ "JavaScript", "JS" ];
+ expect(this.subject).toEqual([ "JavaScript", "JS" ]);
+ });
+});
diff --git a/test/static/replaceSpec.js b/test/static/replaceSpec.js
index 4339ff2..e2eddba 100644
--- a/test/static/replaceSpec.js
+++ b/test/static/replaceSpec.js
@@ -5,7 +5,7 @@ describe("Awesomplete.REPLACE", function () {
def("instance", function() { return { input: { value: "initial" } } });
it("replaces input value", function () {
- this.subject.call(this.instance, "JavaScript");
+ this.subject.call(this.instance, { value: "JavaScript" });
expect(this.instance.input.value).toBe("JavaScript");
});
});