-
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 tests for atomic-commerce-recommendation-list (#4437)
https://coveord.atlassian.net/browse/KIT-3248 --------- Co-authored-by: Frederic Beaudoin <[email protected]>
- Loading branch information
1 parent
ff39242
commit 74dff0d
Showing
8 changed files
with
267 additions
and
12 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
92 changes: 92 additions & 0 deletions
92
...e/atomic-commerce-recommendation-list/atomic-commerce-recommendation-list.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,92 @@ | ||
import {wrapInCommerceInterface} from '@coveo/atomic-storybook-utils/commerce/commerce-interface-wrapper'; | ||
import {parameters} from '@coveo/atomic-storybook-utils/common/common-meta-parameters'; | ||
import {renderComponent} from '@coveo/atomic-storybook-utils/common/render-component'; | ||
import type {Meta, StoryObj as Story} from '@storybook/web-components'; | ||
|
||
const {decorator, play} = wrapInCommerceInterface({skipFirstSearch: false}); | ||
|
||
const meta: Meta = { | ||
component: 'atomic-commerce-recommendation-list', | ||
title: 'Atomic-Commerce/Atomic Recommendation List', | ||
id: 'atomic-commerce-recommendation-list', | ||
render: renderComponent, | ||
decorators: [decorator], | ||
parameters, | ||
play, | ||
args: { | ||
'attributes-slot-id': 'd8118c04-ff59-4f03-baca-2fc5f3b81221', | ||
'slots-default': `<atomic-product-template> | ||
<template> | ||
<atomic-product-section-name> | ||
<atomic-product-link class="font-bold"></atomic-product-link> | ||
</atomic-product-section-name> | ||
<atomic-product-section-visual> | ||
<atomic-product-image field="ec_thumbnails"></atomic-product-image> | ||
</atomic-product-section-visual> | ||
<atomic-product-section-metadata> | ||
<atomic-product-text field="ec_brand" class="text-neutral-dark block"></atomic-product-text> | ||
<atomic-product-rating field="ec_rating"></atomic-product-rating> | ||
</atomic-product-section-metadata> | ||
<atomic-product-section-emphasized> | ||
<atomic-product-price currency="USD"></atomic-product-price> | ||
</atomic-product-section-emphasized> | ||
<atomic-product-section-children> | ||
<atomic-product-children></atomic-product-children> | ||
</atomic-product-section-children> | ||
</template> | ||
</atomic-product-template>`, | ||
}, | ||
}; | ||
export default meta; | ||
|
||
export const Default: Story = { | ||
name: 'atomic-commerce-recommendation-list', | ||
}; | ||
|
||
const {play: playNoFirstQuery} = wrapInCommerceInterface({ | ||
skipFirstSearch: true, | ||
}); | ||
export const BeforeQuery: Story = { | ||
tags: ['test'], | ||
play: playNoFirstQuery, | ||
}; | ||
|
||
export const WithFullTemplate: Story = { | ||
tags: ['test'], | ||
args: { | ||
'slots-default': ` <atomic-product-template> | ||
<template> | ||
<atomic-product-section-visual> | ||
<span>Visual Section</span> | ||
</atomic-product-section-visual> | ||
<atomic-product-section-badge> | ||
<span>Badge Section</span> | ||
</atomic-product-section-badge> | ||
<atomic-product-section-actions> | ||
<span>Actions Section</span> | ||
</atomic-product-section-actions> | ||
<atomic-product-section-title> | ||
<span>Title Section</span> | ||
</atomic-product-section-title> | ||
<atomic-product-section-title-metadata> | ||
<span>Title Metadata Section</span> | ||
</atomic-product-section-title-metadata> | ||
<atomic-product-section-emphasized> | ||
<span>Emphasized Section</span> | ||
</atomic-product-section-emphasized> | ||
<atomic-product-section-excerpt> | ||
<span>Excerpt Section</span> | ||
</atomic-product-section-excerpt> | ||
<atomic-product-section-bottom-metadata> | ||
<span>Bottom Metadata Section</span> | ||
</atomic-product-section-bottom-metadata> | ||
</template> | ||
</atomic-product-template>`, | ||
}, | ||
}; | ||
|
||
export const AsCarousel: Story = { | ||
args: { | ||
'attributes-products-per-page': 3, | ||
}, | ||
}; |
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
102 changes: 102 additions & 0 deletions
102
...mmerce/atomic-commerce-recommendation-list/e2e/atomic-commerce-recommendation-list.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,102 @@ | ||
import {test, expect} from './fixture'; | ||
|
||
test.describe('before query is loaded', () => { | ||
test.beforeEach(async ({recommendationList}) => { | ||
await recommendationList.load({story: 'before-query'}); | ||
await recommendationList.hydrated.waitFor(); | ||
}); | ||
|
||
test('should be a11y compliant', async ({makeAxeBuilder}) => { | ||
const accessibilityResults = await makeAxeBuilder().analyze(); | ||
expect(accessibilityResults.violations.length).toEqual(0); | ||
}); | ||
|
||
test('should have placeholders', async ({recommendationList}) => { | ||
await expect(recommendationList.placeholder.first()).toBeVisible(); | ||
}); | ||
}); | ||
|
||
test.describe('after query is loaded', () => { | ||
test.beforeEach(async ({recommendationList}) => { | ||
await recommendationList.load({story: 'default'}); | ||
await recommendationList.hydrated.waitFor(); | ||
}); | ||
|
||
test('should be a11y compliant', async ({makeAxeBuilder}) => { | ||
const accessibilityResults = await makeAxeBuilder().analyze(); | ||
expect(accessibilityResults.violations.length).toEqual(0); | ||
}); | ||
|
||
test('should have recommendations', async ({recommendationList}) => { | ||
await expect(recommendationList.recommendation.first()).toBeVisible(); | ||
}); | ||
}); | ||
|
||
test.describe('with a full result template', () => { | ||
test.beforeEach(async ({recommendationList}) => { | ||
await recommendationList.load({story: 'with-full-template'}); | ||
await recommendationList.hydrated.waitFor(); | ||
}); | ||
|
||
test('should be a11y compliant', async ({makeAxeBuilder}) => { | ||
const accessibilityResults = await makeAxeBuilder().analyze(); | ||
expect(accessibilityResults.violations.length).toEqual(0); | ||
}); | ||
|
||
test('should have recommendations', async ({recommendationList}) => { | ||
await expect(recommendationList.recommendation.first()).toBeVisible(); | ||
}); | ||
}); | ||
|
||
test.describe('with a carousel', () => { | ||
test.beforeEach(async ({recommendationList}) => { | ||
await recommendationList.load({story: 'as-carousel'}); | ||
await recommendationList.hydrated.waitFor(); | ||
}); | ||
|
||
test('should be a11y compliant', async ({makeAxeBuilder}) => { | ||
const accessibilityResults = await makeAxeBuilder().analyze(); | ||
expect(accessibilityResults.violations.length).toEqual(0); | ||
}); | ||
|
||
test('should have recommendations', async ({recommendationList}) => { | ||
await expect(recommendationList.recommendation.first()).toBeVisible(); | ||
}); | ||
|
||
test('should support going forward and backward', async ({ | ||
recommendationList, | ||
}) => { | ||
await recommendationList.nextButton.click(); | ||
await expect(recommendationList.indicators.nth(1)).toHaveAttribute( | ||
'part', | ||
'indicator active-indicator' | ||
); | ||
|
||
await recommendationList.prevButton.click(); | ||
await recommendationList.prevButton.click(); | ||
await expect(recommendationList.indicators.nth(3)).toHaveAttribute( | ||
'part', | ||
'indicator active-indicator' | ||
); | ||
|
||
await recommendationList.nextButton.click(); | ||
await expect(recommendationList.indicators.nth(0)).toHaveAttribute( | ||
'part', | ||
'indicator active-indicator' | ||
); | ||
}); | ||
}); | ||
|
||
test('with no recommendations returned by the API, should render placeholders', async ({ | ||
recommendationList, | ||
}) => { | ||
await recommendationList.noRecommendations(); | ||
await recommendationList.load({story: 'default'}); | ||
await recommendationList.hydrated.waitFor({state: 'hidden'}); | ||
await expect | ||
.poll(async () => await recommendationList.recommendation.count()) | ||
.toBe(0); | ||
await expect | ||
.poll(async () => await recommendationList.placeholder.count()) | ||
.toBe(0); | ||
}); |
19 changes: 19 additions & 0 deletions
19
packages/atomic/src/components/commerce/atomic-commerce-recommendation-list/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 {AtomicCommerceRecommendationList as RecommendationList} from './page-object'; | ||
|
||
type MyFixtures = { | ||
recommendationList: RecommendationList; | ||
}; | ||
|
||
export const test = base.extend<MyFixtures & AxeFixture>({ | ||
makeAxeBuilder, | ||
recommendationList: async ({page}, use) => { | ||
await use(new RecommendationList(page)); | ||
}, | ||
}); | ||
|
||
export {expect} from '@playwright/test'; |
30 changes: 30 additions & 0 deletions
30
...ges/atomic/src/components/commerce/atomic-commerce-recommendation-list/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,30 @@ | ||
import type {Page} from '@playwright/test'; | ||
import {BasePageObject} from '../../../../../playwright-utils/base-page-object'; | ||
|
||
export class AtomicCommerceRecommendationList extends BasePageObject<'atomic-commerce-recommendation-list'> { | ||
constructor(page: Page) { | ||
super(page, 'atomic-commerce-recommendation-list'); | ||
} | ||
|
||
get placeholder() { | ||
return this.page.locator('.placeholder'); | ||
} | ||
|
||
get recommendation() { | ||
return this.page.locator( | ||
'[part="result-list-grid-clickable-container outline"]' | ||
); | ||
} | ||
|
||
get indicators() { | ||
return this.page.getByRole('listitem'); | ||
} | ||
|
||
get nextButton() { | ||
return this.page.getByLabel('Next'); | ||
} | ||
|
||
get prevButton() { | ||
return this.page.getByLabel('Previous'); | ||
} | ||
} |
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 |
---|---|---|
@@ -1,10 +1,5 @@ | ||
{ | ||
"extends": "./tsconfig.stencil.json", | ||
"exclude": [ | ||
"node_modules", | ||
"src/external-builds", | ||
"**/*.stories.tsx", | ||
"**/*.stories.ts", | ||
"**/*.stories.js" | ||
] | ||
|
||
"exclude": ["node_modules", "src/external-builds"] | ||
} |