From 65f0bb799bd34bc1a136dd568a177fe59f4bd00f Mon Sep 17 00:00:00 2001 From: batbattur Date: Thu, 29 Jun 2023 17:26:06 -0700 Subject: [PATCH] Shop page tests: add assertions to check url after clicking on a facet 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`. --- .../playwright/product-list/filters.spec.ts | 36 +++++++++++++++++-- 1 file changed, 34 insertions(+), 2 deletions(-) diff --git a/frontend/tests/playwright/product-list/filters.spec.ts b/frontend/tests/playwright/product-list/filters.spec.ts index 138bc6b4..3f625fda 100644 --- a/frontend/tests/playwright/product-list/filters.spec.ts +++ b/frontend/tests/playwright/product-list/filters.spec.ts @@ -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 }) => { @@ -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') @@ -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'); @@ -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(''); }); }); @@ -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 @@ -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 }) => {