Fix race condition in "Show record" MKWS-137
authorHeikki Levanto <heikki@indexdata.dk>
Fri, 7 Mar 2014 14:32:42 +0000 (15:32 +0100)
committerHeikki Levanto <heikki@indexdata.dk>
Fri, 7 Mar 2014 14:32:42 +0000 (15:32 +0100)
test/spec/mkws-pazpar2.js

index e459931..50dfa94 100644 (file)
@@ -312,7 +312,24 @@ describe("Check Termlist", function () {
 describe("Show record", function () {
     var record_number = 1; // the Nth record in hit list
     it("show record author", function () {
 describe("Show record", function () {
     var record_number = 1; // the Nth record in hit list
     it("show record author", function () {
-        $("div.mkwsRecords div.record:nth-child(" + record_number + ") a").trigger("click");
+        // 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");
+        });
+        
         // wait until the record pops up
         waitsFor(function () {
             var show = $("div.mkwsRecords div.record:nth-child(" + record_number + ") div");
         // wait until the record pops up
         waitsFor(function () {
             var show = $("div.mkwsRecords div.record:nth-child(" + record_number + ") div");