1 /* Copyright (c) 2013 IndexData ApS. http://indexdata.com
3 * perform papzpar2 / pz2.js search & retrieve request in the browser
7 describe("Check pazpar2 search", function () {
8 it("pazpar2 was successfully initialize", function () {
9 expect(mkws_config.error).toBe(undefined);
12 it("validate HTML id's", function () {
13 expect($("input#mkwsQuery").length == 1).toBe(true);
14 expect($("input#mkwsButton").length == 1).toBe(true);
16 expect($("#mkwsNext").length == 1).toBe(false);
17 expect($("#mkwsPrev").length == 1).toBe(false);
20 it("run search query", function () {
21 $("input#mkwsQuery").val("freebsd");
22 expect($("input#mkwsQuery").val()).toMatch(/^freebsd$/);
24 setTimeout(function () {
25 $("input#mkwsButton").trigger("click");
31 describe("Check pazpar2 navigation", function () {
33 it("check running search next/prev", function () {
34 expect($("#mkwsPager").length == 1).toBe(true);
36 function my_click(id, time) {
37 setTimeout(function () {
38 debug("trigger click on id: " + id);
39 var click = $(id).trigger("click");
41 debug("next click is success: " + click.length);
42 expect(click.length == 1).toBe(true);
48 // click next/prev after N seconds
49 my_click("#mkwsNext", 7);
50 my_click("#mkwsNext", 8);
51 my_click("#mkwsPrev", 9);
57 describe("Check pazpar2 hit counter", function () {
58 function get_hit_counter() {
59 if ($("#mkwsPager").length == 0) return -1;
61 var found = $("#mkwsPager").text();
62 var re = /found: ([0-9]+)/;
67 hits = parseInt(RegExp.$1);
68 expect(hits).toBeGreaterThan(0);
71 debug("Hits: " + hits);
75 function show_record() {
76 it("Show record", function () {
77 var click = $("div#mkwsRecords div.record:nth-child(3) :nth-child(2)").trigger("click");
78 debug("show click is success: " + click.length);
79 expect(click.length == 1).toBe(true);
83 it("check running search hit counter", function () {
84 var max_time = 10; // in seconds
85 var expected_hits = 116; //
89 function found(time, none) {
90 setTimeout(function () {
92 hits = get_hit_counter();
94 // debug("found: " + found);
96 expect(hits < 0).toBeTruthy();
101 debug("mkws pager found records: '" + hits + "'");
102 debug("time state: " + j_time);
104 expect(time >= 0).toBeTruthy();
109 // check hit counter after N seconds
117 waitsFor(function () {
118 return j_time == max_time ? true : false;
119 }, "The Value should be 20 seconds", max_time * 1000);
123 expect($("#mkwsPager").length == 1).toBe(true);
127 expect(j_time <= max_time).toBeTruthy();
128 expect(j_hits).toBeGreaterThan(expected_hits);
133 it("found Termlist", function () {
134 var termlist = $("div#mkwsTermlists");
135 debug("Termlist success: " + termlist.length);
136 expect(termlist.length == 1).toBe(true);
138 var sources = $("div#mkwsFacetSources");
139 expect(sources.length == 1).toBe(true);
141 var subjects = $("div#mkwsFacetSubjects");
142 expect(subjects.length == 1).toBe(true);
144 var authors = $("div#mkwsFacetAuthors");
145 expect(authors.length == 1).toBe(true);
149 it("Limit search to first source", function () {
150 var hits_all_targets = get_hit_counter();
152 var click = $("div#mkwsFacetSources div.term:nth-child(2) a").trigger("click");
153 debug("limit source click is success: " + click.length);
154 expect(click.length == 1).toBe(true);
156 waitsFor(function () {
157 if ($("div#mkwsNavi").length && $("div#mkwsNavi").text().match(/^Source/)) {
162 }, "Search for source in navi bar", 1000);
164 waitsFor(function () {
165 return get_hit_counter() < hits_all_targets ? true : false;
166 }, "Search for with less hits", 9 * 1000);
169 var hits_single_target = get_hit_counter();
170 debug("get less hits for sources: " + hits_all_targets + " > " + hits_single_target);
171 expect(hits_all_targets).toBeGreaterThan(hits_single_target);
176 it("Limit search to first author", function () {
177 var hits_all_targets = get_hit_counter();
179 var click = $("div#mkwsFacetAuthors div.term:nth-child(2) a").trigger("click");
180 debug("limit author click is success: " + click.length);
181 expect(click.length == 1).toBe(true);
183 waitsFor(function () {
184 return get_hit_counter() < hits_all_targets ? true : false;
185 }, "Search for with less hits", 9 * 1000);
188 var hits_single_target = get_hit_counter();
189 debug("get less hits for authors: " + hits_all_targets + " > " + hits_single_target);
190 expect(hits_all_targets).toBeGreaterThan(hits_single_target);