Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: add invitation tests #151

Merged
merged 1 commit into from
Aug 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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();
});
Loading