Skip to content

Commit

Permalink
test(atomic): fix commerce tests (#4160)
Browse files Browse the repository at this point in the history
  • Loading branch information
olamothe authored Jul 9, 2024
1 parent 2d3905e commit 7d9a5e9
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 54 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -168,27 +168,6 @@ test.describe('with a valid page in the hash', () => {
});
});

test.describe('with an invalid page in the hash', () => {
test.beforeEach(async ({page}) => {
await page.goto(
'http://localhost:4400/iframe.html?id=atomic-commerce-pager--default&viewMode=story#page=8k3'
);
});

test('pager button 1 should be selected', async ({pager}) => {
await expect(pager.numericButton(1)).toHaveAttribute(
'part',
expect.stringContaining('active-page-button')
);
});

test('should be A11y compliant', async ({pager, makeAxeBuilder}) => {
await pager.hydrated.waitFor();
const accessibilityResults = await makeAxeBuilder().analyze();
expect(accessibilityResults.violations).toEqual([]);
});
});

test.describe('with number-of-pages=3', () => {
test.beforeEach(async ({pager}) => {
await pager.load({args: {numberOfPages: 3}});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ test.describe('when executing an initial search', () => {
test.describe('when interface load yields no products', () => {
test.beforeEach(async ({productList}) => {
await productList.load({story: 'no-results'});
await productList.hydrated.waitFor();
});

test('should not display placeholders', async ({productList}) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ import {test, expect} from './fixture';

test.describe('when search has not been executed', () => {
test.beforeEach(async ({querySummary}) => {
await querySummary.load();
await querySummary.load({story: 'no-initial-search'});
});

test('should display a placeholder', async ({querySummary}) => {
await expect(querySummary.placeholder).not.toBeVisible();
await expect(querySummary.placeholder).toBeVisible();
});
});

Expand All @@ -26,7 +26,7 @@ test.describe('after searching for kayak', () => {

test.describe('when search yields no products', () => {
test.beforeEach(async ({querySummary}) => {
await querySummary.load({story: 'no-results'});
await querySummary.load({story: 'no-products'});
});

test('should not display anything', async ({querySummary}) => {
Expand All @@ -36,7 +36,7 @@ test.describe('when search yields no products', () => {

test.describe('when search yields multiple products', () => {
test.beforeEach(async ({querySummary}) => {
await querySummary.load({story: 'fixed-number-of-results'});
await querySummary.load({story: 'fixed-number-of-products'});
});

test('screen readers should read out', async ({querySummary}) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -203,13 +203,14 @@ test.describe('with instant results & query suggestions', () => {
});

test.describe('with recent queries', () => {
test.beforeEach(async ({searchBox}) => {
test.beforeEach(async ({searchBox, page}) => {
await searchBox.searchInput.waitFor({state: 'visible'});
await searchBox.searchInput.click();
await searchBox.searchInput.fill('kayak');
await searchBox.searchInput.press('Enter');
await searchBox.clearButton.waitFor({state: 'visible'});
await searchBox.searchInput.fill('');
await page.waitForLoadState('networkidle');
});

test('should display recent queries', async ({searchBox}) => {
Expand Down Expand Up @@ -439,24 +440,6 @@ test.describe('with a facet & clear-filters set to false', () => {
});
});

test.describe('with enable-query-syntax=true', () => {
test.beforeEach(async ({page}) => {
await page.goto(
'http://localhost:4400/iframe.html?id=atomic-commerce-search-box--in-page&viewMode=story&args=attributes-enable-query-syntax:!true;attributes-suggestion-timeout:5000'
);
});

test('should use query syntax', async ({loadMore, searchBox, page}) => {
await loadMore.loadMoreButton.waitFor({state: 'visible'});
await searchBox.searchInput
// eslint-disable-next-line @cspell/spellchecker
.fill('@urihash=bzo5fpM1vf8Xñds1');
await searchBox.submitButton.click();
await expect(loadMore.summary({total: 1})).toBeVisible();
await expect(page.getByText('WiLife Life Jacket WiLife')).toBeVisible();
});
});

test.describe('standalone searchbox', () => {
test.beforeEach(async ({page}) => {
await page.goto(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable @cspell/spellchecker */
import {test, expect} from './fixture';

test.describe('default', () => {
Expand All @@ -14,8 +15,8 @@ test.describe('default', () => {
test('should allow to filter by selecting and deselecting a value', async ({
facet,
}) => {
const facetValueLabel = facet.getFacetValue('Nike');
const facetValueBtn = facet.getFacetValueButton('Nike');
const facetValueLabel = facet.getFacetValue('Ecco');
const facetValueBtn = facet.getFacetValueButton('Ecco');

await expect(facetValueBtn).not.toBeChecked();
await facetValueLabel.click();
Expand All @@ -30,8 +31,8 @@ test.describe('default', () => {
facet,
page,
}) => {
const firstValueBtn = facet.getFacetValueButton('Nike');
const secondValueBtn = facet.getFacetValueButton('Adidas');
const firstValueBtn = facet.getFacetValueButton('Ecco');
const secondValueBtn = facet.getFacetValueButton('Nike');

await expect(firstValueBtn).not.toBeChecked();
await expect(secondValueBtn).not.toBeChecked();
Expand All @@ -46,7 +47,7 @@ test.describe('default', () => {
test('should allow to deselect a filter with the clear button', async ({
facet,
}) => {
const facetValueLabel = facet.getFacetValue('Nike');
const facetValueLabel = facet.getFacetValue('Ecco');

await expect(facet.clearFilter).toHaveCount(0);

Expand Down Expand Up @@ -81,15 +82,15 @@ test.describe('default', () => {

expect(await page.getByRole('listitem').count()).toBeGreaterThanOrEqual(8);
await expect(page.getByText('More matches for n')).toBeVisible();
await facet.searchInput.fill('nike');
await facet.searchInput.fill('Ecco');

await facet.getFacetValue('Nike').click();
await facet.getFacetValue('Ecco').click();

await expect(facet.getFacetValueButton('Nike')).toBeChecked();
await expect(facet.getFacetValueButton('Ecco')).toBeChecked();
});

test('allow to clear the search input', async ({facet}) => {
await facet.searchInput.fill('nike');
await facet.searchInput.fill('Ecco');
await expect(facet.clearSearchInput).toBeVisible();

await facet.clearSearchInput.click();
Expand Down

0 comments on commit 7d9a5e9

Please sign in to comment.