-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test(atomic): add atomic-commerce-numeric-facet tests (#4138)
KIT-3258 --------- Co-authored-by: GitHub Actions Bot <>
- Loading branch information
Showing
5 changed files
with
159 additions
and
1 deletion.
There are no files selected for viewing
39 changes: 39 additions & 0 deletions
39
...mmerce/facets/atomic-commerce-numeric-facet/atomic-commerce-numeric-facet.new.stories.tsx
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,39 @@ | ||
import { | ||
wrapInCommerceInterface, | ||
playExecuteFirstSearch, | ||
playKeepOnlyFirstFacetOfType, | ||
} from '@coveo/atomic/storybookUtils/commerce-interface-wrapper'; | ||
import {parameters} from '@coveo/atomic/storybookUtils/common-meta-parameters'; | ||
import {renderComponent} from '@coveo/atomic/storybookUtils/render-component'; | ||
import type {Meta, StoryObj as Story} from '@storybook/web-components'; | ||
import {html} from 'lit-html'; | ||
|
||
const {play, decorator} = wrapInCommerceInterface({skipFirstSearch: true}); | ||
|
||
const meta: Meta = { | ||
component: 'atomic-commerce-numeric-facet', | ||
title: 'Atomic-Commerce/NumericFacet', | ||
id: 'atomic-commerce-numeric-facet', | ||
render: renderComponent, | ||
decorators: [decorator], | ||
parameters, | ||
play, | ||
}; | ||
|
||
export default meta; | ||
|
||
export const Default: Story = { | ||
name: 'atomic-commerce-numeric-facet', | ||
decorators: [ | ||
(_) => { | ||
return html`<div id="code-root"> | ||
<atomic-commerce-facets></atomic-commerce-facets> | ||
</div>`; | ||
}, | ||
], | ||
play: async (context) => { | ||
await play(context); | ||
await playExecuteFirstSearch(context); | ||
playKeepOnlyFirstFacetOfType('atomic-commerce-numeric-facet', context); | ||
}, | ||
}; |
59 changes: 59 additions & 0 deletions
59
...ts/commerce/facets/atomic-commerce-numeric-facet/e2e/atomic-commerce-numeric-facet.e2e.ts
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, expect} from './fixture'; | ||
|
||
test.describe('default', () => { | ||
test.beforeEach(async ({numericFacet}) => { | ||
await numericFacet.load(); | ||
}); | ||
|
||
test('should be A11y compliant', async ({numericFacet, makeAxeBuilder}) => { | ||
await numericFacet.hydrated.waitFor(); | ||
const accessibilityResults = await makeAxeBuilder().analyze(); | ||
expect(accessibilityResults.violations).toEqual([]); | ||
}); | ||
|
||
test('should allow to select and deselect a range', async ({ | ||
numericFacet, | ||
}) => { | ||
const facetValueLabel = numericFacet.getFacetValue('12', '4,200'); | ||
const facetValueBtn = numericFacet.getFacetValueButton('12', '4,200'); | ||
|
||
await expect(facetValueBtn).not.toBeChecked(); | ||
await facetValueLabel.click(); | ||
|
||
await expect(facetValueBtn).toBeChecked(); | ||
|
||
await facetValueLabel.click(); | ||
await expect(facetValueBtn).not.toBeChecked(); | ||
}); | ||
|
||
test('should allow to deselect a filter with the clear button', async ({ | ||
numericFacet, | ||
}) => { | ||
const facetValueLabel = numericFacet.getFacetValue('12', '4,200'); | ||
|
||
await facetValueLabel.click(); | ||
|
||
await expect(numericFacet.clearFilter).toBeVisible(); | ||
await numericFacet.clearFilter.click(); | ||
|
||
await expect(numericFacet.clearFilter).toHaveCount(0); | ||
}); | ||
|
||
test('should allow to filter by entering a valid minimum and maximum value', async ({ | ||
numericFacet, | ||
}) => { | ||
await numericFacet.inputMinimum.fill('100'); | ||
await numericFacet.inputMaximum.fill('200'); | ||
await numericFacet.inputApply.click(); | ||
await expect(numericFacet.clearFilter).toBeVisible(); | ||
}); | ||
|
||
test('should prevent from filtering by entering an invalid minimum and maximum value', async ({ | ||
numericFacet, | ||
}) => { | ||
await numericFacet.inputMinimum.fill('200'); | ||
await numericFacet.inputMaximum.fill('100'); | ||
await numericFacet.inputApply.click(); | ||
await expect(numericFacet.clearFilter).toHaveCount(0); | ||
}); | ||
}); |
19 changes: 19 additions & 0 deletions
19
packages/atomic/src/components/commerce/facets/atomic-commerce-numeric-facet/e2e/fixture.ts
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,19 @@ | ||
import {test as base} from '@playwright/test'; | ||
import { | ||
AxeFixture, | ||
makeAxeBuilder, | ||
} from '../../../../../../playwright-utils/base-fixture'; | ||
import {NumericFacetPageObject} from './page-object'; | ||
|
||
type MyFixtures = { | ||
numericFacet: NumericFacetPageObject; | ||
}; | ||
|
||
export const test = base.extend<MyFixtures & AxeFixture>({ | ||
makeAxeBuilder, | ||
numericFacet: async ({page}, use) => { | ||
await use(new NumericFacetPageObject(page)); | ||
}, | ||
}); | ||
|
||
export {expect} from '@playwright/test'; |
38 changes: 38 additions & 0 deletions
38
...es/atomic/src/components/commerce/facets/atomic-commerce-numeric-facet/e2e/page-object.ts
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,38 @@ | ||
import type {Page} from '@playwright/test'; | ||
import {AnyFacetPageObject} from '../../e2e/page-object'; | ||
|
||
export class NumericFacetPageObject extends AnyFacetPageObject<'atomic-commerce-numeric-facet'> { | ||
constructor(page: Page) { | ||
super(page, 'atomic-commerce-numeric-facet'); | ||
} | ||
|
||
get title() { | ||
return this.page.getByText('Price'); | ||
} | ||
|
||
getFacetValueButton(start: string, end: string) { | ||
return this.page.getByLabel(`Inclusion filter on ${start} to ${end}`); | ||
} | ||
|
||
getFacetValue(start: string, end: string) { | ||
return this.page | ||
.getByRole('listitem') | ||
.filter({hasText: `${start} to ${end}`}); | ||
} | ||
|
||
get clearFilter() { | ||
return this.page.getByRole('button').filter({hasText: /Clear.*filter/}); | ||
} | ||
|
||
get inputMinimum() { | ||
return this.page.getByLabel('Enter a minimum numerical'); | ||
} | ||
|
||
get inputMaximum() { | ||
return this.page.getByLabel('Enter a maximum numerical'); | ||
} | ||
|
||
get inputApply() { | ||
return this.page.getByLabel('Apply custom numerical values'); | ||
} | ||
} |
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