Skip to content

Commit

Permalink
Add firefox, webkit testing, improve size matching
Browse files Browse the repository at this point in the history
  • Loading branch information
raimohanska committed Jan 27, 2024
1 parent 8dd3377 commit a9a0838
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 6 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ jobs:
env:
SESSION_SIGNING_SECRET: notsosecretthing
- name: Prepare Playwright
run: npx playwright install chromium
run: npx playwright install chromium firefox webkit
- name: Run playwright tests
run: yarn test:playwright
- name: Archive results
Expand Down
16 changes: 15 additions & 1 deletion playwright.config.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { PlaywrightTestConfig } from "@playwright/test"
import { PlaywrightTestConfig, devices } from "@playwright/test"

const ci = process.env.CI === "true"

Expand All @@ -15,5 +15,19 @@ const config: PlaywrightTestConfig = {
trace: "on",
},
reporter: ci ? "github" : "line",
projects: [
{
name: "chromium",
use: { ...devices["Desktop Chrome"] },
},
{
name: "firefox",
use: { ...devices["Desktop Firefox"] },
},
{
name: "webkit",
use: { ...devices["Desktop Safari"] },
},
],
}
export default config
17 changes: 16 additions & 1 deletion playwright/src/pages/BoardPage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,11 @@ export function BoardPage(page: Page) {
})
}

async function getElementSize(item: Locator) {
const { width, height } = assertNotNull(await item.boundingBox())
return { width, height }
}

async function createNew(paletteItem: Locator, x: number, y: number) {
await expect(paletteItem).toBeVisible()

Expand Down Expand Up @@ -137,7 +142,17 @@ export function BoardPage(page: Page) {
},
async assertItemPosition(item: Locator, x: number, y: number) {
const pos = await getElementPosition(item)
expect(pos).toEqual({ x, y })
expect(pos.x).toBeGreaterThan(x - 5)
expect(pos.x).toBeLessThan(x + 5)
expect(pos.y).toBeGreaterThan(y - 5)
expect(pos.y).toBeLessThan(y + 5)
},
async assertItemSize(item: Locator, width: number, height: number) {
const size = await getElementSize(item)
expect(size.width).toBeGreaterThan(width - 5)
expect(size.width).toBeLessThan(width + 5)
expect(size.height).toBeGreaterThan(height - 5)
expect(size.height).toBeLessThan(height + 5)
},
async getItemPosition(item: Locator) {
return await getElementPosition(item)
Expand Down
6 changes: 3 additions & 3 deletions playwright/src/tests/board.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ test.describe("Basic board functionality", () => {
await board.selectItems(monoids, semigroups)
await board.dragItem(monoids, 400, 300)
await board.assertItemPosition(monoids, 400, 300)
await board.assertItemPosition(semigroups, 300, 197)
await board.assertItemPosition(semigroups, 300, 200)
})
})

Expand Down Expand Up @@ -107,7 +107,7 @@ test.describe("Basic board functionality", () => {
const n2 = await board.createNoteWithText(300, 100, "ALL")
const n3 = await board.createNoteWithText(320, 190, "THESE")
await board.createNoteWithText(300, 250, "BUT NOT THIS")
await board.selectItems(n1, n2, n3)
await board.selectItems(n3, n2, n1)
const originalCoordinates = await Promise.all([n1, n2, n3].map((n) => board.getItemPosition(n)))
await (await board.contextMenu.openHorizontalAlign()).left.click()
const newCoordinates = await Promise.all([n1, n2, n3].map((n) => board.getItemPosition(n)))
Expand Down Expand Up @@ -140,7 +140,7 @@ test.describe("Basic board functionality", () => {
await test.step("Can drag to resize items", async () => {
await board.selectItems(monoids)
await board.dragSelectionBottomCorner(550, 550)
await expect(monoids).toHaveCSS("width", "382.562px")
await board.assertItemSize(monoids, 380, 380)
})
})

Expand Down

0 comments on commit a9a0838

Please sign in to comment.