summaryrefslogtreecommitdiffstats
path: root/test/api/openSpec.js
diff options
context:
space:
mode:
authorVladislav Zarakovsky <vlad.zar@gmail.com>2015-11-24 13:33:45 +0300
committerVladislav Zarakovsky <vlad.zar@gmail.com>2015-11-24 15:41:23 +0300
commit4b7a44949899b1f4ee96c9b3cab26233f040cc1d (patch)
tree4fb51148214a63307d6013a36d417a78de8607b8 /test/api/openSpec.js
parentdcd462013daf14b7dd9629f3278f93dc4b33ad26 (diff)
downloadawesomplete-4b7a44949899b1f4ee96c9b3cab26233f040cc1d.zip
awesomplete-4b7a44949899b1f4ee96c9b3cab26233f040cc1d.tar.gz
awesomplete-4b7a44949899b1f4ee96c9b3cab26233f040cc1d.tar.bz2
awesomplete.open tests
Diffstat (limited to 'test/api/openSpec.js')
-rw-r--r--test/api/openSpec.js53
1 files changed, 53 insertions, 0 deletions
diff --git a/test/api/openSpec.js b/test/api/openSpec.js
new file mode 100644
index 0000000..e79c721
--- /dev/null
+++ b/test/api/openSpec.js
@@ -0,0 +1,53 @@
+describe("awesomplete.open", function () {
+
+ $.fixture("plain");
+
+ subject(function () { return new Awesomplete("#plain", this.options) });
+
+ def("events", function () { return { opened: $.noop } });
+
+ it("opens completer", function () {
+ this.subject.open();
+ expect(this.subject.ul.hasAttribute("hidden")).toBe(false);
+ });
+
+ // Exposes this bug https://github.com/LeaVerou/awesomplete/pull/16740
+ // FIXME better fix is probably required as discussed in PR above
+ xit("fills in the list on creation", function () {
+ $("#plain").value = "ite";
+ this.options = { list: "item1, item2" };
+ this.subject.open();
+
+ expect(this.subject.ul.children.length).toBe(2);
+ });
+
+ it("fires awesomplete-open event", function () {
+ spyOn(this.events, "opened")
+ $.on(this.subject.input, "awesomplete-open", this.events.opened);
+ this.subject.open();
+
+ expect(this.events.opened).toHaveBeenCalled();
+ });
+
+ describe("with autoFirst: true", function () {
+ def("options", function () { return { autoFirst: true } });
+
+ it("automatically selects first item", function () {
+ spyOn(this.subject, "goto");
+ this.subject.open();
+
+ expect(this.subject.goto).toHaveBeenCalledWith(0);
+ });
+ });
+
+ describe("with autoFirst: false", function () {
+ def("options", function () { return { autoFirst: false } });
+
+ it("does not select any item", function () {
+ this.subject.open();
+
+ expect(this.subject.selected).toBe(false);
+ expect(this.subject.index).toBe(-1);
+ });
+ });
+});