-
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.
chore(atomic): various utils fixes (#4878)
storybook: add mdx support storybook-dev: sync up lang & assets after a watch cycle dev: ignore e2e from watch cycle lit: add barebone base page object https://coveord.atlassian.net/browse/KIT-3897 --------- Co-authored-by: Alex Prudhomme <[email protected]> Co-authored-by: GitHub Actions Bot <>
- Loading branch information
1 parent
6537c36
commit 0bd99f2
Showing
4 changed files
with
113 additions
and
4 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
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 |
---|---|---|
@@ -0,0 +1,82 @@ | ||
import type {Page} from '@playwright/test'; | ||
import {buildArgsParam} from '@storybook/router'; | ||
|
||
type Component = Record<string, unknown>; | ||
|
||
export class BasePageObject { | ||
constructor( | ||
public page: Page, | ||
public tag: string | ||
) {} | ||
|
||
get urlRoot() { | ||
return 'http://localhost:4400/iframe.html'; | ||
} | ||
|
||
get hydrated() { | ||
return this.page.locator(`${this.tag}`); | ||
} | ||
|
||
async load({ | ||
args, | ||
story = 'default', | ||
}: {args?: Record<string, unknown>; story?: string} = {}) { | ||
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}`); | ||
} | ||
} | ||
|
||
async noProducts() { | ||
await this.page.route('**/commerce/v2/search', async (route) => { | ||
const response = await route.fetch(); | ||
const body = await response.json(); | ||
body.products = []; | ||
if (body.pagination) { | ||
body.pagination.totalEntries = 0; | ||
body.pagination.totalPages = 0; | ||
} | ||
body.facets = []; | ||
await route.fulfill({ | ||
response, | ||
json: body, | ||
}); | ||
}); | ||
|
||
return this; | ||
} | ||
|
||
async noRecommendations() { | ||
return this.nRecommendations(0); | ||
} | ||
|
||
async nRecommendations(numberOfRecommendations?: number) { | ||
await this.page.route('**/commerce/v2/recommendations', async (route) => { | ||
const response = await route.fetch(); | ||
const body = await response.json(); | ||
if (numberOfRecommendations !== undefined) { | ||
body['products'] = body['products'].slice(0, numberOfRecommendations); | ||
} | ||
await route.fulfill({ | ||
response, | ||
json: body, | ||
}); | ||
}); | ||
|
||
return this; | ||
} | ||
|
||
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