-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
https://coveord.atlassian.net/browse/KIT-3254 --------- Co-authored-by: GitHub Actions Bot <>
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
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 {CommerceEngineConfiguration} from '@coveo/headless/commerce'; | ||
import type {Meta, StoryObj as Story} from '@storybook/web-components'; | ||
import {html} from 'lit/static-html.js'; | ||
|
||
const {decorator, play} = wrapInCommerceInterface({ | ||
skipFirstSearch: true, | ||
}); | ||
|
||
const noResultsEngineConfig: Partial<CommerceEngineConfiguration> = { | ||
preprocessRequest: (r) => { | ||
const parsed = JSON.parse(r.body as string); | ||
// eslint-disable-next-line @cspell/spellchecker | ||
parsed.query = 'qnjssoptjhyalwnmrbgtyslsd'; | ||
r.body = JSON.stringify(parsed); | ||
return r; | ||
}, | ||
}; | ||
|
||
const fixedNumberOfResults = ( | ||
perPage: number | ||
): Partial<CommerceEngineConfiguration> => ({ | ||
preprocessRequest: (r) => { | ||
const parsed = JSON.parse(r.body as string); | ||
parsed.perPage = perPage; | ||
r.body = JSON.stringify(parsed); | ||
return r; | ||
}, | ||
}); | ||
|
||
const {play: playNoresults} = wrapInCommerceInterface({ | ||
skipFirstSearch: false, | ||
engineConfig: noResultsEngineConfig, | ||
}); | ||
|
||
const {play: playFixedNumberOfResults} = wrapInCommerceInterface({ | ||
skipFirstSearch: false, | ||
engineConfig: fixedNumberOfResults(27), | ||
}); | ||
|
||
const meta: Meta = { | ||
component: 'atomic-commerce-query-summary', | ||
title: 'Atomic-Commerce/QuerySummary', | ||
id: 'atomic-commerce-query-summary', | ||
render: renderComponent, | ||
decorators: [decorator], | ||
parameters, | ||
play, | ||
}; | ||
|
||
export default meta; | ||
|
||
export const Default: Story = { | ||
name: 'atomic-query-summary', | ||
}; | ||
|
||
export const NoResults: Story = { | ||
name: 'No Results', | ||
tags: ['test'], | ||
decorators: [(story) => story()], | ||
play: async (context) => { | ||
await playNoresults(context); | ||
}, | ||
}; | ||
|
||
export const FixedNumberOfResults: Story = { | ||
name: 'Fixed Number of Results', | ||
tags: ['test'], | ||
decorators: [(story) => story()], | ||
play: async (context) => { | ||
await playFixedNumberOfResults(context); | ||
}, | ||
}; | ||
|
||
export const WithSearchBox: Story = { | ||
name: 'With a Search Box', | ||
tags: ['test'], | ||
decorators: [ | ||
(story) => | ||
html` <atomic-commerce-layout> | ||
<atomic-layout-section section="search"> | ||
<atomic-commerce-search-box></atomic-commerce-search-box> | ||
</atomic-layout-section> | ||
<atomic-layout-section section="main"> | ||
<atomic-layout-section section="status"> | ||
${story()} | ||
</atomic-layout-section> | ||
</atomic-layout-section> | ||
</atomic-commerce-layout>`, | ||
], | ||
play: async (context) => { | ||
await play(context); | ||
}, | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
import {test, expect} from './fixture'; | ||
|
||
test.describe('when search has not been executed', () => { | ||
test.beforeEach(async ({querySummary}) => { | ||
await querySummary.load(); | ||
}); | ||
|
||
test('should display a placeholder', async ({querySummary}) => { | ||
await expect(querySummary.placeholder).not.toBeVisible(); | ||
}); | ||
}); | ||
|
||
test.describe('after searching for kayak', () => { | ||
test.beforeEach(async ({searchBox, querySummary}) => { | ||
await querySummary.load({}, 'with-search-box'); | ||
await searchBox.hydrated.waitFor(); | ||
await searchBox.searchInput.fill('kayak'); | ||
await searchBox.submitButton.click(); | ||
}); | ||
|
||
test('should not display duration by default', async ({querySummary}) => { | ||
const textRegex = /^Results 1-[\d,]+ of [\d,]+ for kayak$/; | ||
await expect(querySummary.text(textRegex)).toBeVisible(); | ||
Check failure on line 23 in packages/atomic/src/components/commerce/atomic-commerce-query-summary/e2e/atomic-commerce-query-summary.e2e.ts GitHub Actions / Run Playwright tests for Atomic[webkit] › components/commerce/atomic-commerce-query-summary/e2e/atomic-commerce-query-summary.e2e.ts:21:7 › after searching for kayak › should not display duration by default
Check failure on line 23 in packages/atomic/src/components/commerce/atomic-commerce-query-summary/e2e/atomic-commerce-query-summary.e2e.ts GitHub Actions / Run Playwright tests for Atomic[webkit] › components/commerce/atomic-commerce-query-summary/e2e/atomic-commerce-query-summary.e2e.ts:21:7 › after searching for kayak › should not display duration by default
Check failure on line 23 in packages/atomic/src/components/commerce/atomic-commerce-query-summary/e2e/atomic-commerce-query-summary.e2e.ts GitHub Actions / Run Playwright tests for Atomic[webkit] › components/commerce/atomic-commerce-query-summary/e2e/atomic-commerce-query-summary.e2e.ts:21:7 › after searching for kayak › should not display duration by default
Check failure on line 23 in packages/atomic/src/components/commerce/atomic-commerce-query-summary/e2e/atomic-commerce-query-summary.e2e.ts GitHub Actions / Run Playwright tests for Atomic[chromium] › components/commerce/atomic-commerce-query-summary/e2e/atomic-commerce-query-summary.e2e.ts:21:7 › after searching for kayak › should not display duration by default
|
||
}); | ||
}); | ||
|
||
test.describe('when search yields no results', () => { | ||
test.beforeEach(async ({querySummary}) => { | ||
await querySummary.load({}, 'no-results'); | ||
}); | ||
|
||
test('should not display anything', async ({querySummary}) => { | ||
await expect(querySummary.hydrated).toBeEmpty(); | ||
}); | ||
}); | ||
|
||
test.describe('when search yields 27 results', () => { | ||
test.beforeEach(async ({querySummary}) => { | ||
await querySummary.load({}, 'fixed-number-of-results'); | ||
}); | ||
|
||
test('screen readers should read out', async ({querySummary}) => { | ||
const textRegex = /Results 1-27 of [\d,]+/; | ||
await expect(querySummary.ariaLive(textRegex)).toBeVisible(); | ||
}); | ||
}); | ||
|
||
test.describe('when a query yield a single result', () => { | ||
test.beforeEach(async ({querySummary, searchBox}) => { | ||
await querySummary.load({}, 'with-search-box'); | ||
await searchBox.hydrated.waitFor(); | ||
await searchBox.searchInput.fill('@ec_product_id=SP03730_00007'); | ||
await searchBox.submitButton.click(); | ||
}); | ||
|
||
test('should display message', async ({querySummary}) => { | ||
const textRegex = /^Result 1 of 1 for @ec_product_id=SP03730_00007$/; | ||
await expect(querySummary.text(textRegex)).toBeVisible(); | ||
Check failure on line 58 in packages/atomic/src/components/commerce/atomic-commerce-query-summary/e2e/atomic-commerce-query-summary.e2e.ts GitHub Actions / Run Playwright tests for Atomic[webkit] › components/commerce/atomic-commerce-query-summary/e2e/atomic-commerce-query-summary.e2e.ts:56:7 › when a query yield a single result › should display message
Check failure on line 58 in packages/atomic/src/components/commerce/atomic-commerce-query-summary/e2e/atomic-commerce-query-summary.e2e.ts GitHub Actions / Run Playwright tests for Atomic[webkit] › components/commerce/atomic-commerce-query-summary/e2e/atomic-commerce-query-summary.e2e.ts:56:7 › when a query yield a single result › should display message
Check failure on line 58 in packages/atomic/src/components/commerce/atomic-commerce-query-summary/e2e/atomic-commerce-query-summary.e2e.ts GitHub Actions / Run Playwright tests for Atomic[webkit] › components/commerce/atomic-commerce-query-summary/e2e/atomic-commerce-query-summary.e2e.ts:56:7 › when a query yield a single result › should display message
|
||
}); | ||
|
||
test('screen readers should read out', async ({querySummary}) => { | ||
const textRegex = /^Result 1 of 1 for @ec_product_id=SP03730_00007$/; | ||
await expect(querySummary.ariaLive(textRegex)).toBeVisible(); | ||
}); | ||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import {test as base} from '@playwright/test'; | ||
import { | ||
AxeFixture, | ||
makeAxeBuilder, | ||
} from '../../../../../playwright-utils/base-fixture'; | ||
import {SearchBoxPageObject as SearchBox} from '../../atomic-commerce-search-box/e2e/page-object'; | ||
import {QuerySummaryPageObject as QuerySummary} from './page-object'; | ||
|
||
type MyFixtures = { | ||
searchBox: SearchBox; | ||
querySummary: QuerySummary; | ||
}; | ||
|
||
export const test = base.extend<MyFixtures & AxeFixture>({ | ||
makeAxeBuilder, | ||
searchBox: async ({page}, use) => { | ||
await use(new SearchBox(page)); | ||
}, | ||
querySummary: async ({page}, use) => { | ||
await use(new QuerySummary(page)); | ||
}, | ||
}); | ||
export {expect} from '@playwright/test'; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import type {Page} from '@playwright/test'; | ||
import {BasePageObject} from '../../../../../playwright-utils/base-page-object'; | ||
|
||
export class QuerySummaryPageObject extends BasePageObject<'atomic-commerce-query-summary'> { | ||
constructor(page: Page) { | ||
super(page, 'atomic-commerce-query-summary'); | ||
} | ||
|
||
get placeholder() { | ||
return this.page.locator('[part="placeholder"]'); | ||
} | ||
|
||
ariaLive(textRegex: RegExp) { | ||
return this.page.getByRole('status').filter({hasText: textRegex}); | ||
} | ||
|
||
text(summaryRegex: RegExp) { | ||
return this.page.getByText(summaryRegex); | ||
} | ||
} |