Mark Lavin avatar Mark Lavin committed 1cda301

Additional tests for deck add/remove events.

Comments (0)

Files changed (1)

selectable/tests/qunit/test-events.js

             start();
         }, 500);
     });
+
+    module("Custom Event Tests", {
+        setup: function () {
+            this.inputs = createTextSelectMultiple('autocompleteselectmultiple');
+            this.textInput = this.inputs[0];
+            this.hiddenInput = this.inputs[1];
+            $('#qunit-fixture').append(this.textInput);
+            bindSelectables('#qunit-fixture');
+        }
+    });
+
+    test("Add Deck Item", function() {
+        expect(1);
+        var count = 0,
+            item = {id: "1", value: 'foo'};
+        this.textInput.bind('djselectableadd', function(e, item) {
+            count = count + 1;
+        });
+        this.textInput.djselectable('select', item);
+        equal(count, 1, "djselectableadd should fire once when manually selected.");
+    });
+
+    test("Prevent Add Deck Item", function() {
+        expect(1);
+        var count = 0,
+            item = {id: "1", value: 'foo'},
+            deck = $('.selectable-deck', '#qunit-fixture');
+        this.textInput.bind('djselectableadd', function(e, item) {
+            return false;
+        });
+        this.textInput.djselectable('select', item);
+        deck = $('.selectable-deck', '#qunit-fixture');
+        equal($('li', deck).length, 0, "Item should not be added.");
+    });
+
+    test("Remove Deck Item", function() {
+        expect(1);
+        var count = 0,
+            item = {id: "1", value: 'foo'},
+            deck = $('.selectable-deck', '#qunit-fixture');
+        this.textInput.bind('djselectableremove', function(e, item) {
+            count = count + 1;
+        });
+        this.textInput.djselectable('select', item);
+        $('.selectable-deck-remove a', deck).click();
+        equal(count, 1, "djselectableremove should fire once when item is removed.");
+    });
+
+    test("Prevent Remove Deck Item", function() {
+        expect(1);
+        var count = 0,
+            item = {id: "1", value: 'foo'},
+            deck = $('.selectable-deck', '#qunit-fixture');
+        this.textInput.bind('djselectableremove', function(e, item) {
+            return false;
+        });
+        var item = {id: "1", value: 'foo'};
+        this.textInput.djselectable('select', item);
+        $('.selectable-deck-remove a', deck).click();
+        equal($('li', deck).length, 1, "Item should not be removed.");
+    });
 });
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.