-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add new constant and data-testid, create tests for the search functio…
…nality
- Loading branch information
Showing
3 changed files
with
61 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
import { test } from '../fixtures'; | ||
import { expect } from 'playwright/test'; | ||
import { BRAND_NAME, COLLECTION_NAME, HOMEPAGE_ENDPOINT, PRODUCT_NAME, RANDOM_STRING } from '../constants'; | ||
|
||
test.describe('Search functionality', () => { | ||
test.beforeEach('Navigate to the home page', async ({ page }) => { | ||
await page.goto(HOMEPAGE_ENDPOINT); | ||
}); | ||
|
||
test('Search by product name', async ({ page }) => { | ||
if (!PRODUCT_NAME) { | ||
test.skip(!PRODUCT_NAME, 'PLAYWRIGHT_PRODUCT_NAME was not defined'); | ||
return; | ||
} | ||
|
||
await page.getByTestId('search-icon').click(); | ||
await page.getByPlaceholder('Search...').waitFor(); | ||
await page.getByPlaceholder('Search...').fill(PRODUCT_NAME); | ||
await page.getByRole('listbox').waitFor(); | ||
await expect(page.getByRole('listbox')).toContainText(PRODUCT_NAME); | ||
}); | ||
|
||
test('Search by brand name', async ({ page }) => { | ||
if (!BRAND_NAME) { | ||
test.skip(!BRAND_NAME, 'PLAYWRIGHT_BRAND_NAME was not defined'); | ||
return; | ||
} | ||
|
||
await page.getByTestId('search-icon').click(); | ||
await page.getByPlaceholder('Search...').waitFor(); | ||
await page.getByPlaceholder('Search...').fill(BRAND_NAME); | ||
await page.getByRole('listbox').waitFor(); | ||
|
||
const searchResults = await page.getByRole('listbox').locator('li').all(); | ||
for (const item of searchResults) { | ||
await expect(item).toContainText(BRAND_NAME, { ignoreCase: true }); | ||
} | ||
}); | ||
|
||
test('Search by collection name', async ({ page }) => { | ||
if (!COLLECTION_NAME) { | ||
test.skip(!COLLECTION_NAME, 'PLAYWRIGHT_COLLECTION_NAME was not defined'); | ||
return; | ||
} | ||
|
||
await page.getByTestId('search-icon').click(); | ||
await page.getByPlaceholder('Search...').waitFor(); | ||
await page.getByPlaceholder('Search...').fill(COLLECTION_NAME); | ||
await page.getByRole('listbox').waitFor(); | ||
await expect(page.getByRole('listbox').locator('li')).not.toHaveCount(0); | ||
}); | ||
|
||
test('Search by invalid parameter', async ({ page }) => { | ||
await page.getByTestId('search-icon').click(); | ||
await page.getByPlaceholder('Search...').waitFor(); | ||
await page.getByPlaceholder('Search...').fill(RANDOM_STRING); | ||
await expect(page.getByText('No results found')).toBeVisible(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters