Skip to content

Commit

Permalink
Improve test reliability by always setting nickname
Browse files Browse the repository at this point in the history
  • Loading branch information
raimohanska committed Mar 11, 2024
1 parent 081d8ff commit bc0d831
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 21 deletions.
12 changes: 8 additions & 4 deletions playwright/src/pages/BoardPage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -287,10 +287,14 @@ export function BoardPage(page: Page, browser: Browser) {
await this.assertSelected(items[i], true)
}
},
userInfo: {
async dismiss() {
await page.locator(".user-info button").click()
},
async setNickname(nickname: string) {
await page
.locator(".user-info .icon")
.or(page.locator(".user-info .nickname"))
.first()
.click({ force: true })
await page.locator(".user-info .nickname input").fill(nickname)
await page.locator(".user-info button").click()
},
contextMenu: ContextMenu(page),
async deleteIndexedDb() {
Expand Down
25 changes: 14 additions & 11 deletions playwright/src/pages/DashboardPage.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Browser, Page, selectors } from "@playwright/test"
import { Browser, Page, selectors, test } from "@playwright/test"
import { BoardPage, semiUniqueId, NewBoardOptions } from "./BoardPage"

export async function navigateToDashboard(page: Page, browser: Browser) {
Expand All @@ -10,17 +10,20 @@ export async function navigateToDashboard(page: Page, browser: Browser) {
export function DashboardPage(page: Page, browser: Browser) {
return {
async createNewBoard(options?: NewBoardOptions) {
const name = options?.boardName ?? `Test board ${semiUniqueId()}`
const useCRDT = options?.useCRDT ?? true
return await test.step("Create new board", async () => {
const name = options?.boardName ?? `Test board ${semiUniqueId()}`
const useCRDT = options?.useCRDT ?? true

await page.getByPlaceholder("Enter board name").fill(name)
if (useCRDT) {
await page.getByText("use collaborative text editor").click()
}
await page.getByRole("button", { name: "Create" }).click()
const board = BoardPage(page, browser)
await board.assertBoardName(name)
return board
await page.getByPlaceholder("Enter board name").fill(name)
if (useCRDT) {
await page.getByText("use collaborative text editor").click()
}
await page.getByRole("button", { name: "Create" }).click()
const board = BoardPage(page, browser)
// TODO: this is flaky in at least "Switching between boards"
await board.assertBoardName(name)
return board
})
},
async goToBoard(name: string) {
await page.locator(".recent-boards li").filter({ hasText: name }).first().click()
Expand Down
8 changes: 4 additions & 4 deletions playwright/src/tests/board.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ test.describe("Basic board functionality", () => {

await test.step("Check with new session", async () => {
const newBoard = await board.openBoardInNewBrowser()
await newBoard.userInfo.dismiss()
await newBoard.setNickname("User 2")
await expect(newBoard.getNote("Monads")).toBeVisible()
})
})
Expand All @@ -208,7 +208,7 @@ test.describe("Basic board functionality", () => {
await test.step("Check with new session", async () => {
await board.deleteIndexedDb()
const newBoard = await board.openBoardInNewBrowser()
await newBoard.userInfo.dismiss()
await newBoard.setNickname("User 2")
await expect(newBoard.getArea("Monads")).toBeVisible()
})
})
Expand Down Expand Up @@ -256,7 +256,7 @@ test.describe("Basic board functionality", () => {
await test.step("Check with new session", async () => {
await board.deleteIndexedDb()
const newBoard = await board.openBoardInNewBrowser()
await newBoard.userInfo.dismiss()
await newBoard.setNickname("User 2")
await expect(newBoard.getNote("text")).not.toBeVisible()
})
})
Expand Down Expand Up @@ -311,7 +311,7 @@ test.describe("Basic board functionality", () => {
await test.step("Check with new session", async () => {
await board.deleteIndexedDb()
const newBoard = await board.openBoardInNewBrowser()
await newBoard.userInfo.dismiss()
await newBoard.setNickname("User 2")
await expect(newBoard.getArea("Semigroups")).toBeVisible()
})
})
Expand Down
13 changes: 11 additions & 2 deletions playwright/src/tests/collaboration.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,13 @@ test.describe("Two simultaneous users", () => {
await expect(userPage.getNote(anotherUserPageNoteText)).toBeVisible()
})

test("Change board name", async ({ page, browser }) => {
const { user1Page: userPage, user2Page } = await createBoardWithTwoUsers(page, browser)
// create 2 notes, one on each page
await userPage.renameBoard("Renamed board")
await user2Page.assertBoardName("Renamed board")
})

const onTopPart = { position: { x: 9, y: 15 } } as const

test("Users can collaboratively edit a text area", async ({ page, browser }) => {
Expand Down Expand Up @@ -126,12 +133,14 @@ test.describe("Two simultaneous users", () => {

async function createBoardWithTwoUsers(page: Page, browser: Browser) {
const user1Page = await navigateToNewBoard(page, browser, { boardName: "Collab test board" })
await user1Page.setNickname("User 1")

const boardId = user1Page.getBoardId()
const user2Page = await user1Page.openBoardInNewBrowser()
await user2Page.setNickname("User 2")

await user1Page.userInfo.dismiss()
await user2Page.userInfo.dismiss()
await user1Page.assertBoardName("Collab test board")
await user2Page.assertBoardName("Collab test board")

return { user1Page, user2Page, boardId }
}
Expand Down

0 comments on commit bc0d831

Please sign in to comment.