Skip to content

Commit 58f11f4

Browse files
committed
test: add search tests
1 parent 8816698 commit 58f11f4

File tree

1 file changed

+71
-0
lines changed

1 file changed

+71
-0
lines changed

e2e/tests/public/search.spec.ts

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
import { test, expect } from "../../index"
2+
3+
test.describe("Search tests", async () => {
4+
test("Searching for a specific product returns the correct product page", async ({
5+
productPage,
6+
}) => {
7+
const searchModal = productPage.searchModal
8+
await searchModal.open()
9+
await searchModal.searchInput.fill("Sweatshirt")
10+
await searchModal.searchResult
11+
.filter({ hasText: "Sweatshirt" })
12+
.first()
13+
.click()
14+
await productPage.container.waitFor({ state: "visible" })
15+
await expect(productPage.productTitle).toContainText("Sweatshirt")
16+
})
17+
18+
test("An erroneous search returns an empty result", async ({
19+
productPage,
20+
}) => {
21+
const searchModal = productPage.searchModal
22+
await searchModal.open()
23+
await searchModal.searchInput.fill("Does Not Sweatshirt")
24+
await expect(searchModal.noSearchResultsContainer).toBeVisible()
25+
})
26+
27+
test("User can search after an empty search result", async ({
28+
productPage,
29+
}) => {
30+
const searchModal = productPage.searchModal
31+
32+
await searchModal.open()
33+
await searchModal.searchInput.fill("Does Not Sweatshirt")
34+
await expect(searchModal.noSearchResultsContainer).toBeVisible()
35+
36+
await searchModal.searchInput.fill("Sweat")
37+
await expect(searchModal.searchResults).toBeVisible()
38+
await expect(searchModal.searchResult.first()).toBeVisible()
39+
})
40+
41+
test("Closing the search page returns user back to their current page", async ({
42+
storePage,
43+
productPage,
44+
loginPage,
45+
}) => {
46+
const searchModal = storePage.searchModal
47+
await test.step("Navigate to the store page and open and close search modal", async () => {
48+
await storePage.goto()
49+
await searchModal.open()
50+
await searchModal.close()
51+
await expect(storePage.container).toBeVisible()
52+
})
53+
54+
await test.step("Navigate to the product page and open and close search modal", async () => {
55+
await storePage.goto()
56+
const product = await storePage.getProduct("Sweatshirt")
57+
await product.locator.click()
58+
await productPage.container.waitFor({ state: "visible" })
59+
await searchModal.open()
60+
await searchModal.close()
61+
await expect(productPage.container).toBeVisible()
62+
})
63+
64+
await test.step("Navigate to the login page and open and close search modal", async () => {
65+
await loginPage.goto()
66+
await searchModal.open()
67+
await searchModal.close()
68+
await expect(loginPage.container).toBeVisible()
69+
})
70+
})
71+
})

0 commit comments

Comments
 (0)