-
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): start tests on atomic-commerce-facets (#4071)
Mostly: Add new `base-page-object` to inherit from for each tests, which should simplify/streamline the "load this story for this component with these arguments in the URL" repetitive pattern. https://coveord.atlassian.net/browse/KIT-3256
- Loading branch information
Showing
18 changed files
with
306 additions
and
77 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
File renamed without changes.
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,42 @@ | ||
import type {Page} from '@playwright/test'; | ||
import {buildArgsParam} from '@storybook/router'; | ||
import {JSX} from '../dist/types/components'; | ||
|
||
export class BasePageObject< | ||
TagName extends keyof JSX.IntrinsicElements, | ||
Component = JSX.IntrinsicElements[TagName], | ||
> { | ||
constructor( | ||
public page: Page, | ||
public tag: TagName | ||
) {} | ||
|
||
get hydrated() { | ||
return this.page.locator(`${this.tag}[class*="hydrated"]`); | ||
} | ||
|
||
get urlRoot() { | ||
return 'http://localhost:4400/iframe.html'; | ||
} | ||
|
||
async load(args?: Component, story: string = 'default') { | ||
if (args) { | ||
await this.page.goto( | ||
`${this.urlRoot}?id=${this.tag}--${story}&args=${buildArgsParam(undefined, this.camelToKebab(args))}` | ||
); | ||
} else { | ||
await this.page.goto(`${this.urlRoot}?id=${this.tag}--${story}`); | ||
} | ||
} | ||
|
||
private camelToKebab(args: Component) { | ||
const toKebab: Record<string, unknown> = {}; | ||
Object.entries(args as Record<string, unknown>).forEach(([key, value]) => { | ||
toKebab[ | ||
`attributes-${key.replace(/([a-z0-9]|(?=[A-Z]))([A-Z])/g, '$1-$2').toLowerCase()}` | ||
] = value; | ||
}); | ||
|
||
return toKebab; | ||
} | ||
} |
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
6 changes: 3 additions & 3 deletions
6
...ages/atomic/src/components/commerce/atomic-commerce-load-more-products/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
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
22 changes: 11 additions & 11 deletions
22
packages/atomic/src/components/commerce/atomic-commerce-search-box/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 |
---|---|---|
@@ -1,28 +1,28 @@ | ||
import {test as base} from '@playwright/test'; | ||
import { | ||
AxeFixture, | ||
makeAxeBuilder, | ||
} from '@coveo/atomic/playwrightUtils/base-fixture'; | ||
import {test as base} from '@playwright/test'; | ||
import {AtomicCommerceLoadMoreProductsLocators as LoadMore} from '../../atomic-commerce-load-more-products/e2e/page-object'; | ||
import {AtomicCommerceFacetsLocators as Facets} from '../../facets/atomic-commerce-facets/e2e/page-object'; | ||
import {AtomicCommerceSearchBoxLocators as SearchBox} from './page-object'; | ||
} from '../../../../../playwright-utils/base-fixture'; | ||
import {LoadMoreProductsPageObject} from '../../atomic-commerce-load-more-products/e2e/page-object'; | ||
import {FacetsPageObject} from '../../facets/atomic-commerce-facets/e2e/page-object'; | ||
import {SearchBoxPageObject} from './page-object'; | ||
|
||
type MyFixtures = { | ||
searchBox: SearchBox; | ||
facets: Facets; | ||
loadMore: LoadMore; | ||
searchBox: SearchBoxPageObject; | ||
facets: FacetsPageObject; | ||
loadMore: LoadMoreProductsPageObject; | ||
}; | ||
|
||
export const test = base.extend<MyFixtures & AxeFixture>({ | ||
makeAxeBuilder, | ||
searchBox: async ({page}, use) => { | ||
await use(new SearchBox(page)); | ||
await use(new SearchBoxPageObject(page)); | ||
}, | ||
facets: async ({page}, use) => { | ||
await use(new Facets(page)); | ||
await use(new FacetsPageObject(page)); | ||
}, | ||
loadMore: async ({page}, use) => { | ||
await use(new LoadMore(page)); | ||
await use(new LoadMoreProductsPageObject(page)); | ||
}, | ||
}); | ||
export {expect} from '@playwright/test'; |
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
Oops, something went wrong.