-
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.
create tests for the collections, add new locators, data-testids, fun…
…ctions
- Loading branch information
Showing
7 changed files
with
65 additions
and
5 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
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,45 @@ | ||
import { test } from '../fixtures'; | ||
import { expect } from 'playwright/test'; | ||
import { BRAND_NAME, COLLECTION_NAME, COLLECTIONS_ENDPOINT, HOMEPAGE_ENDPOINT } from '../constants'; | ||
import { getCollectionEndpoint } from '../utils'; | ||
|
||
test.describe('Collections page', () => { | ||
test.beforeEach('Navigate to the home page and open collection menu', async ({ page, collectionsPage }) => { | ||
if (!COLLECTION_NAME) { | ||
test.skip(!COLLECTION_NAME, 'PLAYWRIGHT_COLLECTION_NAME was not defined'); | ||
return; | ||
} | ||
|
||
await page.goto(HOMEPAGE_ENDPOINT); | ||
await page.getByTestId('nav-bar').getByRole('button', { name: COLLECTION_NAME, exact: true }).click(); | ||
await collectionsPage.collectionsDialog().waitFor(); | ||
}); | ||
|
||
test('Verify user can navigate to the collection', async ({ page, collectionsPage }) => { | ||
await collectionsPage | ||
.collectionsDialog() | ||
.locator('a', { hasText: `Shop all ${COLLECTION_NAME}` }) | ||
.click(); | ||
await page.waitForURL(getCollectionEndpoint()); | ||
|
||
await page.getByRole('heading', { name: COLLECTION_NAME, exact: true }).waitFor(); | ||
await expect(collectionsPage.productItems()).not.toHaveCount(0); | ||
}); | ||
|
||
test('Verify user can navigate to the collection by brand name', async ({ page, collectionsPage }) => { | ||
if (!BRAND_NAME) { | ||
test.skip(!BRAND_NAME, 'PLAYWRIGHT_BRAND_NAME was not defined'); | ||
return; | ||
} | ||
|
||
await collectionsPage.brandsSection().hover(); | ||
await collectionsPage.getBrandByName(BRAND_NAME).click(); | ||
await page.waitForURL(COLLECTIONS_ENDPOINT + BRAND_NAME.toLowerCase()); | ||
|
||
await page.getByRole('heading', { name: BRAND_NAME, exact: true }).waitFor(); | ||
await expect(collectionsPage.productItems()).not.toHaveCount(0); | ||
for (const product of await collectionsPage.productItems().all()) { | ||
await expect(product).toContainText(BRAND_NAME, { ignoreCase: true }); | ||
} | ||
}); | ||
}); |
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,9 @@ | ||
import { COLLECTION_NAME, COLLECTIONS_ENDPOINT } from './constants'; | ||
|
||
export function transformStringToSlug(string: string) { | ||
return string.toLowerCase().replace(/\s+/g, '-'); | ||
} | ||
|
||
export function getCollectionEndpoint() { | ||
return COLLECTIONS_ENDPOINT + transformStringToSlug(`${COLLECTION_NAME}`); | ||
} |
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