Skip to content

Commit 9967008

Browse files
committed
reuse methods
1 parent fc32dee commit 9967008

File tree

2 files changed

+4
-26
lines changed

2 files changed

+4
-26
lines changed

tests/e2e/global.spec.ts

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
import { expect, takeSnapshot, test } from "@chromatic-com/playwright"
22
import { Page } from "@playwright/test"
33

4-
import { breakpointAsNumber } from "@/lib/utils/screen"
5-
64
import { DEFAULT_LOCALE } from "@/lib/constants"
75

86
import { testData } from "./fixtures/testData"
@@ -58,7 +56,6 @@ test.describe("Global", () => {
5856
})
5957

6058
test("switches to Chinese (mobile)", async ({ page }) => {
61-
await page.setViewportSize({ width: breakpointAsNumber.sm, height: 800 })
6259
const isMobile = await homePage.isMobileViewport()
6360
test.skip(!isMobile, "This test is for mobile viewports only")
6461

@@ -73,11 +70,12 @@ test.describe("Global", () => {
7370

7471
test.beforeEach(async ({ page }) => {
7572
homePage = new HomePage(page)
73+
await waitForPageReady(page)
7674
})
7775

7876
async function switchToArabic(page: Page, homePage: HomePage) {
7977
await homePage.switchToLanguage("ar", /^العربية Arabic/i)
80-
await expect(page).toHaveURL(/\/ar(\/|$)/)
78+
await homePage.assertUrlMatches(/\/ar(\/|$)/)
8179
await expect(
8280
page.getByRole("heading", { level: 1, name: /إيثريوم/i })
8381
).toBeVisible()
@@ -95,12 +93,12 @@ test.describe("Global", () => {
9593
await homePage.goto()
9694
await waitForPageReady(page)
9795

98-
await expect(page).toHaveURL(`/${DEFAULT_LOCALE}/`)
96+
await homePage.assertUrlMatches(`/${DEFAULT_LOCALE}/`)
9997

10098
await homePage.openLanguagePickerDesktop()
10199
await switchToArabic(page, homePage)
102100

103-
await expect(page).toHaveURL(/\/ar(\/|$)/)
101+
await homePage.assertUrlMatches(/\/ar(\/|$)/)
104102

105103
const logo = page.getByTestId("nav-logo")
106104
const searchBtn = page.getByTestId("search-input-button")

tests/e2e/utils/testHelpers.ts

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -192,26 +192,6 @@ export const waitForElementCountChange = async (
192192
return newCount
193193
}
194194

195-
/**
196-
* Simulate mobile viewport
197-
*/
198-
export const setMobileViewport = async (page: Page): Promise<void> => {
199-
await page.setViewportSize({
200-
width: breakpointAsNumber.sm,
201-
height: 800,
202-
})
203-
}
204-
205-
/**
206-
* Simulate desktop viewport
207-
*/
208-
export const setDesktopViewport = async (page: Page): Promise<void> => {
209-
await page.setViewportSize({
210-
width: 1200,
211-
height: 800,
212-
})
213-
}
214-
215195
/**
216196
* Assert element is visible with better error message
217197
*/

0 commit comments

Comments
 (0)