X-Git-Url: http://git.indexdata.com/?a=blobdiff_plain;f=test%2Fspec%2Fmkws-pazpar2.js;h=211b61c9e2c336a878d33b3d8ecd8b493c53c038;hb=ba4eb503acca0f5208aca788b23437b0101cba86;hp=cab9b478147ca5cb1b6c2bc52b170f7d7d31a100;hpb=86de43e9e9947fbcb75be3a3a71c7e4a12cd59e3;p=mkws-moved-to-github.git diff --git a/test/spec/mkws-pazpar2.js b/test/spec/mkws-pazpar2.js index cab9b47..211b61c 100644 --- a/test/spec/mkws-pazpar2.js +++ b/test/spec/mkws-pazpar2.js @@ -1,4 +1,4 @@ -/* Copyright (c) 2013-2014 IndexData ApS. http://indexdata.com +/* Copyright (c) 2013-2014 Index Data ApS. http://indexdata.com * * perform papzpar2 / pz2.js search & retrieve request in the browser * @@ -56,28 +56,30 @@ function init_jasmine_config() { } mkws.jasmine_done = false; -} - -var get_hit_counter = function () { - // not yet here - if ($(".mkwsPager").length == 0) return -1; - - var found = $(".mkwsPager").text(); - var re = /\([A-Za-z]+:\s+([0-9]+)\)/; - re.exec(found); - var hits = -1; +}; - if (RegExp.$1) { - hits = parseInt(RegExp.$1); - if (hits <= 0) { - debug("Oooops in get_hit_counter: " + RegExp.$1 + " '" + found + "'"); - } +function get_hit_counter() { + var $ = mkws.$; + // not yet here + if ($(".mkwsPager").length == 0) return -1; + + var found = $(".mkwsPager").text(); + var re = /\([A-Za-z]+:\s+([0-9]+)\)/; + re.exec(found); + var hits = -1; + + if (RegExp.$1) { + hits = parseInt(RegExp.$1); + if (hits <= 0) { + debug("Oooops in get_hit_counter: " + RegExp.$1 + " '" + found + "'"); } - - //debug("Hits: " + hits); - return hits; } + //debug("Hits: " + hits); + return hits; +}; + +/******************************************************************************/ describe("Init jasmine config", function () { it("jasmine was successfully initialized", function () { init_jasmine_config(); @@ -91,6 +93,8 @@ describe("Init jasmine config", function () { //disabled xdescribe("Check MOTD before search", function () { + var $ = mkws.$; + // Check that the MOTD has been moved into its container, and // is visible before the search. // the mkwsMOTD div was originally inside a testMOTD div, which should @@ -250,7 +254,7 @@ describe("Check Termlist", function () { waitsFor(function () { return $("div.mkwsFacet[data-mkws-facet='author'] div.mkwsTerm").length >= 2 ? true : false; - }, "At least one author link displayed", 4 * jasmine_config.second); + }, "At least two author link displayed", 4 * jasmine_config.second); runs(function () { expect($("div.mkwsFacet[data-mkws-facet='author'] div.mkwsTerm").length).toBeGreaterThan(1); @@ -374,7 +378,7 @@ describe("Check Source Facets", function () { $(".mkwsPager").bind("DOMNodeInserted DOMNodeRemoved propertychange", function () { waitcount++; - debug("DOM wait for stat: " + waitcount); + debug("DOM change mkwsPager, for stat: " + waitcount); }); }); @@ -576,28 +580,35 @@ describe("Check removable facets links", function () { runs(function () { $("div.mkwsRecords").bind("DOMNodeInserted DOMNodeRemoved propertychange", function () { waitcount++; - debug("DOM change for removeable: " + waitcount); + debug("DOM change mkwsRecords for removeable: " + waitcount); }); }); waitsFor(function () { return waitcount >= 2 && $("a.mkwsRemovable").length == 1 ? 1 : 0; - }, "Records DOM change, removable", 2 * jasmine_config.second); + }, "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 () { - // debug("wait for: " + waitcount); - return waitcount >= 4 && $("a.mkwsRemovable").length == 0 ? true : false; - }, "Records DOM change, removable2", 2 * jasmine_config.second); - + return waitcount >= 2 && $("a.mkwsRemovable").length == 0 ? true : false; + }, "DOM change mkwsRecords, removable2", 2 * jasmine_config.second); runs(function () { - debug("unbind removable"); + debug("unbind removable2"); $("div.mkwsRecords").unbind("DOMNodeInserted DOMNodeRemoved propertychange"); }); }); @@ -627,23 +638,21 @@ describe("Check per page options", function () { $("div.mkwsRecords").bind("DOMNodeInserted DOMNodeRemoved propertychange", function () { waitcount++; - debug("DOM wait for change, per page: " + waitcount); + debug("DOM change mkwsRecords, per page: " + waitcount); }); }); waitsFor(function () { - //debug("wait for: " + waitcount); - return waitcount >= (per_page_number * 2) ? true : false; - }, "Records DOM change, by per page", 3 * jasmine_config.second); + // 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 () { - $("div.mkwsRecords").unbind("DOMNodeInserted DOMNodeRemoved propertychange"); debug("unbind per page"); - }); + $("div.mkwsRecords").unbind("DOMNodeInserted DOMNodeRemoved propertychange"); - runs(function () { var records = $("div.mkwsRecords > div.mkwsSummary"); - debug("Got now " + records.length + " records"); + debug("Per page got now " + records.length + " records"); expect(records.length).toBe(per_page_number); }); }); @@ -667,7 +676,7 @@ describe("Check SortBy options", function () { var list = []; var terms = $("div.mkwsRecords > div.mkwsSummary > a"); for (var i = 0; i < terms.length; i++) { - var term = $(terms[i]).text(); + var term = $(terms[i]).text().trim(); list.push(term); // debug(prefix + "title: " + term); } @@ -677,7 +686,7 @@ describe("Check SortBy options", function () { runs(function () { $("div.mkwsRecords").bind("DOMNodeInserted DOMNodeRemoved propertychange", function () { waitcount++; - //debug("DOM wait for change, sort by: " + waitcount); + debug("DOM change mkwsRecords, sort by: " + waitcount); }); var select = $("select.mkwsSort option[selected='selected']"); @@ -691,17 +700,15 @@ describe("Check SortBy options", function () { waitsFor(function () { //debug("wait for2: " + waitcount); - return waitcount >= per_page_number ? true : false; - }, "Records DOM change, by sort page", 3 * jasmine_config.second); + 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 per page"); - }); + debug("unbind by sort"); - runs(function () { - var records = $("div.mkwsRecords > div.mkwsSummary a"); - debug("Got now " + records.length + " records"); + var records = $("div.mkwsRecords > div.mkwsSummary > a"); + debug("Sort by got now " + records.length + " records"); expect(records.length).toBe(per_page_number); }); @@ -709,7 +716,7 @@ describe("Check SortBy options", function () { var title_list_new = title_list("yyy "); var diff_flag = 0; for (var i = 0; i < title_list_old.length; i++) { - debug(title_list_old[i] + " :: " + title_list_new[i]); + debug((i+1) + ". " + title_list_old[i] + " :: " + title_list_new[i]); if (title_list_old[i] != title_list_new[i]) { diff_flag++; @@ -721,10 +728,29 @@ describe("Check SortBy options", function () { }); }); +describe("Check async widget discovery", function () { + var $ = mkws.$; + it("initialises a new widget", function() { + $("div.mkwsSearch").after('
'); + 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); + }); + }); +}); /* done */ describe("All tests are done", function () { it(">>> hooray <<<", function () { mkws.jasmine_done = true; + debug(">>> hooray <<<"); }); });