Skip to content

Commit ff21d93

Browse files
committed
refactor tests
1 parent 673693b commit ff21d93

File tree

4 files changed

+27
-24
lines changed

4 files changed

+27
-24
lines changed

tests/e2e/global.spec.ts

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ test.describe("Global", () => {
1515
// Try invalid search queries
1616
await homePage.search(testData.search.invalidQuery)
1717

18-
// Should not crash or show errors, has to show no results
18+
// Should not crash or show errors, has to show the no results message
1919
await page.waitForTimeout(1000) // Allow search to process
2020

2121
await homePage.verifyNoResults()
@@ -65,21 +65,9 @@ test.describe("Global", () => {
6565
).toBeVisible()
6666
}
6767

68-
test("switches to Chinese (desktop)", async ({ page }) => {
69-
const isMobile = await homePage.isMobileViewport()
70-
test.skip(isMobile, "This test is for desktop viewports only")
71-
72-
await expect(page).toHaveURL(`/${DEFAULT_LOCALE}/`)
73-
await homePage.openLanguagePickerDesktop()
74-
await switchToChinese(page, homePage)
75-
})
76-
77-
test("switches to Chinese (mobile)", async ({ page }) => {
78-
const isMobile = await homePage.isMobileViewport()
79-
test.skip(!isMobile, "This test is for mobile viewports only")
80-
68+
test("switches to Chinese", async ({ page }) => {
8169
await expect(page).toHaveURL(`/${DEFAULT_LOCALE}/`)
82-
await homePage.openLanguagePickerMobile()
70+
await homePage.openLanguagePicker()
8371
await switchToChinese(page, homePage)
8472
})
8573
})
@@ -113,7 +101,7 @@ test.describe("Global", () => {
113101

114102
await homePage.assertUrlMatches(`/${DEFAULT_LOCALE}/`)
115103

116-
await homePage.openLanguagePickerDesktop()
104+
await homePage.openLanguagePicker()
117105
await switchToArabic(page, homePage)
118106

119107
await homePage.assertUrlMatches(/\/ar(\/|$)/)

tests/e2e/home.spec.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ test.describe("Home Page", () => {
2525
})
2626

2727
test("main navigation - desktop", async () => {
28-
// Only run this test for desktop projects
2928
const isMobile = await homePage.isMobileViewport()
3029
test.skip(isMobile, "This test is for desktop viewports only")
3130

tests/e2e/pages/BasePage.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,27 @@ export class BasePage {
128128
await this.mobileSidebar.getByRole("button", { name: /languages/i }).click()
129129
}
130130

131+
/**
132+
* Open language picker
133+
*/
134+
async openLanguagePicker(): Promise<void> {
135+
const isMobile = await this.isMobileViewport()
136+
if (isMobile) {
137+
await this.openLanguagePickerMobile()
138+
} else {
139+
await this.openLanguagePickerDesktop()
140+
}
141+
}
142+
143+
async getSearchButton(): Promise<Locator> {
144+
const isMobile = await this.isMobileViewport()
145+
if (isMobile) {
146+
return this.searchButtonMobile
147+
} else {
148+
return this.searchInputButton
149+
}
150+
}
151+
131152
/**
132153
* Switch to a specific language
133154
*/

tests/e2e/pages/HomePage.ts

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -32,13 +32,8 @@ export class HomePage extends BasePage {
3232
* Perform a search action
3333
*/
3434
async search(query: string) {
35-
const isMobile = await this.isMobileViewport()
36-
37-
if (isMobile) {
38-
await this.searchButtonMobile.first().click()
39-
} else {
40-
await this.searchInputButton.first().click()
41-
}
35+
const searchBtn = await this.getSearchButton()
36+
await searchBtn.click()
4237

4338
await this.searchInput.fill(query)
4439
}

0 commit comments

Comments
 (0)