+/* remove the "source" and "author" facet link to get more records again */
+describe("Check removable facets links", function () {
+ var $ = mkws.$;
+
+ it("remove links for source and author", function () {
+ var waitcount = 0;
+ if (!jasmine_config.check_sortby) {
+ debug("ignore check for removable facets");
+ return;
+ }
+
+
+ runs(function () {
+ var click = $("a.mkwsRemovable").eq(0).trigger("click");
+ debug("Removed first facets link: " + click.length);
+ expect(click.length).toBe(1);
+ });
+
+ runs(function () {
+ $("div.mkwsRecords").bind("DOMNodeInserted DOMNodeRemoved propertychange", function () {
+ waitcount++;
+ debug("DOM change mkwsRecords for removeable: " + waitcount);
+ });
+ });
+
+ waitsFor(function () {
+ return waitcount >= 2 && $("a.mkwsRemovable").length == 1 ? 1 : 0;
+ }, "Records DOM change mkwsRecords, removable", 2 * jasmine_config.second);
+
+ runs(function () {
+ debug("unbind removable");
+ $("div.mkwsRecords").unbind("DOMNodeInserted DOMNodeRemoved propertychange");
+ waitcount = 0;
+
+ $("div.mkwsRecords").bind("DOMNodeInserted DOMNodeRemoved propertychange", function () {
+ waitcount++;
+ debug("DOM change mkwsRecords for removeable2: " + waitcount);
+ });
+
+ var click = $("a.mkwsRemovable").eq(0).trigger("click");
+ debug("Removed second facets link: " + click.length);
+ expect(click.length).toBe(1);
+ });
+
+ waitsFor(function () {
+ return waitcount >= 2 && $("a.mkwsRemovable").length == 0 ? true : false;
+ }, "DOM change mkwsRecords, removable2", 2 * jasmine_config.second);
+
+ runs(function () {
+ debug("unbind removable2");
+ $("div.mkwsRecords").unbind("DOMNodeInserted DOMNodeRemoved propertychange");
+ });
+ });
+});
+
+
+describe("Check per page options", function () {
+ var $ = mkws.$;
+
+ it("show per page", function () {
+ if (!jasmine_config.check_sortby) {
+ debug("ignore check for per page select");
+ return;
+ }
+ var waitcount = 0;
+ var per_page_number = 20;
+
+
+ runs(function () {
+ var select = $("select.mkwsPerpage option[selected='selected']");
+ debug("per page default is: " + select.text() + " and unselect it");
+ select.removeAttr('selected');
+
+ select = $("select.mkwsPerpage option[value='" + per_page_number + "']").attr('selected', true);
+ debug("per page is set to: " + select.text());
+ select.trigger("change");
+
+ $("div.mkwsRecords").bind("DOMNodeInserted DOMNodeRemoved propertychange", function () {
+ waitcount++;
+ debug("DOM change mkwsRecords, per page: " + waitcount);
+ });
+ });
+
+ waitsFor(function () {
+ // debug("per page waitcounter: " + waitcount)
+ return waitcount >= (per_page_number + 10) ? true : false;
+ }, "DOM change mkwsRecords, by per page", 3 * jasmine_config.second);
+
+ runs(function () {
+ debug("unbind per page");
+ $("div.mkwsRecords").unbind("DOMNodeInserted DOMNodeRemoved propertychange");
+
+ var records = $("div.mkwsRecords > div.mkwsSummary");
+ debug("Per page got now " + records.length + " records");
+ expect(records.length).toBe(per_page_number);
+ });
+ });
+});
+
+describe("Check SortBy options", function () {
+ var $ = mkws.$;
+
+ it("show per page", function () {
+ if (!jasmine_config.check_sortby) {
+ debug("ignore check for sort by");
+ return;
+ }
+
+ var waitcount = 0;
+ var sort_value = 'title:1';
+ var per_page_number = 20;
+ var title_list_old = title_list("xxx ");
+
+ function title_list(prefix) {
+ var list = [];
+ var terms = $("div.mkwsRecords > div.mkwsSummary > a");
+ for (var i = 0; i < terms.length; i++) {
+ var term = $(terms[i]).text().trim();
+ list.push(term);
+ // debug(prefix + "title: " + term);
+ }
+ return list;
+ }
+
+ runs(function () {
+ $("div.mkwsRecords").bind("DOMNodeInserted DOMNodeRemoved propertychange", function () {
+ waitcount++;
+ debug("DOM change mkwsRecords, sort by: " + waitcount);
+ });
+
+ var select = $("select.mkwsSort option[selected='selected']");
+ debug("Sort by default is: " + select.text() + " and unselect it");
+ select.removeAttr('selected');
+
+ select = $("select.mkwsSort option[value='" + sort_value + "']").attr('selected', true);
+ debug("sort by is set to: " + select.text());
+ select.trigger("change");
+ });
+
+ waitsFor(function () {
+ //debug("wait for2: " + waitcount);
+ return waitcount >= (per_page_number + 10) ? true : false;
+ }, "DOM change mkwsRecords, by sort page", 3 * jasmine_config.second);
+
+ runs(function () {
+ $("div.mkwsRecords").unbind("DOMNodeInserted DOMNodeRemoved propertychange");
+ debug("unbind by sort");
+
+ var records = $("div.mkwsRecords > div.mkwsSummary > a");
+ debug("Sort by got now " + records.length + " records");
+ expect(records.length).toBe(per_page_number);
+ });
+
+ runs(function () {
+ var title_list_new = title_list("yyy ");
+ var diff_flag = 0;
+ for (var i = 0; i < title_list_old.length; i++) {
+ debug((i+1) + ". " + title_list_old[i] + " :: " + title_list_new[i]);
+
+ if (title_list_old[i] != title_list_new[i]) {
+ diff_flag++;
+ }
+ }
+ debug("Title changes: " + diff_flag + " out of " + per_page_number);
+ expect(diff_flag).not.toBe(0);
+ });
+ });
+});
+
+describe("Check async widget discovery", function () {
+ var $ = mkws.$;
+ it("initialises a new widget", function() {
+ $("div.mkwsSearch").after('<div id="asyncSearch"><div class="mkwsSearch mkwsTeam_async"></div></div>');
+ mkws.init("Another search box", "#asyncSearch");
+ waitsFor(function () {
+ return $("#asyncSearch input").length >= 1 ? true : false;
+ }, "Call init() to build an .mkwsSearch", 750);
+ runs(function () {
+ var numInput = $("div.mkwsSearch input").length;
+ debug("Input elements present: " + numInput);
+ expect(numInput).toBe(4);
+ var numRec = $("div.mkwsRecords > div.mkwsSummary > a").length;
+ debug("Records should still be present. There are: " + numRec);
+ expect(numRec).toBeGreaterThan(0);
+ });
+ });
+});
+