diff options
author | Vladislav Zarakovsky <vlad.zar@gmail.com> | 2015-11-24 15:29:27 +0300 |
---|---|---|
committer | Vladislav Zarakovsky <vlad.zar@gmail.com> | 2015-11-24 15:29:27 +0300 |
commit | ba73e7795689c46de2be98666d1998091f542919 (patch) | |
tree | b07c9604210a9fb4fc6ad60b50eeb155da35c684 /test | |
parent | eff8334482cb0915980a0c543218009af0c3e682 (diff) | |
download | awesomplete-ba73e7795689c46de2be98666d1998091f542919.zip awesomplete-ba73e7795689c46de2be98666d1998091f542919.tar.gz awesomplete-ba73e7795689c46de2be98666d1998091f542919.tar.bz2 |
List initialization tests
Diffstat (limited to 'test')
-rw-r--r-- | test/fixtures/options.html | 10 | ||||
-rw-r--r-- | test/init/listSpec.js | 85 |
2 files changed, 95 insertions, 0 deletions
diff --git a/test/fixtures/options.html b/test/fixtures/options.html index 8ff9eb1..16a2905 100644 --- a/test/fixtures/options.html +++ b/test/fixtures/options.html @@ -1,8 +1,18 @@ +<input id="no-options" class="simple-input" /> + <input id="with-custom-options" data-minchars="4" data-maxitems="8" data-autofirst="true" /> +<input id="with-data-list-inline" data-list="With, Data, List, Inline" /> + <input id="with-data-list" data-list="#data-list" /> <ul id="data-list"> <li>With</li> <li>Data</li> <li>List</li> </ul> + +<input id="with-list" list="list" /> +<datalist id="list"> + <option>With</option> + <option>List</option> +</datalist> 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"]); + }); + }); +}); |