disable final test, will bock further manual tests on the page
[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     it("check running search hit counter", function () {
59         var max_time = 10; // in seconds
60         var expected_hits = 116; //
61         var j_time = 0;
62         var j_hits = 0;
63
64         function found(time, none) {
65             setTimeout(function () {
66                 j_time = time;
67
68                 var found = $("#mkwsPager").text();
69                 var re = /found: ([0-9]+)/;
70                 re.exec(found);
71                 var hits = -1;
72
73                 if (RegExp.$1) {
74                     hits = RegExp.$1;
75                     expect(hits).toBeGreaterThan(0);
76                 }
77
78                 // debug("found: " + found);
79                 if (none) {
80                     expect(hits < 0).toBeTruthy();
81                 } else {
82                     j_hits = hits;
83                 }
84
85                 debug("mkws pager found records: '" + hits + "'");
86                 debug("time state: " + j_time);
87
88                 expect(time >= 0).toBeTruthy();
89             }, time * 1000);
90         }
91
92         runs(function () {
93             // check hit counter after N seconds
94             found(0, true);
95             found(3);
96             found(6);
97             found(8);
98             found(max_time);
99         });
100
101         waitsFor(function () {
102             return j_time == max_time ? true : false;
103         }, "The Value should be 20 seconds", max_time * 1000);
104
105
106         runs(function () {
107             expect($("#mkwsPager").length == 1).toBe(true);
108         })
109
110         runs(function () {
111             expect(j_time <= max_time).toBeTruthy();
112             expect(j_hits).toBeGreaterThan(expected_hits);
113         });
114     });
115
116     it("Show record", function () {
117         var click = $("div#mkwsRecords div.record:nth-child(3) :nth-child(2)").trigger("click");
118         debug("show click is success: " + click.length);
119         expect(click.length == 1).toBe(true);
120     });
121
122     /*
123     it("Final success message in search input field", function () {
124         $("input#mkwsQuery").val("jasmine test is done");
125         expect($("input#mkwsQuery").val()).toMatch(/done/);
126     });
127     */
128 });