Skip to content

Commit

Permalink
Merge pull request #151 from jbrunton/invitation-tests
Browse files Browse the repository at this point in the history
test: add invitation tests
  • Loading branch information
jbrunton authored Aug 25, 2024
2 parents ba0787a + 6549827 commit 9611a27
Show file tree
Hide file tree
Showing 2 changed files with 86 additions and 2 deletions.
6 changes: 6 additions & 0 deletions e2e/tests/fixtures/room-page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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);
}
Expand Down
82 changes: 80 additions & 2 deletions e2e/tests/rooms.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
});

Expand All @@ -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 ([email protected]) requested approval to join the room"
)
).toBeVisible();

await user1RoomPage.sendMessage("/approve request [email protected]");

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 [email protected]");

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();
});

0 comments on commit 9611a27

Please sign in to comment.