Fix broken glimpse button compatibility

dac5f133b17d2d948d1320fd30c2ee2e798789be broke the E2E tests by removing
the glimpse id and making it a class instead.

This change makes both versions work and also foresees that "cutoff"
might disappear at some point.

Change-Id: Iea3251a466500e30e88e5e78bed35e6bb00dd602
diff --git a/lib/korap_rc.js b/lib/korap_rc.js
index a628dbf..5a650a4 100644
--- a/lib/korap_rc.js
+++ b/lib/korap_rc.js
@@ -159,10 +159,43 @@
     }
 
     async assure_glimpse_off(page) {
+        // Get the cutoff checkbox - works in both old and new Kalamar versions
         const glimpse = await page.$("input[name=cutoff]")
+        if (!glimpse) {
+            console.log("Glimpse checkbox not found, skipping")
+            return
+        }
         const glimpse_value = await (await glimpse.getProperty('checked')).jsonValue()
         if (glimpse_value) {
-            await page.click("#glimpse")
+            // Try new Kalamar version first (toggle button with class 'glimpse')
+            const newGlimpseButton = await page.$(".glimpse")
+            if (newGlimpseButton) {
+                const isVisible = await page.evaluate(el => {
+                    const style = window.getComputedStyle(el)
+                    return style.display !== 'none' && style.visibility !== 'hidden'
+                }, newGlimpseButton)
+                if (isVisible) {
+                    await newGlimpseButton.click()
+                    return
+                }
+            }
+            // Fall back to old Kalamar version (label with id 'glimpse')
+            const oldGlimpseLabel = await page.$("#glimpse")
+            if (oldGlimpseLabel) {
+                const isVisible = await page.evaluate(el => {
+                    const style = window.getComputedStyle(el.parentNode || el)
+                    return style.display !== 'none' && style.visibility !== 'hidden'
+                }, oldGlimpseLabel)
+                if (isVisible) {
+                    await page.click("#glimpse")
+                    return
+                }
+            }
+            // Last resort: directly toggle the checkbox via JavaScript
+            await page.evaluate(() => {
+                const checkbox = document.querySelector("input[name=cutoff]")
+                if (checkbox) checkbox.checked = false
+            })
         }
     }