Skip to content

Commit

Permalink
Shop page tests: add assertions to check url after clicking on a facet
Browse files Browse the repository at this point in the history
Added assertions to make sure the url pathname is still the same, and
only the query changes after clicking on a facet. For example, after
clicking the `Phone` Device category filter on `Shop/Samsung_Repair_Kits`
page should redirect to `/Shop/Samsung_Repair_Kits?filter[facet_tags.Device Category]=Phone`
and not `/Shop/Samsung_Repair_Kits/Phone`.
  • Loading branch information
batbattur committed Jun 30, 2023
1 parent 6d7c20c commit 65f0bb7
Showing 1 changed file with 34 additions and 2 deletions.
36 changes: 34 additions & 2 deletions frontend/tests/playwright/product-list/filters.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,8 @@ async function resetAndCheckRefinements(buttonText: string, page: Page) {
).toBe(0);
}

const SHOP_PAGE_URL = '/Shop/Samsung_Repair_Kits';

test.describe('Product List Filtering', () => {
test.describe('Desktop Filters', () => {
test.skip(({ page }) => {
Expand Down Expand Up @@ -165,7 +167,7 @@ test.describe('Product List Filtering', () => {
});

test('Filter Products on /Shop Page', async ({ page }) => {
await page.goto('/Shop/Samsung_Repair_Kits');
await page.goto(SHOP_PAGE_URL);

const facetList = page
.getByTestId('facets-accordion')
Expand All @@ -182,6 +184,11 @@ test.describe('Product List Filtering', () => {
const firstCollapsedAccordionItem =
await visibleFacetList[0].elementHandle();

// Check current url path and search params.
const url = new URL(page.url());
expect(url.pathname).toEqual(SHOP_PAGE_URL);
expect(url.search).toEqual('');

// Click the first facet accordion item.
if (!firstCollapsedAccordionItem) {
throw new Error('Could not find first collapsed accordion item');
Expand Down Expand Up @@ -214,7 +221,17 @@ test.describe('Product List Filtering', () => {
results
);

// Check that url pathname is still /Shop/Samsung_Repair_Kits
// after clicking on a facet button.
const urlAfterApplyingFilters = new URL(page.url());
expect(urlAfterApplyingFilters.pathname).toEqual(SHOP_PAGE_URL);
expect(urlAfterApplyingFilters.search).not.toEqual('');

await resetAndCheckRefinements('Clear all filters', page);

const urlAfterClearingFilters = new URL(page.url());
expect(urlAfterClearingFilters.pathname).toEqual(SHOP_PAGE_URL);
expect(urlAfterClearingFilters.search).toEqual('');
});
});

Expand Down Expand Up @@ -286,7 +303,12 @@ test.describe('Product List Filtering', () => {
});

test('Filter Products on /Shop Page', async ({ page }) => {
await page.goto('/Shop/Samsung_Repair_Kits');
await page.goto(SHOP_PAGE_URL);

// Check current url path and search params.
const url = new URL(page.url());
expect(url.pathname).toEqual(SHOP_PAGE_URL);
expect(url.search).toEqual('');

// Select the first filter and close the drawer
await page
Expand Down Expand Up @@ -320,7 +342,17 @@ test.describe('Product List Filtering', () => {
results
);

// Check that url pathname is still /Shop/Samsung_Repair_Kits
// after clicking on a facet button.
const urlAfterApplyingFilters = new URL(page.url());
expect(urlAfterApplyingFilters.pathname).toEqual(SHOP_PAGE_URL);
expect(urlAfterApplyingFilters.search).not.toEqual('');

await resetAndCheckRefinements('Clear all filters', page);

const urlAfterClearingFilters = new URL(page.url());
expect(urlAfterClearingFilters.pathname).toEqual(SHOP_PAGE_URL);
expect(urlAfterClearingFilters.search).toEqual('');
});

test('Facet Drawer Apply and Clear All Buttons', async ({ page }) => {
Expand Down

0 comments on commit 65f0bb7

Please sign in to comment.