TagSpaces is an offline, open source, document manager with tagging support
chore: fix test for background image in grid
Ilian Sapundshiev560836f39181
diff --git a/tests/e2e/folderprops.pw.e2e.js b/tests/e2e/folderprops.pw.e2e.jsindex 4495996b2..d6358737a 100644--- a/tests/e2e/folderprops.pw.e2e.js+++ b/tests/e2e/folderprops.pw.e2e.js@@ -18,10 +18,11 @@ import {getAttribute,getElementScreenshot,getGridFileSelector,+ isBackgroundImageLoaded,openFolder,openFolderProp,setInputValue,- waitUntilChanged,+ waitUntilChanged} from './general.helpers';import {createFileS3,@@ -415,10 +416,8 @@ test.describe('TST02 - Folder properties', () => {await openFolder('empty_folder');const targetSelector = '[data-tid=backgroundTID]>div'; //'[data-tid=perspectiveGridFileTable]';- const screenshotSelector = '[data-tid=perspectiveGridFileTable]';- const initScreenshot = await getElementScreenshot(screenshotSelector);- const initStyle = await getAttribute(targetSelector, 'style');+ // Set backgroundawait clickOn('[data-tid=changeBackgroundImageTID]');await clickOn('ul[data-tid=predefinedBackgroundsTID] > li');@@ -428,19 +427,15 @@ test.describe('TST02 - Folder properties', () => {5000,);await clickOn('[data-tid=colorPickerConfirm]');- // Wait for background-image style change- await waitUntilChanged(targetSelector, initStyle, 'style', 8000);- const withBgnScreenshot = await getElementScreenshot(screenshotSelector);- expect(initScreenshot).not.toBe(withBgnScreenshot);- const bgStyle = await getAttribute(targetSelector, 'style');+ const loaded = await isBackgroundImageLoaded(targetSelector);+ expect(loaded).toBe(true);// Remove backgroundawait clickOn('[data-tid=changeBackgroundImageTID]');await clickOn('[data-tid=clearBackground]');- await waitUntilChanged(targetSelector, bgStyle, 'style', 8000);+ const loaded2 = await isBackgroundImageLoaded(targetSelector);+ expect(loaded2).toBe(false);- const bgnRemovedScreenshot = await getElementScreenshot(screenshotSelector);- expect(initScreenshot).toBe(bgnRemovedScreenshot);});});diff --git a/tests/e2e/general.helpers.js b/tests/e2e/general.helpers.jsindex 25ef0972e..a1e50ad3e 100644--- a/tests/e2e/general.helpers.js+++ b/tests/e2e/general.helpers.js@@ -112,6 +112,48 @@ export async function waitUntilChanged(return await element.getAttribute(attribute);}+/**+ * Checks if a locator has a background-image property that resolves to a loadable URL.+ * @param {string} locator+ * @returns {Promise<boolean>}+ */+export async function isBackgroundImageLoaded(targetSelector) {+ const locator = global.client.locator(targetSelector);+ return await locator.evaluate((el) => {++ const style = window.getComputedStyle(el);+ const bgImage = style.backgroundImage;++ // 1. Check if property exists and is not 'none'+ if (!bgImage || bgImage === 'none') {+ return false;+ }++ // 2. Extract URL (Handles quotes/no-quotes: url("...") or url(...))+ // Note: This grabs the first URL if multiple backgrounds exist+ const urlMatch = bgImage.match(/url\(["']?(.*?)["']?\)/);++ // If no URL found (e.g., it's a linear-gradient), return false+ if (!urlMatch) return false;++ const url = urlMatch[1];++ // 3. Verify image loads+ return new Promise((resolve) => {+ const img = new Image();+ img.src = url;++ // Check if already cached/complete+ if (img.complete && img.naturalWidth > 0) return resolve(true);++ img.onload = () => resolve(img.naturalWidth > 0);+ img.onerror = () => resolve(false);+ });+ });+}+++// Utility to get style attributeexport async function getAttribute(selector, attribute = 'style') {return await global.client