-
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(commerce): add tests for atomic-commerce-text (#4061)
TODO: - [x] Test for pluralization https://coveord.atlassian.net/browse/KIT-3255 --------- Co-authored-by: GitHub Actions Bot <> Co-authored-by: Alex Prudhomme <[email protected]>
- Loading branch information
1 parent
cd4718d
commit 7aa3e8e
Showing
8 changed files
with
160 additions
and
1 deletion.
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
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
54 changes: 54 additions & 0 deletions
54
.../atomic/src/components/commerce/atomic-commerce-text/atomic-commerce-text.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,54 @@ | ||
import {wrapInCommerceInterface} 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 {within} from '@storybook/test'; | ||
import type {Meta, StoryObj as Story} from '@storybook/web-components'; | ||
|
||
const {decorator, play} = wrapInCommerceInterface({skipFirstSearch: true}); | ||
|
||
const meta: Meta = { | ||
component: 'atomic-commerce-text', | ||
title: 'Atomic-Commerce/Product Template Components/Text', | ||
id: 'atomic-commerce-text', | ||
render: renderComponent, | ||
decorators: [decorator], | ||
parameters, | ||
play, | ||
}; | ||
|
||
export default meta; | ||
|
||
export const Default: Story = { | ||
name: 'atomic-commerce-text', | ||
args: { | ||
'attributes-value': 'Atomic Commerce Text', | ||
}, | ||
}; | ||
|
||
export const WithTranslations: Story = { | ||
name: 'With translations', | ||
play: async (context) => { | ||
await play(context); | ||
const canvas = within(context.canvasElement); | ||
const commerceInterface = | ||
await canvas.findByTestId<HTMLAtomicCommerceInterfaceElement>( | ||
'root-interface' | ||
); | ||
|
||
await context.step('Load translations', () => { | ||
commerceInterface.i18n.addResourceBundle('en', 'translation', { | ||
// "translation-key": "A single product" | ||
[context.args['attributes-value']]: context.args.translationValue, | ||
// "translation-key_other": "{{count}} products" | ||
[context.args['attributes-value'] + '_other']: | ||
context.args.translationValueOther, | ||
}); | ||
}); | ||
}, | ||
args: { | ||
'attributes-value': 'translation-key', | ||
'attributes-count': 1, | ||
translationValue: 'A single product', | ||
translationValueOther: '{{count}} products', | ||
}, | ||
}; |
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
36 changes: 36 additions & 0 deletions
36
packages/atomic/src/components/commerce/atomic-commerce-text/e2e/atomic-commerce-text.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,36 @@ | ||
import {expect, test} from './fixture'; | ||
|
||
test.describe('default', () => { | ||
test('should show text', async ({text}) => { | ||
await text.load(); | ||
|
||
await expect(text.getText).toHaveText('Atomic Commerce Text'); | ||
}); | ||
|
||
test('should be A11y compliant', async ({text, makeAxeBuilder}) => { | ||
await text.load(); | ||
|
||
await text.hydrated.waitFor(); | ||
const accessibilityResults = await makeAxeBuilder().analyze(); | ||
expect(accessibilityResults.violations).toEqual([]); | ||
}); | ||
|
||
test('should translate text', async ({text}) => { | ||
await text.load({story: 'with-translations'}); | ||
|
||
await text.hydrated.waitFor(); | ||
|
||
await expect(text.getText).toHaveText('A single product'); | ||
}); | ||
|
||
test('should translate text with count', async ({text}) => { | ||
await text.load({ | ||
args: {count: 2, value: 'translation-key'}, | ||
story: 'with-translations', | ||
}); | ||
|
||
await text.hydrated.waitFor(); | ||
|
||
await expect(text.getText).toHaveText('2 products'); | ||
}); | ||
}); |
18 changes: 18 additions & 0 deletions
18
packages/atomic/src/components/commerce/atomic-commerce-text/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,18 @@ | ||
import {test as base} from '@playwright/test'; | ||
import { | ||
AxeFixture, | ||
makeAxeBuilder, | ||
} from '../../../../../playwright-utils/base-fixture'; | ||
import {AtomicCommerceText as Text} from './page-object'; | ||
|
||
type MyFixtures = { | ||
text: Text; | ||
}; | ||
|
||
export const test = base.extend<MyFixtures & AxeFixture>({ | ||
makeAxeBuilder, | ||
text: async ({page}, use) => { | ||
await use(new Text(page)); | ||
}, | ||
}); | ||
export {expect} from '@playwright/test'; |
12 changes: 12 additions & 0 deletions
12
packages/atomic/src/components/commerce/atomic-commerce-text/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,12 @@ | ||
import type {Page} from '@playwright/test'; | ||
import {BasePageObject} from '../../../../../playwright-utils/base-page-object'; | ||
|
||
export class AtomicCommerceText extends BasePageObject<'atomic-commerce-text'> { | ||
constructor(page: Page) { | ||
super(page, 'atomic-commerce-text'); | ||
} | ||
|
||
get getText() { | ||
return this.page.locator('atomic-commerce-text'); | ||
} | ||
} |