From c28f2b9829b0ba9d92c622b2e758b8d994ef74d8 Mon Sep 17 00:00:00 2001 From: rldhont Date: Thu, 1 Feb 2024 15:55:25 +0100 Subject: [PATCH] Tests end2end: Digitizing, testing rendering from local storage --- tests/end2end/playwright/draw.spec.ts | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/tests/end2end/playwright/draw.spec.ts b/tests/end2end/playwright/draw.spec.ts index 32b5d8069d..81a1abb7b7 100644 --- a/tests/end2end/playwright/draw.spec.ts +++ b/tests/end2end/playwright/draw.spec.ts @@ -205,6 +205,32 @@ test.describe('Draw', () => { expect(await page.locator('#newOlMap').screenshot()).toMatchSnapshot('draw-edition.png'); }); + test('From local storage', async ({ page }) => { + const the_json = '[{"type":"Polygon","color":"#000000","coords":[[[764321.0416656,6290805.935670358],[767628.3399468632,6290805.935670358],[767628.3399468632,6295105.423436],[764321.0416656,6295105.423436],[764321.0416656,6290805.935670358],[764321.0416656,6290805.935670358]]]}]'; + await page.evaluate(token => localStorage.setItem('testsrepository_draw_draw_drawLayer', token), the_json); + const json_stored = await page.evaluate(() => localStorage.getItem('testsrepository_draw_draw_drawLayer')); + await expect(json_stored).toEqual(the_json); + + // Reload + await page.reload({ waitUntil: 'networkidle' }); + // Display + await page.locator('#button-draw').click(); + + // Clear local storage + await page.evaluate(() => localStorage.removeItem('testsrepository_draw_draw_drawLayer')); + expect(await page.evaluate(() => localStorage.getItem('testsrepository_draw_draw_drawLayer'))).toBeNull; + + // Check the geometry has been drawn + expect(await page.evaluate(() => lizMap.mainLizmap.digitizing.featureDrawn)).toHaveLength(1); + + // Hide all elements but #map, #newOlMap and their children + await page.$eval("*", el => el.style.visibility = 'hidden'); + await page.$eval("#newOlMap, #newOlMap *", el => el.style.visibility = 'visible'); + + // Check rendering + expect(await page.locator('#newOlMap').screenshot()).toMatchSnapshot('draw-edition.png'); + }); + test('WKT found in local storage', async ({ page }) => { // Save WKT to the old local storage const wkt = 'POINT(770737.2003016905 6279832.319974077)';