limit to author search
[mkws-moved-to-github.git] / test / spec / mkws-pazpar2.js
1 /* Copyright (c) 2013 IndexData ApS. http://indexdata.com
2  *
3  * perform papzpar2 / pz2.js search & retrieve request in the browser
4  *
5  */
6
7 describe("Check pazpar2 search", function () {
8     it("pazpar2 was successfully initialize", function () {
9         expect(mkws_config.error).toBe(undefined);
10     });
11
12     it("validate HTML id's", function () {
13         expect($("input#mkwsQuery").length == 1).toBe(true);
14         expect($("input#mkwsButton").length == 1).toBe(true);
15
16         expect($("#mkwsNext").length == 1).toBe(false);
17         expect($("#mkwsPrev").length == 1).toBe(false);
18     });
19
20     it("run search query", function () {
21         $("input#mkwsQuery").val("freebsd");
22         expect($("input#mkwsQuery").val()).toMatch(/^freebsd$/);
23
24         setTimeout(function () {
25             $("input#mkwsButton").trigger("click");
26         }, 3 * 1000);
27     });
28 });
29
30
31 describe("Check pazpar2 navigation", function () {
32     // Asynchronous part
33     it("check running search next/prev", function () {
34         expect($("#mkwsPager").length == 1).toBe(true);
35
36         function my_click(id, time) {
37             setTimeout(function () {
38                 debug("trigger click on id: " + id);
39                 var click = $(id).trigger("click");
40
41                 debug("next click is success: " + click.length);
42                 expect(click.length == 1).toBe(true);
43
44             }, time * 1000);
45         }
46
47         runs(function () {
48             // click next/prev after N seconds
49             my_click("#mkwsNext", 7);
50             my_click("#mkwsNext", 8);
51             my_click("#mkwsPrev", 9);
52         });
53     });
54 });
55
56
57 describe("Check pazpar2 hit counter", function () {
58     function get_hit_counter() {
59         if ($("#mkwsPager").length == 0) return -1;
60
61         var found = $("#mkwsPager").text();
62         var re = /found: ([0-9]+)/;
63         re.exec(found);
64         var hits = -1;
65
66         if (RegExp.$1) {
67             hits = parseInt(RegExp.$1);
68             expect(hits).toBeGreaterThan(0);
69         }
70
71         debug("Hits: " + hits);
72         return hits;
73     }
74
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);
80         });
81     }
82
83     it("check running search hit counter", function () {
84         var max_time = 10; // in seconds
85         var expected_hits = 116; //
86         var j_time = 0;
87         var j_hits = 0;
88
89         function found(time, none) {
90             setTimeout(function () {
91                 j_time = time;
92                 hits = get_hit_counter();
93
94                 // debug("found: " + found);
95                 if (none) {
96                     expect(hits < 0).toBeTruthy();
97                 } else {
98                     j_hits = hits;
99                 }
100
101                 debug("mkws pager found records: '" + hits + "'");
102                 debug("time state: " + j_time);
103
104                 expect(time >= 0).toBeTruthy();
105             }, time * 1000);
106         }
107
108         runs(function () {
109             // check hit counter after N seconds
110             found(0, true);
111             found(3);
112             found(6);
113             found(8);
114             found(max_time);
115         });
116
117         waitsFor(function () {
118             return j_time == max_time ? true : false;
119         }, "The Value should be 20 seconds", max_time * 1000);
120
121
122         runs(function () {
123             expect($("#mkwsPager").length == 1).toBe(true);
124         })
125
126         runs(function () {
127             expect(j_time <= max_time).toBeTruthy();
128             expect(j_hits).toBeGreaterThan(expected_hits);
129         });
130     });
131
132     // show_record();
133     it("found Termlist", function () {
134         var termlist = $("div#mkwsTermlists");
135         debug("Termlist success: " + termlist.length);
136         expect(termlist.length == 1).toBe(true);
137
138         var sources = $("div#mkwsFacetSources");
139         expect(sources.length == 1).toBe(true);
140
141         var subjects = $("div#mkwsFacetSubjects");
142         expect(subjects.length == 1).toBe(true);
143
144         var authors = $("div#mkwsFacetAuthors");
145         expect(authors.length == 1).toBe(true);
146     });
147
148     // show_record();
149     it("Limit search to first source", function () {
150         var hits_all_targets = get_hit_counter();
151
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);
155
156         waitsFor(function () {
157             if ($("div#mkwsNavi").length && $("div#mkwsNavi").text().match(/^Source/)) {
158                 return true;
159             } else {
160                 return false;
161             }
162         }, "Search for source in navi bar", 1000);
163
164         waitsFor(function () {
165             return get_hit_counter() < hits_all_targets ? true : false;
166         }, "Search for with less hits", 9 * 1000);
167
168         runs(function () {
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);
172         });
173     });
174
175     // show_record();
176     it("Limit search to first author", function () {
177         var hits_all_targets = get_hit_counter();
178
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);
182
183         waitsFor(function () {
184             return get_hit_counter() < hits_all_targets ? true : false;
185         }, "Search for with less hits", 9 * 1000);
186
187         runs(function () {
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);
191         });
192     });
193
194     // show_record();
195 });