|
| 1 | +import { test, expect, chromium } from '@playwright/test'; |
| 2 | + |
| 3 | +test.describe('map-a loaded inline or remote, directly or via templated map-link tests', () => { |
| 4 | + let page; |
| 5 | + let context; |
| 6 | + test.beforeAll(async function () { |
| 7 | + context = await chromium.launchPersistentContext(''); |
| 8 | + page = |
| 9 | + context.pages().find((page) => page.url() === 'about:blank') || |
| 10 | + (await context.newPage()); |
| 11 | + await page.goto('map-a.html'); |
| 12 | + await page.waitForTimeout(500); |
| 13 | + }); |
| 14 | + |
| 15 | + const contentLocations = ['inline', 'remote']; |
| 16 | + for (const inlineOrRemote of contentLocations) { |
| 17 | + test(`${inlineOrRemote} map-a-wrapped-map-geometry loaded directly creates a hyperlink`, async () => { |
| 18 | + const directlyLoadedFeaturesLayer = await page.getByTestId( |
| 19 | + `${inlineOrRemote}-features` |
| 20 | + ); |
| 21 | + const directlyLoadedFeaturesCount = |
| 22 | + await directlyLoadedFeaturesLayer.evaluate((l) => { |
| 23 | + let node = l.hasAttribute('src') ? l.shadowRoot : l; |
| 24 | + return node.querySelectorAll('map-feature').length; |
| 25 | + }); |
| 26 | + expect(directlyLoadedFeaturesCount).toBe(2); |
| 27 | + // one of them contains a map-a wrapping its map-geometry |
| 28 | + const directlyLoadedHyperlinksCount = |
| 29 | + await directlyLoadedFeaturesLayer.evaluate((l) => { |
| 30 | + let node = l.hasAttribute('src') ? l.shadowRoot : l; |
| 31 | + return node.querySelectorAll('map-feature:has(map-a)').length; |
| 32 | + }); |
| 33 | + expect(directlyLoadedHyperlinksCount).toBe(1); |
| 34 | + // all features should have a _groupEl prop (i.e. all features are rendered) |
| 35 | + const directlyLoadedFeaturesRenderedCount = |
| 36 | + await directlyLoadedFeaturesLayer.evaluate((l) => { |
| 37 | + let node = l.hasAttribute('src') ? l.shadowRoot : l; |
| 38 | + const hasRendering = (f) => Boolean(f._groupEl); |
| 39 | + return Array.from(node.querySelectorAll('map-feature')).filter( |
| 40 | + hasRendering |
| 41 | + ).length; |
| 42 | + }); |
| 43 | + expect(directlyLoadedFeaturesRenderedCount).toEqual( |
| 44 | + directlyLoadedFeaturesCount |
| 45 | + ); |
| 46 | + }); |
| 47 | + test(`${inlineOrRemote} map-a-wrapped-map-geometry loaded via templated map-link creates a hyperlink`, async () => { |
| 48 | + const templatedLoadedFeaturesContainer = await page.getByTestId( |
| 49 | + `${inlineOrRemote}-templated-link` |
| 50 | + ); |
| 51 | + const templatedLoadedFeaturesCount = |
| 52 | + await templatedLoadedFeaturesContainer.evaluate((l) => { |
| 53 | + return l.shadowRoot.querySelectorAll('map-feature').length; |
| 54 | + }); |
| 55 | + expect(templatedLoadedFeaturesCount).toBe(2); |
| 56 | + // one of them contains a map-a wrapping its map-geometry |
| 57 | + const templatedLoadedHyperlinksCount = |
| 58 | + await templatedLoadedFeaturesContainer.evaluate((l) => { |
| 59 | + return l.shadowRoot.querySelectorAll('map-feature:has(map-a)').length; |
| 60 | + }); |
| 61 | + expect(templatedLoadedHyperlinksCount).toBe(1); |
| 62 | + // all features should have a _groupEl prop (i.e. all features are rendered) |
| 63 | + const templatedLoadedFeaturesRenderedCount = |
| 64 | + await templatedLoadedFeaturesContainer.evaluate((l) => { |
| 65 | + const hasRendering = (f) => Boolean(f._groupEl); |
| 66 | + return Array.from( |
| 67 | + l.shadowRoot.querySelectorAll('map-feature') |
| 68 | + ).filter(hasRendering).length; |
| 69 | + }); |
| 70 | + expect(templatedLoadedFeaturesRenderedCount).toEqual( |
| 71 | + templatedLoadedFeaturesCount |
| 72 | + ); |
| 73 | + }); |
| 74 | + } |
| 75 | +}); |
0 commit comments