Skip to content

Commit

Permalink
added open OSM tests
Browse files Browse the repository at this point in the history
  • Loading branch information
amurKontur committed May 23, 2024
1 parent 0d11600 commit 808f568
Show file tree
Hide file tree
Showing 3 changed files with 80 additions and 2 deletions.
29 changes: 29 additions & 0 deletions e2e/openOsm.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 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.getIntegerCoordinatesFromUrl();

// 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.getIntegerCoordinatesFromUrl(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.getIntegerCoordinatesFromUrl();

// 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.getIntegerCoordinatesFromUrl(newPage);
expect(osmCoordinates).toStrictEqual(coordinates);
});
}
24 changes: 22 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,22 @@ 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 at string format
*/

async getIntegerCoordinatesFromUrl(page: Page = this.page) {
const currentUrlCutParams = page.url().split('map=')[1].split('/');
const [zoom, latitude] = currentUrlCutParams;
const longitude = currentUrlCutParams[2].split('&')[0];
const getIntegerPart = (value: string) => value.split('.')[0];
return {
zoomInteger: getIntegerPart(zoom),
latitudeInteger: getIntegerPart(latitude),
longitudeInteger: getIntegerPart(longitude),
};
}
}

0 comments on commit 808f568

Please sign in to comment.