refactor: make a new test "Check record list", called before "Show record"
[mkws-moved-to-github.git] / test / spec / mkws-pazpar2.js
index 41ad086..d042366 100644 (file)
@@ -6,7 +6,7 @@
 
 // get references from mkws.js, lazy evaluation
 var debug = function (text) {
-        mkws.debug(text)
+        mkws.debug("Jasmine: " + text)
     }
 
     // Define empty mkws_config for simple applications that don't define it.
@@ -75,6 +75,27 @@ describe("Init jasmine config", function () {
     });
 });
 
+describe("Check MOTD before search", function () {
+    // 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
+    // now be emtpy
+    // Note that the testMOTD is a regular div, and uses #testMOTD,
+    // since the automagic class-making does not apply to it.
+    it("MOTD is hidden", function () {
+        expect($(".mkwsMOTD").length).toBe(1);
+        expect($("#testMOTD").length).toBe(1);
+        expect($("#testMOTD").text()).toMatch("^ *$");
+    });
+
+    it("mkwsMOTDContainer has received the text", function () {
+        expect($(".mkwsMOTDContainer").length).toBe(1);
+        expect($(".mkwsMOTDContainer").text()).toMatch(/MOTD/);
+    });
+
+
+});
+
 describe("Check pazpar2 search", function () {
     it("pazpar2 was successfully initialized", function () {
         expect(mkws_config.error).toBe(undefined);
@@ -105,12 +126,23 @@ describe("Check pazpar2 search", function () {
 
         runs(function () {
             debug("Click on submit button");
-            var click = $("input.mkwsButton").trigger("click");
-            expect(click.length).toBe(1);
+            $("input.mkwsButton").trigger("click");
         })
     });
 });
 
+describe("Check MOTD after search", function () {
+    it("MOTD is hidden", function () {
+        expect($(".mkwsMOTD").length).toBe(1);
+        expect($(".mkwsMOTD").is(":hidden")).toBe(true);
+        debug("motd " + $(".mkwsMOTD"));
+        debug("motd t=" + $(".mkwsMOTD").text());
+        debug("motd v=" + $(".mkwsMOTD").is(":visible"));
+        //expect($("div.mkwsBytarget").is(":visible")).toBe(true);
+    });
+});
+
+
 
 /*
  * This part runs in background. It should be rewritten with
@@ -125,10 +157,7 @@ describe("Check pazpar2 navigation", function () {
         function my_click(id, time) {
             setTimeout(function () {
                 debug("trigger click on id: " + id);
-                var click = $(id).trigger("click");
-
-                debug("next/prev: " + id + " click is success: " + click.length);
-                expect(click.length).toBe(1);
+                $(id).trigger("click");
             }, time * jasmine_config.second);
         }
 
@@ -227,10 +256,13 @@ describe("Check Termlist", function () {
                 break;
             }
         }
+        if ($("div.mkwsFacetAuthors div.term:nth-child(" + author_number + ") a").text().length == 0) {
+            debug("No good authors found. Not clicking on the bad ones");
+            return;
+        }
 
-        var click = $("div.mkwsFacetAuthors div.term:nth-child(" + author_number + ") a").trigger("click");
-        debug("limit author click is success: " + click.length);
-        expect(click.length).toBe(1);
+        debug("Clicking on author (" + author_number + ") " + $("div.mkwsFacetAuthors div.term:nth-child(" + author_number + ") a").text());
+        $("div.mkwsFacetAuthors div.term:nth-child(" + author_number + ") a").trigger("click");
 
         waitsFor(function () {
             return get_hit_counter() < hits_all_targets ? true : false;
@@ -258,9 +290,7 @@ describe("Check Termlist", function () {
             }
         }
 
-        var click = $("div.mkwsFacetSources div.term:nth-child(" + source_number + ") a").trigger("click");
-        debug("limit source click " + (source_number - 1) + " is success: " + click.length);
-        expect(click.length).toBe(1);
+        $("div.mkwsFacetSources div.term:nth-child(" + source_number + ") a").trigger("click");
 
         waitsFor(function () {
             if ($("div.mkwsNavi").length && $("div.mkwsNavi").text().match(/(Source|datenquelle|kilder): /i)) {
@@ -284,6 +314,28 @@ describe("Check Termlist", function () {
     });
 });
 
+describe("Check record list", function () {
+    it("got a record", function () {
+        // make sure we have a link.
+        var linkaddr = "div.mkwsRecords div.record:nth-child(1) a";
+        var waitcount = 0;
+
+        waitsFor(function () {
+            waitcount++;
+            debug("waiting for the link " + waitcount + " " + $(linkaddr) + " =" + $(linkaddr).length + " " + $(linkaddr).text());
+            return ($(linkaddr).length > 0);
+        }, "wait until we see a link", 1 * jasmine_config.second);
+
+        runs(function () {
+            var link = $(linkaddr);
+            debug("== waited (" + waitcount + ") for the link..." + $(linkaddr) + " =" + $(linkaddr).length + " " + $(linkaddr).text());
+            expect(link.length).toBe(1);
+            // link.trigger("click");
+        });
+    });
+});
+
+
 describe("Show record", function () {
     var record_number = 1; // the Nth record in hit list
     it("show record author", function () {
@@ -330,9 +382,7 @@ describe("Check switch menu Records/Targets", function () {
     });
 
     it("switch to target view", function () {
-        var click = $("div.mkwsSwitch").children('a').eq(1).trigger("click");
-        debug("target view click is success: " + click.length);
-        expect(click.length).toBe(1);
+        $("div.mkwsSwitch").children('a').eq(1).trigger("click");
 
         // now the target table must be visible
         expect($("div.mkwsBytarget").is(":visible")).toBe(true);
@@ -351,9 +401,7 @@ describe("Check switch menu Records/Targets", function () {
     });
 
     it("switch back to record view", function () {
-        var click = $("div.mkwsSwitch").children('a').eq(0).trigger("click");
-        debug("record view click is success: " + click.length);
-        expect(click.length).toBe(1);
+        $("div.mkwsSwitch").children('a').eq(0).trigger("click");
 
         // now the target table must be visible
         expect($("div.mkwsBytarget").is(":visible")).toBe(false);