Mark Lavin avatar Mark Lavin committed 9d4fa74

Tests for hightlight match option.

Comments (0)

Files changed (1)

selectable/tests/qunit/test-options.js

+/*global define, module, test, expect, equal, ok*/
+
+define(['selectable'], function ($) {
+
+    module("Plugin Options Tests", {
+        setup: function () {
+            // Patch AJAX requests
+            var self = this;
+            this.xhr = sinon.useFakeXMLHttpRequest();
+            this.requests = [];
+            this.xhr.onCreate = function (xhr) {
+                self.requests.push(xhr);
+            };
+            this.input = createTextComplete('autocomplete');
+            $('#qunit-fixture').append(this.input);
+            bindSelectables('#qunit-fixture');
+        },
+        teardown: function () {
+            this.xhr.restore();
+            this.input.djselectable('destroy');
+        }
+    });
+
+    test("Highlight Match On", function () {
+        expect(2);
+        var response = simpleLookupResponse(),
+            self = this,
+            menu, item, highlight;
+        this.input.djselectable("option", "highlightMatch", true);
+        this.input.val("ap").keydown();
+        stop();
+        setTimeout(function () {
+            self.requests[0].respond(200, {"Content-Type": "application/json"},
+                JSON.stringify(response)
+            );
+            menu = $('ul.ui-autocomplete.ui-menu:visible');
+            item = $('li', menu).eq(0);
+            highlight = $('.highlight', item);
+            equal(highlight.length, 1, "Highlight should be present");
+            equal(highlight.text(), "Ap", "Highlight text should match");
+            start();
+        }, 300);
+    });
+
+    test("Highlight Match Off", function () {
+        expect(1);
+        var response = simpleLookupResponse(),
+            self = this,
+            menu, item, highlight;
+        this.input.djselectable("option", "highlightMatch", false);
+        this.input.val("ap").keydown();
+        stop();
+        setTimeout(function () {
+            self.requests[0].respond(200, {"Content-Type": "application/json"},
+                JSON.stringify(response)
+            );
+            menu = $('ul.ui-autocomplete.ui-menu:visible');
+            item = $('li', menu).eq(0);
+            highlight = $('.highlight', item);
+            equal(highlight.length, 0, "Highlight should not be present");
+            start();
+        }, 300);
+    });
+});
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.