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

Commit

Permalink
Refactor test code into method
Browse files Browse the repository at this point in the history
  • Loading branch information
MidhunSureshR committed Jul 22, 2024
1 parent da1b493 commit 88d5b83
Show file tree
Hide file tree
Showing 15 changed files with 43 additions and 38 deletions.
2 changes: 1 addition & 1 deletion playwright/e2e/chat-export/html-export.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ test.describe("HTML Export", () => {
page.locator(".mx_EventTile_last .mx_MTextBody .mx_EventTile_body").getByText("Testing 9"),
).toBeVisible();

await page.getByRole("button", { name: "Room info" }).click();
await app.toggleRoomInfoPanel();
await page.getByRole("menuitem", { name: "Export Chat" }).click();

const downloadPromise = page.waitForEvent("download");
Expand Down
2 changes: 1 addition & 1 deletion playwright/e2e/create-room/create-room.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ test.describe("Create Room", () => {
await dialog.getByRole("button", { name: "Create room" }).click();

await expect(page).toHaveURL(/\/#\/room\/#test-room-1:localhost/);
const header = page.locator(".mx_LegacyRoomHeader");
const header = page.locator(".mx_RoomHeader");
await expect(header).toContainText(name);
await expect(header).toContainText(topic);
});
Expand Down
14 changes: 3 additions & 11 deletions playwright/e2e/crypto/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -329,15 +329,6 @@ export async function createRoom(page: Page, roomName: string, isEncrypted: bool
}
}

/**
* Open the room info panel and return the panel element
* @param page - the page to use
*/
export const openRoomInfo = async (page: Page) => {
await page.getByRole("button", { name: "Room info" }).click();
return page.locator(".mx_RightPanel");
};

/**
* Configure the given MatrixClient to auto-accept any invites
* @param client - the client to configure
Expand All @@ -357,10 +348,11 @@ export async function autoJoin(client: Client) {
* @param page - the page to use
* @param bob - the user to verify
*/
export const verify = async (page: Page, bob: Bot) => {
export const verify = async (app: ElementAppPage, bob: Bot) => {
const page = app.page;
const bobsVerificationRequestPromise = waitForVerificationRequest(bob);

const roomInfo = await openRoomInfo(page);
const roomInfo = await app.toggleRoomInfoPanel();
await page.locator(".mx_RightPanelTabs").getByText("People").click();
await roomInfo.getByText("Bob").click();
await roomInfo.getByRole("button", { name: "Verify" }).click();
Expand Down
4 changes: 2 additions & 2 deletions playwright/e2e/integration-manager/get-openid-token.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,8 @@ test.describe("Integration Manager: Get OpenID Token", () => {
await app.viewRoomByName(ROOM_NAME);
});

test("should successfully obtain an openID token", async ({ page }) => {
await openIntegrationManager(page);
test("should successfully obtain an openID token", async ({ page, app }) => {
await openIntegrationManager(app);
await sendActionFromIntegrationManager(page, integrationManagerUrl);

const iframe = page.frameLocator(`iframe[src*="${integrationManagerUrl}"]`);
Expand Down
10 changes: 5 additions & 5 deletions playwright/e2e/integration-manager/kick.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ test.describe("Integration Manager: Kick", () => {
await app.client.inviteUser(room.roomId, targetUser.credentials.userId);
await expect(page.getByText(`${BOT_DISPLAY_NAME} joined the room`)).toBeVisible();

await openIntegrationManager(page);
await openIntegrationManager(app);
await sendActionFromIntegrationManager(page, integrationManagerUrl, room.roomId, targetUser.credentials.userId);
await closeIntegrationManager(page, integrationManagerUrl);
await expectKickedMessage(page, true);
Expand All @@ -185,7 +185,7 @@ test.describe("Integration Manager: Kick", () => {
},
});

await openIntegrationManager(page);
await openIntegrationManager(app);
await sendActionFromIntegrationManager(page, integrationManagerUrl, room.roomId, targetUser.credentials.userId);
await closeIntegrationManager(page, integrationManagerUrl);
await expectKickedMessage(page, false);
Expand All @@ -197,7 +197,7 @@ test.describe("Integration Manager: Kick", () => {
await expect(page.getByText(`${BOT_DISPLAY_NAME} joined the room`)).toBeVisible();
await targetUser.leave(room.roomId);

await openIntegrationManager(page);
await openIntegrationManager(app);
await sendActionFromIntegrationManager(page, integrationManagerUrl, room.roomId, targetUser.credentials.userId);
await closeIntegrationManager(page, integrationManagerUrl);
await expectKickedMessage(page, false);
Expand All @@ -209,7 +209,7 @@ test.describe("Integration Manager: Kick", () => {
await expect(page.getByText(`${BOT_DISPLAY_NAME} joined the room`)).toBeVisible();
await app.client.ban(room.roomId, targetUser.credentials.userId);

await openIntegrationManager(page);
await openIntegrationManager(app);
await sendActionFromIntegrationManager(page, integrationManagerUrl, room.roomId, targetUser.credentials.userId);
await closeIntegrationManager(page, integrationManagerUrl);
await expectKickedMessage(page, false);
Expand All @@ -218,7 +218,7 @@ test.describe("Integration Manager: Kick", () => {
test("should no-op if the target was never a room member", async ({ page, app, bot: targetUser, room }) => {
await app.viewRoomByName(ROOM_NAME);

await openIntegrationManager(page);
await openIntegrationManager(app);
await sendActionFromIntegrationManager(page, integrationManagerUrl, room.roomId, targetUser.credentials.userId);
await closeIntegrationManager(page, integrationManagerUrl);
await expectKickedMessage(page, false);
Expand Down
10 changes: 5 additions & 5 deletions playwright/e2e/integration-manager/read_events.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ test.describe("Integration Manager: Read Events", () => {

// Send a state event
const sendEventResponse = await app.client.sendStateEvent(room.roomId, eventType, eventContent, stateKey);
await openIntegrationManager(page);
await openIntegrationManager(app);

// Read state events
await sendActionFromIntegrationManager(page, integrationManagerUrl, room.roomId, eventType, stateKey);
Expand All @@ -162,7 +162,7 @@ test.describe("Integration Manager: Read Events", () => {

// Send a state event
const sendEventResponse = await app.client.sendStateEvent(room.roomId, eventType, eventContent, stateKey);
await openIntegrationManager(page);
await openIntegrationManager(app);

// Read state events
await sendActionFromIntegrationManager(page, integrationManagerUrl, room.roomId, eventType, stateKey);
Expand Down Expand Up @@ -196,7 +196,7 @@ test.describe("Integration Manager: Read Events", () => {
app.client.sendStateEvent(room.roomId, eventType, eventContent3, stateKey3),
]);

await openIntegrationManager(page);
await openIntegrationManager(app);

// Read state events
await sendActionFromIntegrationManager(
Expand All @@ -217,11 +217,11 @@ test.describe("Integration Manager: Read Events", () => {
await expect(iframe.locator("#message-response")).toContainText(`"content":${JSON.stringify(eventContent3)}`);
});

test("should fail to read an event type which is not allowed", async ({ page, room }) => {
test("should fail to read an event type which is not allowed", async ({ page, app, room }) => {
const eventType = "com.example.event";
const stateKey = "";

await openIntegrationManager(page);
await openIntegrationManager(app);

// Read state events
await sendActionFromIntegrationManager(page, integrationManagerUrl, room.roomId, eventType, stateKey);
Expand Down
2 changes: 1 addition & 1 deletion playwright/e2e/integration-manager/send_event.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ test.describe("Integration Manager: Send Event", () => {
);

await app.viewRoomByName(ROOM_NAME);
await openIntegrationManager(page);
await openIntegrationManager(app);
});

test("should send a state event", async ({ page, app, room }) => {
Expand Down
7 changes: 4 additions & 3 deletions playwright/e2e/integration-manager/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,11 @@ See the License for the specific language governing permissions and
limitations under the License.
*/

import type { Page } from "@playwright/test";
import type { ElementAppPage } from "../../pages/ElementAppPage";

export async function openIntegrationManager(page: Page) {
await page.getByRole("button", { name: "Room info" }).click();
export async function openIntegrationManager(app: ElementAppPage) {
const { page } = app;
await app.toggleRoomInfoPanel();
await page
.locator(".mx_RoomSummaryCard_appsGroup")
.getByRole("button", { name: "Add widgets, bridges & bots" })
Expand Down
2 changes: 1 addition & 1 deletion playwright/e2e/invite/invite-dialog.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ test.describe("Invite dialog", function () {
await expect(page.getByText("Hanako created and configured the room.")).toBeVisible();

// Open the room info panel
await page.getByRole("button", { name: "Room info" }).click();
await app.toggleRoomInfoPanel();

await page.locator(".mx_BaseCard").getByRole("menuitem", { name: "Invite" }).click();

Expand Down
5 changes: 3 additions & 2 deletions playwright/e2e/lazy-loading/lazy-loading.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,9 @@ test.describe("Lazy Loading", () => {
}
}

async function openMemberlist(page: Page): Promise<void> {
await page.locator(".mx_LegacyRoomHeader").getByRole("button", { name: "Room info" }).click();
async function openMemberlist(app: ElementAppPage): Promise<void> {
await app.toggleRoomInfoPanel();
const { page } = app;
await page.locator(".mx_RightPanelTabs").getByText("People").click();
}

Expand Down
6 changes: 4 additions & 2 deletions playwright/e2e/polls/pollHistory.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import { test, expect } from "../../element-web-test";
import type { Page } from "@playwright/test";

Check failure on line 17 in playwright/e2e/polls/pollHistory.spec.ts

View workflow job for this annotation

GitHub Actions / ESLint

'Page' is defined but never used
import type { Bot } from "../../pages/bot";
import type { Client } from "../../pages/client";
import { ElementAppPage } from "../../pages/ElementAppPage";

test.describe("Poll history", () => {
type CreatePollOptions = {
Expand Down Expand Up @@ -66,8 +67,9 @@ test.describe("Poll history", () => {
});
};

async function openPollHistory(page: Page): Promise<void> {
await page.getByRole("button", { name: "Room info" }).click();
async function openPollHistory(app: ElementAppPage): Promise<void> {
const { page } = app;
await app.toggleRoomInfoPanel();
await page.locator(".mx_RoomSummaryCard").getByRole("menuitem", { name: "Poll history" }).click();
}

Expand Down
2 changes: 1 addition & 1 deletion playwright/e2e/presence/presence.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ test.describe("Presence tests", () => {
);
await app.client.createRoom({}); // trigger sync

await page.getByRole("button", { name: "Room info" }).click();
await app.toggleRoomInfoPanel();
await page.locator(".mx_RightPanel").getByText("People").click();
await expect(page.locator(".mx_EntityTile_unreachable")).toContainText("Bob");
await expect(page.locator(".mx_EntityTile_unreachable")).toContainText("User's server unreachable");
Expand Down
4 changes: 2 additions & 2 deletions playwright/e2e/right-panel/right-panel.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,9 @@ test.describe("RightPanel", () => {
await app.closeDialog();

// Close and reopen the right panel to render the room address
await page.getByRole("button", { name: "Room info" }).click();
await app.toggleRoomInfoPanel();
await expect(page.locator(".mx_RightPanel")).not.toBeVisible();
await page.getByRole("button", { name: "Room info" }).click();
await app.toggleRoomInfoPanel();

await expect(page.locator(".mx_RightPanel")).toMatchScreenshot("with-name-and-address.png");
});
Expand Down
2 changes: 1 addition & 1 deletion playwright/e2e/right-panel/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import { ElementAppPage } from "../../pages/ElementAppPage";

export async function viewRoomSummaryByName(page: Page, app: ElementAppPage, name: string): Promise<void> {
await app.viewRoomByName(name);
await page.getByRole("button", { name: "Room info" }).click();
await app.toggleRoomInfoPanel();
return checkRoomSummaryCard(page, name);
}

Expand Down
9 changes: 9 additions & 0 deletions playwright/pages/ElementAppPage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -171,4 +171,13 @@ export class ElementAppPage {
await spotlight.open();
return spotlight;
}

/**
* Opens/closes the room info panel
* @returns locator to the right panel
*/
public async toggleRoomInfoPanel(): Promise<Locator> {
await this.page.getByRole("button", { name: "Room info" }).first().click();
return this.page.locator(".mx_RightPanel");
}
}

0 comments on commit 88d5b83

Please sign in to comment.