Skip to content
This repository was archived by the owner on Sep 11, 2024. It is now read-only.

Commit 33d527e

Browse files
authored
Migrate location.spec.ts from Cypress to Playwright (#11945)
Signed-off-by: Michael Telatynski <[email protected]>
1 parent 0bbb9e8 commit 33d527e

File tree

3 files changed

+93
-74
lines changed

3 files changed

+93
-74
lines changed

cypress/e2e/location/location.spec.ts

Lines changed: 0 additions & 74 deletions
This file was deleted.
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
/*
2+
Copyright 2022 The Matrix.org Foundation C.I.C.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
import { Locator, Page } from "@playwright/test";
18+
19+
import { test, expect } from "../../element-web-test";
20+
21+
test.describe("Location sharing", () => {
22+
const selectLocationShareTypeOption = (page: Page, shareType: string): Locator => {
23+
return page.getByTestId(`share-location-option-${shareType}`);
24+
};
25+
26+
const submitShareLocation = (page: Page): Promise<void> => {
27+
return page.getByRole("button", { name: "Share location" }).click();
28+
};
29+
30+
test.use({
31+
displayName: "Tom",
32+
});
33+
34+
test.beforeEach(async ({ page }) => {
35+
await page.addInitScript(() => {
36+
window.localStorage.setItem("mx_lhs_size", "0");
37+
});
38+
});
39+
40+
test("sends and displays pin drop location message successfully", async ({ page, user, app }) => {
41+
const roomId = await app.createRoom({});
42+
await page.goto(`/#/room/${roomId}`);
43+
44+
const composerOptions = await app.openMessageComposerOptions();
45+
await composerOptions.getByRole("menuitem", { name: "Location", exact: true }).click();
46+
47+
await selectLocationShareTypeOption(page, "Pin").click();
48+
49+
await page.locator("#mx_LocationPicker_map").click();
50+
51+
await submitShareLocation(page);
52+
53+
await page.locator(".mx_RoomView_body .mx_EventTile .mx_MLocationBody").click({
54+
position: {
55+
x: 225,
56+
y: 150,
57+
},
58+
});
59+
60+
// clicking location tile opens maximised map
61+
await expect(page.getByRole("dialog")).toBeVisible();
62+
63+
await app.closeDialog();
64+
65+
await expect(page.locator(".mx_Marker")).toBeVisible();
66+
});
67+
});

playwright/pages/ElementAppPage.ts

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,13 @@ export class ElementAppPage {
6161
return this.page.locator(".mx_CreateRoomDialog");
6262
}
6363

64+
/**
65+
* Close dialog currently open dialog
66+
*/
67+
public async closeDialog(): Promise<void> {
68+
return this.page.getByRole("button", { name: "Close dialog", exact: true }).click();
69+
}
70+
6471
/**
6572
* Create a room with given options.
6673
* @param options the options to apply when creating the room
@@ -74,4 +81,23 @@ export class ElementAppPage {
7481
.then((res) => res.room_id);
7582
}, options);
7683
}
84+
85+
/**
86+
* Get the composer element
87+
* @param isRightPanel whether to select the right panel composer, otherwise the main timeline composer
88+
*/
89+
public async getComposer(isRightPanel?: boolean): Promise<Locator> {
90+
const panelClass = isRightPanel ? ".mx_RightPanel" : ".mx_RoomView_body";
91+
return this.page.locator(`${panelClass} .mx_MessageComposer`);
92+
}
93+
94+
/**
95+
* Open the message composer kebab menu
96+
* @param isRightPanel whether to select the right panel composer, otherwise the main timeline composer
97+
*/
98+
public async openMessageComposerOptions(isRightPanel?: boolean): Promise<Locator> {
99+
const composer = await this.getComposer(isRightPanel);
100+
await composer.getByRole("button", { name: "More options", exact: true }).click();
101+
return this.page.getByRole("menu");
102+
}
77103
}

0 commit comments

Comments
 (0)