Skip to content

Commit

Permalink
[FE] Automate click Edit map in OSM and control OSM opening (web OSM) (
Browse files Browse the repository at this point in the history
…#741)

* added open OSM tests

* fix to use URL constructor

* fix to go back to split method

* rename method
  • Loading branch information
amurKontur authored May 27, 2024
1 parent 0d11600 commit 8c5d5f6
Show file tree
Hide file tree
Showing 3 changed files with 85 additions and 2 deletions.
30 changes: 30 additions & 0 deletions e2e/openOsm.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import { expect } from '@playwright/test';
import { test } from './fixtures/test-options.ts';
import { getProjects } from './page-objects/helperBase.ts';

const projects = getProjects();

for (const project of projects) {
test(`As Guest, I can go to ${project.title}, open map and open OSM at map coordinates`, async ({
context,
pageManager,
}) => {
await pageManager.atBrowser.openProject(project);
await pageManager.fromNavigationMenu.goToMap();

// TO DO: remove this action after 18582 issue is fixed
await pageManager.atMap.goToSpecificAreaByUrl(10.597, 53.9196, 27.5097, project);

const coordinates = await pageManager.atMap.getViewportFromUrl();

// Start waiting for new page being opened
const newPagePromise = context.waitForEvent('page');

await (await pageManager.atToolBar.getButtonByText('Edit map in OSM')).click();
const newPage = await newPagePromise;

await pageManager.atMap.waitForUrlToMatchPattern(/openstreetmap/, newPage);
const osmCoordinates = await pageManager.atMap.getViewportFromUrl(newPage);
expect(osmCoordinates).toStrictEqual(coordinates);
});
}
29 changes: 29 additions & 0 deletions e2e/openOsmWithUser.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import { expect } from '@playwright/test';
import { test } from './fixtures/test-options.ts';
import { getProjects } from './page-objects/helperBase.ts';

const projects = getProjects();

for (const project of projects) {
test(`As User with no rights, I can go to ${project.title}, open map and open Rapid OSM editor at map coordinates`, async ({
context,
pageManager,
}) => {
await pageManager.atBrowser.openProject(project, { skipCookieBanner: true });
await pageManager.fromNavigationMenu.goToMap();

// TO DO: remove this action after 18582 issue is fixed
await pageManager.atMap.goToSpecificAreaByUrl(10.597, 53.9196, 27.5097, project);

const coordinates = await pageManager.atMap.getViewportFromUrl();

// Start waiting for new page being opened
const newPagePromise = context.waitForEvent('page');

await (await pageManager.atToolBar.getButtonByText('Edit map in OSM')).click();
const newPage = await newPagePromise;
await pageManager.atMap.waitForUrlToMatchPattern(/rapideditor/, newPage);
const osmCoordinates = await pageManager.atMap.getViewportFromUrl(newPage);
expect(osmCoordinates).toStrictEqual(coordinates);
});
}
28 changes: 26 additions & 2 deletions e2e/page-objects/mapPage.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { expect } from '@playwright/test';
import { HelperBase } from './helperBase';
import type { Page } from '@playwright/test';
import type { Project } from './helperBase';

export class MapCanvas extends HelperBase {
Expand Down Expand Up @@ -42,10 +43,11 @@ export class MapCanvas extends HelperBase {
/**
* This method waits for URL to match specific regexp pattern. It is mostly useful for testing maps.
* @param pattern value for url to have inside in form of RegExp
* @param page playwright page to wait for
*/

async waitForUrlToMatchPattern(pattern: RegExp) {
await this.page.waitForURL(pattern);
async waitForUrlToMatchPattern(pattern: RegExp, page: Page = this.page) {
await page.waitForURL(pattern);
}

/**
Expand Down Expand Up @@ -112,4 +114,26 @@ export class MapCanvas extends HelperBase {
).not.toBeVisible();
await expect(this.page.locator('#map-view')).toBeVisible();
}

/**
* This method gets current url coordinates and returns its integer parts
* @param page playwright page to get url from
* @returns object with zoom, latitude, longitude. Integer values
*/

async getViewportFromUrl(page: Page = this.page) {
const mapData = page.url().split('map=')[1].split('&')[0];
expect(mapData).toBeDefined();

const [zoom, latitude, longitude] = mapData!.split('/').map(Number);
expect(zoom).not.toBeNaN();
expect(latitude).not.toBeNaN();
expect(longitude).not.toBeNaN();

return {
zoomInteger: Math.trunc(zoom),
latitudeInteger: Math.trunc(latitude),
longitudeInteger: Math.trunc(longitude),
};
}
}

0 comments on commit 8c5d5f6

Please sign in to comment.