diff --git a/.github/workflows/ci-testing.yml b/.github/workflows/ci-testing.yml index fec1418..e288d39 100644 --- a/.github/workflows/ci-testing.yml +++ b/.github/workflows/ci-testing.yml @@ -11,11 +11,15 @@ jobs: - uses: actions/checkout@v4 - name: Use Node.js uses: actions/setup-node@v4 - with: - node-version: latest -# - run: sudo apt-get install xvfb -# - run: npm install -# - run: npx playwright install -# - run: xvfb-run --auto-servernum -- npm test - env: - CI: true + with: + node-version: latest + - name: Install XVFB + run: sudo apt-get install -y xvfb + - name: Install Dependencies + run: npm install + - name: Install Playwright + run: npx playwright install + - name: Run Tests with XVFB + run: xvfb-run --auto-servernum -- npm test + env: + CI: true diff --git a/src/background.js b/src/background.js index ade3fc5..a7f1515 100644 --- a/src/background.js +++ b/src/background.js @@ -86,8 +86,7 @@ chrome.runtime.onInstalled.addListener(async () => { featureIndexOverlayOption: false, renderMap: true, defaultExtCoor: 'pcrs', - defaultLocCoor: 'gcrs', - defaultContentPreference: 'no-preference' + defaultLocCoor: 'gcrs' } }); registerContentScripts(); diff --git a/src/popup.html b/src/popup.html index 812e714..6272903 100644 --- a/src/popup.html +++ b/src/popup.html @@ -63,12 +63,10 @@
Accessibility Settings
Content Preferences
- - + -
diff --git a/src/popup.js b/src/popup.js index 5eadd7f..aaba68f 100644 --- a/src/popup.js +++ b/src/popup.js @@ -22,8 +22,7 @@ function loadOptions() { featureIndexOverlayOption: false, renderMap: false, defaultExtCoor: 'pcrs', - defaultLocCoor: 'gcrs', - defaultContentPreference: 'no-preference' + defaultLocCoor: 'gcrs' }; for (let name in options) { let elem = document.getElementById(name); @@ -36,6 +35,15 @@ function loadOptions() { Array.from(elem.children).forEach(el => el.value === options[name]? el.selected = true : el.selected = false); break; + case "object": + if (Array.isArray(options[name])) { + Array.from(elem.children).forEach(o => { + if (options[name].includes(o.value)) { + o.defaultSelected = true; + } + }); + } + break; } } } @@ -55,7 +63,11 @@ function handleCheckboxChange(e) { function handleDropdownChange(e) { let option = e.target.id; - options[option] = Array.from(e.target.children).find(el => el.selected).value; + if (option === 'contentPreference') { + options[option] = Array.from(e.target.children).filter(el => el.selected).map( el => el.value); + } else { + options[option] = Array.from(e.target.children).find(el => el.selected).value; + } saveOptions(); } diff --git a/test/e2e/basics/locale.html b/test/e2e/basics/locale.html index 05fb00d..879387c 100644 --- a/test/e2e/basics/locale.html +++ b/test/e2e/basics/locale.html @@ -1,5 +1,9 @@ - + + + Static Features Test diff --git a/test/e2e/basics/locale.test.js b/test/e2e/basics/locale.test.js index bd4fc50..e24753a 100644 --- a/test/e2e/basics/locale.test.js +++ b/test/e2e/basics/locale.test.js @@ -38,44 +38,44 @@ test.describe("Locale Tests", () => { expect(zoomInTitle).toBe("Zoom in"); expect(zoomOutTitle).toBe("Zoom out"); expect(reloadTitle).toBe("Reload"); - expect(fullScreenTitle).toBe("View Fullscreen"); + expect(fullScreenTitle).toBe("View fullscreen"); }); }); test.describe("Other Locale Tests", () => { - let frContext, frPage; + let svContext, svPage; test.beforeAll(async () => { let pathToExtension = path.join(__dirname, '../../../src/'); - - frContext = await chromium.launchPersistentContext("",{ + // update to swedish because en and fr locales are 'forced' by the lang attribute + svContext = await chromium.launchPersistentContext("",{locale: 'sv', headless: false, slowMo: 50, args: [ - '--lang=fr', + '--lang=sv', `--disable-extensions-except=${pathToExtension}`, `--load-extension=${pathToExtension}` - ], + ] }); - let [background] = frContext.serviceWorkers(); + let [background] = svContext.serviceWorkers(); if (!background) - background = await frContext.waitForEvent("serviceworker"); + background = await svContext.waitForEvent("serviceworker"); const id = background.url().split("/")[2]; - let newPage = await frContext.newPage(); + let newPage = await svContext.newPage(); await newPage.goto('chrome-extension://' + id +'/popup.html', {waitUntil: "load"}); - frPage = await frContext.newPage(); - await frPage.goto("test/e2e/basics/locale.html", {waitUntil: "load"}); + svPage = await svContext.newPage(); + await svPage.goto("test/e2e/basics/locale.html", {waitUntil: "load"}); }); test.afterAll(async () => { - await frContext.close(); + await svContext.close(); }); test("UI button titles", async () => { - let reloadTitle = await frPage.$eval( + let reloadTitle = await svPage.$eval( "xpath=//html/body/mapml-viewer >> css=div > div.leaflet-control-container > div.leaflet-top.leaflet-left > div.mapml-reload-button.leaflet-bar.leaflet-control > button", (tile) => tile.title ); - expect(reloadTitle).toBe("Rechargez"); + expect(reloadTitle).toBe("Läs In Igen"); }); }); diff --git a/test/e2e/basics/popup.test.js b/test/e2e/basics/popup.test.js index 0285394..022880a 100644 --- a/test/e2e/basics/popup.test.js +++ b/test/e2e/basics/popup.test.js @@ -92,14 +92,18 @@ test.describe("Popup test", () => { let newPage = await context.newPage(); await newPage.goto("test/e2e/basics/popup.test.html", { waitUntil: "load" }); - newPage.waitForTimeout(500); + await newPage.waitForTimeout(1000); await newPage.click("body > mapml-viewer"); await newPage.keyboard.press("Shift+F10"); await newPage.keyboard.press("Tab"); + await newPage.waitForTimeout(100); await newPage.keyboard.press("Enter"); await newPage.keyboard.press("Tab"); + await newPage.waitForTimeout(100); await newPage.keyboard.press("Tab"); + await newPage.waitForTimeout(100); await newPage.keyboard.press("Enter"); + await newPage.waitForTimeout(100); const text = await newPage.evaluate(() => navigator.clipboard.readText()); const coordinates = await newPage.evaluate((t) => { @@ -119,7 +123,7 @@ test.describe("Popup test", () => { let newPage = await context.newPage(); await newPage.goto("test/e2e/basics/popup.test.html", { waitUntil: "load" }); - newPage.waitForTimeout(500); + await newPage.waitForTimeout(500); await newPage.click("body > mapml-viewer"); await newPage.keyboard.press("Shift+F10"); await newPage.keyboard.press("Tab"); diff --git a/test/e2e/basics/preferred-content.html b/test/e2e/basics/preferred-content.html index 3fd10ee..55a5c70 100644 --- a/test/e2e/basics/preferred-content.html +++ b/test/e2e/basics/preferred-content.html @@ -5,9 +5,26 @@ Preferred Content Test + - + diff --git a/test/e2e/basics/preferred-content.test.js b/test/e2e/basics/preferred-content.test.js index 36f6635..ed1ce22 100644 --- a/test/e2e/basics/preferred-content.test.js +++ b/test/e2e/basics/preferred-content.test.js @@ -34,6 +34,7 @@ test.describe("Preferred content test", () => { test("User prefers feature content type", async () => { // "page" is the extension popup, hasn't been closed so still open in a // browser tab somewhere... + await page.bringToFront(); await page.keyboard.press("Tab"); await page.keyboard.press("Tab"); await page.keyboard.press("Tab"); @@ -55,5 +56,56 @@ test.describe("Preferred content test", () => { const label = await layer.evaluate((l) => l._layerControlLabel.textContent); expect(label).toEqual('Feature content'); }); + + test("Multiple preferences can be expressed by user", async () => { + await page.bringToFront(); + await page.keyboard.press("Tab"); + await page.keyboard.press("Tab"); + await page.keyboard.press("Tab"); + await page.keyboard.press("Tab"); + await page.keyboard.press("Tab"); + await page.keyboard.press("Tab"); + await page.keyboard.press("Tab"); + await page.keyboard.press("Tab"); + // features is currently selected, so need a tricky set of key presses + await page.keyboard.press("ArrowUp"); + await page.keyboard.press("ArrowUp"); + await page.keyboard.press("Shift+ArrowDown"); + await page.keyboard.press("Shift+ArrowDown"); + await page.keyboard.press("Shift+ArrowDown"); + let newPage = await context.newPage(); + await newPage.goto("test/e2e/basics/preferred-content.html", { waitUntil: "domcontentloaded" }); + await newPage.waitForTimeout(1000); + let map = newPage.getByTestId('viewer'); + const matches = await map.evaluate((map)=>{ + return map.matchMedia('(prefers-map-content: image) and (prefers-map-content: tile) and (prefers-map-content: feature) and (prefers-map-content: table)').matches; + }); + expect(matches).toBe(true); + }); + test("Multiple disjoint preferences can be expressed by user", async () => { + await page.bringToFront(); + await page.keyboard.press("Tab"); + await page.keyboard.press("Tab"); + await page.keyboard.press("Tab"); + await page.keyboard.press("Tab"); + await page.keyboard.press("Tab"); + await page.keyboard.press("Tab"); + await page.keyboard.press("Tab"); + await page.keyboard.press("Tab"); + await page.keyboard.press("ArrowUp"); + await page.keyboard.press("ArrowUp"); + await page.keyboard.press(" "); // select tiles option + await page.keyboard.press("Control+ArrowDown"); + await page.keyboard.press("Control+ArrowDown"); + await page.keyboard.press(" "); // select tables option + let newPage = await context.newPage(); + await newPage.goto("test/e2e/basics/preferred-content.html", { waitUntil: "domcontentloaded" }); + await newPage.waitForTimeout(1000); + let map = newPage.getByTestId('viewer'); + const matches = await map.evaluate((map)=>{ + return map.matchMedia('(not (prefers-map-content: image)) and (prefers-map-content: tile) and (not (prefers-map-content: feature)) and (prefers-map-content: table)').matches; + }); + expect(matches).toBe(true); + }); }); diff --git a/test/e2e/basics/render.test.js b/test/e2e/basics/render.test.js index edd20b0..54643de 100644 --- a/test/e2e/basics/render.test.js +++ b/test/e2e/basics/render.test.js @@ -49,7 +49,7 @@ test.describe("Render MapML resources test", () => { await page.keyboard.press("Equal"); await page.waitForTimeout(1000); } - await page.waitForTimeout(500); + await page.waitForTimeout(1000); expect(page.url()).toContain("#5,-89.7827040843159,60.27815582468662"); await page.goBack({waitUntil: "networkidle"}); expect(page.url()).toContain("about:blank"); @@ -79,14 +79,6 @@ test.describe("Render MapML resources test", () => { }); test("Render map from text/mapml document", async () => { - //Changes page.goto response (initial page load) to be of content type text/mapml - await page.route("test/e2e/basics/test.mapml", async route => { - const response = await page.request.fetch("test/e2e/basics/test.mapml"); - await route.fulfill({ - body: await response.body(), - contentType: 'text/mapml' - }); - }); await page.goto("test/e2e/basics/test.mapml"); const map = await page.waitForFunction(() => document.querySelector("mapml-viewer")); @@ -134,14 +126,6 @@ test.describe("Render MapML resources test", () => { }); test("Projection defaults to OSMTILE in the case of unknown projection", async () => { - //Changes page.goto response (initial page load) to be of content type text/mapml - await page.route("test/e2e/basics/unknown_projection.mapml", async route => { - const response = await page.request.fetch("test/e2e/basics/unknown_projection.mapml"); - await route.fulfill({ - body: await response.body(), - contentType: 'text/mapml' - }); - }); await page.goto("test/e2e/basics/unknown_projection.mapml"); const map = await page.waitForFunction(() => document.querySelector("mapml-viewer")); const projection = await map.getAttribute('projection'); @@ -149,14 +133,6 @@ test.describe("Render MapML resources test", () => { }, {times: 1}); test.skip("Projection from map-meta[content*=projection] attribute / mime type parameter", async () => { - //Changes page.goto response (initial page load) to be of content type text/mapml - await page.route("test/e2e/basics/content-type-projection.mapml", async route => { - const response = await page.request.fetch("test/e2e/basics/content-type-projection.mapml"); - await route.fulfill({ - body: await response.body(), - contentType: 'text/mapml' - }); - }); await page.waitForTimeout(1000); await page.goto("test/e2e/basics/content-type-projection.mapml"); await page.waitForTimeout(1000);