Don't show random page option for single page results

Change-Id: I2ec9177a9aa78cb0f0bc0f1cd8791191bdc29ce4
diff --git a/Changes b/Changes
index 94eceaa..fa72308 100644
--- a/Changes
+++ b/Changes
@@ -2,6 +2,8 @@
         - Support VCs via URL without queries (diewald)
         - Added translations for regexp and FCSQL (r-wilm)
         - Introduce 'ui-ready' global event. (diewald)
+        - Don't show random page option for single page
+          results (diewald)
 
 0.56 2024-09-23
         - Improve slim test for plugin support
diff --git a/dev/js/spec/panelSpec.js b/dev/js/spec/panelSpec.js
index 9799b07..b9047eb 100644
--- a/dev/js/spec/panelSpec.js
+++ b/dev/js/spec/panelSpec.js
@@ -208,7 +208,7 @@
       expect(list.classList.contains('button-group-list')).toBeTruthy();
       expect(list.classList.contains('visible')).toBeFalsy();
 
-      pagination.addRandomPage();
+      expect(pagination.addRandomPage()).toBeTruthy();
 
       let clicked = false;
       pagination.actions().add(
@@ -225,5 +225,27 @@
       document.body.removeChild(p);
       document.body.removeChild(pagination.actions().element());
     });
+
+    it('shouldn\'t show random page on single pages', function () {
+
+      // Create pagination element for pagination information
+      let p = document.createElement('div');
+      p.setAttribute('id', 'pagination')
+      p.setAttribute('data-page',1);
+      p.setAttribute('data-total',1);
+      p.setAttribute('data-count',25);
+
+      document.body.appendChild(p);
+
+      // Create pagination class object
+      var pagination = paginationClass.create();
+      let list = pagination.actions().element();
+      expect(pagination.type).toEqual('pagination');
+      expect(list.classList.contains('button-group-list')).toBeTruthy();
+      expect(list.classList.contains('visible')).toBeFalsy();
+
+      expect(pagination.addRandomPage()).toBeFalsy();
+    });
+
   });
 });
diff --git a/dev/js/src/panel/pagination.js b/dev/js/src/panel/pagination.js
index dd3331c..03c5258 100644
--- a/dev/js/src/panel/pagination.js
+++ b/dev/js/src/panel/pagination.js
@@ -16,7 +16,6 @@
   // Localization values
   const loc = KorAP.Locale;
   loc.RANDOM_PAGE = loc.RANDOM_PAGE || 'Random page';
-
   
   return {
     type : 'pagination',
@@ -77,18 +76,23 @@
      */
     addRandomPage : function () {
       const pi = pageInfoClass.create();
-      
+
+      if (pi.total() < 2)
+        return false;
+
       const button = this.actions().add(
         loc.RANDOM_PAGE,
         {},
         function () {
-          if (pi.total() > 0) {
+          if (pi.total() > 1) {
             const sp = new URLSearchParams(window.location.search);
             sp.set("p", Math.floor(Math.random() * pi.total()) + 1);
             window.location.search = sp.toString();
           };
         }
-      )
+      );
+
+      return true;
     }
   }
 });