|
| 1 | +import { test, expect, chromium } from '@playwright/test'; |
| 2 | + |
| 3 | +test.describe('Layer legend tests', () => { |
| 4 | + let page; |
| 5 | + let context; |
| 6 | + |
| 7 | + test.beforeAll(async () => { |
| 8 | + context = await chromium.launchPersistentContext('', { slowMo: 250 }); |
| 9 | + page = await context.newPage(); |
| 10 | + await page.goto('layerLegend.html'); |
| 11 | + await page.locator('mapml-viewer').hover(); |
| 12 | + }); |
| 13 | + |
| 14 | + test.afterAll(async () => { |
| 15 | + await context.close(); |
| 16 | + }); |
| 17 | + |
| 18 | + test('Legend layer has legend details in layer settings', async () => { |
| 19 | + // Get the first layer in the overlay list (the one with an img legend) |
| 20 | + const layer = page |
| 21 | + .locator('.leaflet-control-layers-overlays > fieldset') |
| 22 | + .first(); |
| 23 | + |
| 24 | + // Open the settings for that layer and check that the legend details are present |
| 25 | + const settings = layer.locator('.mapml-layer-item-settings'); |
| 26 | + |
| 27 | + // Check that the legend details, name, and link are present and correct |
| 28 | + const legendDetails = settings.locator('details.mapml-layer-item-legend'); |
| 29 | + await expect(legendDetails).toHaveCount(1); |
| 30 | + await expect(legendDetails.locator('summary')).toHaveText('Legend'); |
| 31 | + await expect( |
| 32 | + legendDetails.locator('a.mapml-layer-item-legend-link') |
| 33 | + ).toHaveAttribute( |
| 34 | + 'href', |
| 35 | + 'http://maps.geogratis.gc.ca/wms/toporama_en?SERVICE=WMS&REQUEST=GetLegendGraphic&LAYER=WMS-Toporama&VERSION=1.1&FORMAT=image/png' |
| 36 | + ); |
| 37 | + await expect( |
| 38 | + legendDetails.locator('img.mapml-layer-item-legend-image') |
| 39 | + ).toHaveAttribute( |
| 40 | + 'src', |
| 41 | + 'http://maps.geogratis.gc.ca/wms/toporama_en?SERVICE=WMS&REQUEST=GetLegendGraphic&LAYER=WMS-Toporama&VERSION=1.1&FORMAT=image/png' |
| 42 | + ); |
| 43 | + |
| 44 | + // check that the legend details are the second details element in the settings |
| 45 | + const secondDetails = settings.locator('> details').nth(1); |
| 46 | + await expect(secondDetails).toHaveClass( |
| 47 | + 'mapml-layer-item-legend mapml-control-layers' |
| 48 | + ); |
| 49 | + }); |
| 50 | + |
| 51 | + test('Layer without legend does not render legend details in settings', async () => { |
| 52 | + // Get the second layer in the overlay list (the one without a legend) |
| 53 | + const layer = page |
| 54 | + .locator('.leaflet-control-layers-overlays > fieldset') |
| 55 | + .nth(1); |
| 56 | + |
| 57 | + // check that the settings for that layer do not contain any legend details |
| 58 | + const settings = layer.locator('.mapml-layer-item-settings'); |
| 59 | + await expect( |
| 60 | + settings.locator('details.mapml-layer-item-legend') |
| 61 | + ).toHaveCount(0); |
| 62 | + }); |
| 63 | + |
| 64 | + test('Layer with a non img legend renders a legend link', async () => { |
| 65 | + // Get the third layer in the overlay list (the one with a non img legend) |
| 66 | + const layer = page |
| 67 | + .locator('.leaflet-control-layers-overlays > fieldset') |
| 68 | + .nth(2); |
| 69 | + |
| 70 | + // check that the settings for that layer contain a legend link |
| 71 | + const settings = layer.locator('.mapml-layer-item-settings'); |
| 72 | + |
| 73 | + // Check that the legend details, name, and link are present and correct |
| 74 | + const legendDetails = settings.locator('details.mapml-layer-item-legend'); |
| 75 | + await expect(legendDetails).toHaveCount(1); |
| 76 | + await expect(legendDetails.locator('summary')).toHaveText('Legend'); |
| 77 | + await expect( |
| 78 | + legendDetails.locator('a.mapml-layer-item-legend-link') |
| 79 | + ).toHaveAttribute('href', 'https://maps4html.org/web-map-doc/'); |
| 80 | + |
| 81 | + // not working, need to manually open the legend for it to update. |
| 82 | + /*await expect( |
| 83 | + legendDetails.locator('a.mapml-layer-item-legend-link') |
| 84 | + ).toHaveText("Open Legend"); |
| 85 | + */ |
| 86 | + |
| 87 | + // check that the legend details are the second details element in the settings |
| 88 | + const secondDetails = settings.locator('> details').nth(1); |
| 89 | + await expect(secondDetails).toHaveClass( |
| 90 | + 'mapml-layer-item-legend mapml-control-layers' |
| 91 | + ); |
| 92 | + }); |
| 93 | +}); |
0 commit comments