summaryrefslogtreecommitdiffstats
path: root/test/init/listSpec.js
diff options
context:
space:
mode:
Diffstat (limited to 'test/init/listSpec.js')
-rw-r--r--test/init/listSpec.js85
1 files changed, 85 insertions, 0 deletions
diff --git a/test/init/listSpec.js b/test/init/listSpec.js
new file mode 100644
index 0000000..b4d2b66
--- /dev/null
+++ b/test/init/listSpec.js
@@ -0,0 +1,85 @@
+describe("Awesomplete list", function () {
+
+ $.fixture("options");
+
+ subject(function () { return new Awesomplete(this.element, this.options) });
+
+ def("element", "#no-options");
+
+ it("is empty if not provided", function () {
+ expect(this.subject._list).toEqual([]);
+ });
+
+ describe("setter", function () {
+ it("assigns from array", function () {
+ this.subject.list = [ "From", "Array" ];
+ expect(this.subject._list).toEqual([ "From", "Array" ]);
+ });
+
+ it("assigns from comma separated list", function () {
+ this.subject.list = "From,Inline,List";
+ expect(this.subject._list).toEqual([ "From", "Inline", "List" ]);
+ });
+
+ it("assigns from element specified by selector", function () {
+ this.subject.list = "#data-list";
+ expect(this.subject._list).toEqual([ "With", "Data", "List" ]);
+ });
+
+ it("assigns from element", function () {
+ this.subject.list = $("#data-list");
+ expect(this.subject._list).toEqual([ "With", "Data", "List" ]);
+ });
+
+ it("does not assigns from not found list", function () {
+ this.subject.list = "#nosuchlist";
+ expect(this.subject._list).toEqual([]);
+ });
+
+ it("does not assigns from empty list", function () {
+ this.subject.list = "#empty-list";
+ expect(this.subject._list).toEqual([]);
+ });
+ });
+
+ describe("constructor option", function () {
+ it("assigns from array", function () {
+ this.options = { list: [ "From", "Array" ] };
+ expect(this.subject._list).toEqual([ "From", "Array" ]);
+ });
+
+ it("assigns from comma separated list", function () {
+ this.options = { list: "From,Inline,List" };
+ expect(this.subject._list).toEqual([ "From", "Inline", "List" ]);
+ });
+
+ it("assigns from element specified by selector", function () {
+ this.options = { list: "#data-list" };
+ expect(this.subject._list).toEqual([ "With", "Data", "List" ]);
+ });
+
+ it("assigns from list specified by element", function () {
+ this.options = { list: $("#data-list") };
+ expect(this.subject._list).toEqual([ "With", "Data", "List" ]);
+ });
+ });
+
+ describe("data-list html attribute", function () {
+ it("assigns from comma separated list", function () {
+ this.element = "#with-data-list-inline";
+ expect(this.subject._list).toEqual(["With", "Data", "List", "Inline"]);
+ });
+
+ it("assigns from element referenced by selector", function () {
+ this.element = "#with-data-list";
+ expect(this.subject._list).toEqual(["With", "Data", "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"]);
+ });
+ });
+});