Skip to content

Commit

Permalink
Tests e2e playwright: enhancing draw tests
Browse files Browse the repository at this point in the history
* Test erase all
* Check toggle save
  • Loading branch information
rldhont committed Jul 15, 2024
1 parent 8ee506d commit 43726c3
Showing 1 changed file with 54 additions and 3 deletions.
57 changes: 54 additions & 3 deletions tests/end2end/playwright/draw.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,54 @@ test.describe('Draw', () => {
expect(await page.locator('#newOlMap').screenshot()).toMatchSnapshot('draw-edition.png');
});

test('Erase all', async ({ page }) => {
// Polygon
await page.locator('#draw').getByRole('link').nth(1).click();
await page.locator('.digitizing-polygon > svg').click();
await page.locator('#newOlMap').click({
position: {
x: 290,
y: 50
}
});
await page.locator('#newOlMap').click({
position: {
x: 330,
y: 50
}
});

await page.locator('#newOlMap').dblclick({
position: {
x: 330,
y: 115
}
});

// Box
await page.locator('#draw').getByRole('link').nth(1).click();
await page.locator('.digitizing-box > svg').click();
await page.locator('#newOlMap').click({
position: {
x: 340,
y: 50
}
});
await page.locator('#newOlMap').click({
position: {
x: 390,
y: 115
}
});

expect(await page.evaluate(() => lizMap.mainLizmap.digitizing.featureDrawn)).toHaveLength(2);

page.on('dialog', dialog => dialog.accept());
await page.locator('.digitizing-all').click();

expect(await page.evaluate(() => lizMap.mainLizmap.digitizing.featureDrawn)).toBeNull();
});

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);
Expand All @@ -242,9 +290,10 @@ test.describe('Draw', () => {
await reloadMap(page);
// Display
await page.locator('#button-draw').click();
await expect(page.locator('.digitizing-save')).toHaveClass(/active/);

// Clear local storage
await page.evaluate(() => localStorage.removeItem('testsrepository_draw_draw_drawLayer'));
await page.locator('.digitizing-save').click();
expect(await page.evaluate(() => localStorage.getItem('testsrepository_draw_draw_drawLayer'))).toBeNull;

// Check the geometry has been drawn
Expand Down Expand Up @@ -290,15 +339,17 @@ test.describe('Draw', () => {

// The WKT has been moved to the new storage
const new_stored = await page.evaluate(() => localStorage.getItem('testsrepository_draw_draw_drawLayer'));
await expect(new_stored).toEqual(wkt);
await expect(new_stored).not.toBeNull();
await expect(new_stored).not.toEqual(wkt);
expect(await page.evaluate(() => localStorage.getItem('testsrepository_draw_drawLayer'))).toBeNull;

// Save to local storage
await page.locator('#button-draw').click();
await page.locator('.digitizing-save').click();
await expect(page.locator('.digitizing-save')).toHaveClass(/active/);

// The JSON has been stored
const json_stored = await page.evaluate(() => localStorage.getItem('testsrepository_draw_draw_drawLayer'));
await expect(new_stored).toEqual(json_stored);
// '[{"type":"Point","color":"#ff0000","coords":[770737.2003016905,6279832.319974077]}]'
await expect(json_stored).toContain('Point');
await expect(json_stored).not.toContain('LineString');
Expand Down

0 comments on commit 43726c3

Please sign in to comment.