From 6549827e3d845267acddfb7386f11958cbaf061e Mon Sep 17 00:00:00 2001 From: John Brunton Date: Sun, 25 Aug 2024 14:16:12 +0100 Subject: [PATCH] test: add invitation tests --- e2e/tests/fixtures/room-page.ts | 6 +++ e2e/tests/rooms.spec.ts | 82 ++++++++++++++++++++++++++++++++- 2 files changed, 86 insertions(+), 2 deletions(-) diff --git a/e2e/tests/fixtures/room-page.ts b/e2e/tests/fixtures/room-page.ts index 86643415..5426e3f0 100644 --- a/e2e/tests/fixtures/room-page.ts +++ b/e2e/tests/fixtures/room-page.ts @@ -5,12 +5,14 @@ export class RoomPage { private sendButton: Locator; private messagesList: Locator; private joinButton: Locator; + private requestButton: Locator; constructor(private readonly page: Page) { this.messageInput = page.getByPlaceholder("Type a message"); this.sendButton = page.getByRole("button", { name: "Send" }); this.messagesList = page.getByRole("list"); this.joinButton = page.getByRole("button", { name: "Join" }); + this.requestButton = page.getByRole("button", { name: "Request to Join" }); } async sendMessage(content: string) { @@ -29,6 +31,10 @@ export class RoomPage { await this.joinButton.click(); } + async requestToJoin() { + await this.requestButton.click(); + } + getMessage(content: string): Locator { return this.messagesList.getByText(content); } diff --git a/e2e/tests/rooms.spec.ts b/e2e/tests/rooms.spec.ts index 28ff718f..93448c16 100644 --- a/e2e/tests/rooms.spec.ts +++ b/e2e/tests/rooms.spec.ts @@ -49,10 +49,10 @@ test("users can join rooms", async ({ await user2RoomPage.join(); await expect( - user1Page.getByText("User 2 joined the room. Welcome!") + user1Page.getByText("Test User 2 joined the room. Welcome!") ).toBeVisible(); await expect( - user2Page.getByText("User 2 joined the room. Welcome!") + user2Page.getByText("Test User 2 joined the room. Welcome!") ).toBeVisible(); }); @@ -67,3 +67,81 @@ test("owners can rename rooms", async ({ page, menu, roomPage }) => { await expect(roomPage.getMessage("Room renamed to My Room")).toBeVisible(); await expect(page.getByRole("heading", { name: "My Room" })).toBeVisible(); }); + +test("users can request to join rooms when join policy = 'request'", async ({ + page: user1Page, + roomPage: user1RoomPage, + menu: user1Menu, + browser, +}) => { + await user1Page.goto("/"); + + await user1Menu.open(); + await user1Menu.createRoom(); + await user1RoomPage.setJoinPolicy("request"); + + const user2Context = await browser.newContext({ + storageState: user2AuthFile, + }); + const user2Page = await user2Context.newPage(); + + await user2Page.goto(user1Page.url()); + + const user2RoomPage = new RoomPage(user2Page); + await user2RoomPage.requestToJoin(); + + await expect( + user1Page.getByText( + "Test User 2 (test.user.2@example.com) requested approval to join the room" + ) + ).toBeVisible(); + + await user1RoomPage.sendMessage("/approve request test.user.2@example.com"); + + await expect( + user1Page.getByText("Test User 1 approved Test User 2 to join the room") + ).toBeVisible(); + await user2Page.reload(); + await expect( + user2Page.getByText("Test User 1 approved Test User 2 to join the room") + ).toBeVisible(); +}); + +test("users can send invites to rooms when join policy = 'invite'", async ({ + page: user1Page, + roomPage: user1RoomPage, + menu: user1Menu, + browser, +}) => { + await user1Page.goto("/"); + + await user1Menu.open(); + await user1Menu.createRoom(); + await user1RoomPage.setJoinPolicy("invite"); + + const user2Context = await browser.newContext({ + storageState: user2AuthFile, + }); + const user2Page = await user2Context.newPage(); + + await user2Page.goto(user1Page.url()); + + const user2RoomPage = new RoomPage(user2Page); + await expect(user2Page.getByText("You need an invite to join")).toBeVisible(); + + await user1RoomPage.sendMessage("/invite test.user.2@example.com"); + + await expect( + user1Page.getByText("Test User 1 invited Test User 2 to join the room") + ).toBeVisible(); + + await user2Page.reload(); + await user2RoomPage.join(); + + await expect( + user1Page.getByText("Test User 2 joined the room") + ).toBeVisible(); + await expect( + user2Page.getByText("Test User 2 joined the room") + ).toBeVisible(); +});