Skip to content

Commit

Permalink
fix flaky tests
Browse files Browse the repository at this point in the history
  • Loading branch information
fpbrault committed Oct 31, 2024
1 parent cab1ce0 commit 36e7af9
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,9 @@ test.describe('atomic-product-description', async () => {
];

truncateValues.forEach(({value, expectedClass}) => {
test.beforeEach(async ({productDescription}) => {
await productDescription.withLongDescription();
});
test.describe(`when truncateAfter is set to ${value}`, async () => {
test(`should truncate description after ${value} lines`, async ({
productDescription,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,19 @@ export class ProductDescriptionPageObject extends BasePageObject<'atomic-product
get showLessButton() {
return this.page.getByRole('button', {name: 'Show less'});
}

async withLongDescription() {
await this.page.route('**/commerce/v2/search', async (route) => {
const response = await route.fetch();
const body = await response.json();
body.products[0].ec_description =

Check failure on line 29 in packages/atomic/src/components/commerce/product-template-components/atomic-product-description/e2e/page-object.ts

View workflow job for this annotation

GitHub Actions / Run Playwright tests for Atomic (5, 6)

[chromium] › components/commerce/product-template-components/atomic-product-description/e2e/atomic-product-description.e2e.ts:149:13 › atomic-product-description › when description is truncated › when truncateAfter is set to 4 › when clicking the "Show More" button › when isCollapsible is false › should expand description

1) [chromium] › components/commerce/product-template-components/atomic-product-description/e2e/atomic-product-description.e2e.ts:149:13 › atomic-product-description › when description is truncated › when truncateAfter is set to 4 › when clicking the "Show More" button › when isCollapsible is false › should expand description TypeError: Cannot read properties of undefined (reading '0') at components/commerce/product-template-components/atomic-product-description/e2e/page-object.ts:29 27 | const response = await route.fetch(); 28 | const body = await response.json(); > 29 | body.products[0].ec_description = | ^ 30 | 'This is a long description that should be truncated'.repeat(10); 31 | await route.fulfill({ 32 | response, at /home/runner/work/ui-kit/ui-kit/packages/atomic/src/components/commerce/product-template-components/atomic-product-description/e2e/page-object.ts:29:20
'This is a long description that should be truncated'.repeat(10);
await route.fulfill({
response,
json: body,
});
});

return this;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,9 @@ test.describe('atomic-product-excerpt', async () => {
];

truncateValues.forEach(({value, expectedClass}) => {
test.beforeEach(async ({productExcerpt}) => {
await productExcerpt.withLongExcerpt();
});
test.describe(`when truncateAfter is set to ${value}`, async () => {
test(`should truncate excerpt after ${value} lines`, async ({
productExcerpt,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,19 @@ export class ProductExcerptPageObject extends BasePageObject<'atomic-product-exc
get showLessButton() {
return this.page.getByRole('button', {name: 'Show less'});
}

async withLongExcerpt() {
await this.page.route('**/commerce/v2/search', async (route) => {
const response = await route.fetch();
const body = await response.json();
body.products[0].excerpt =
'This is a long excerpt that should be truncated'.repeat(10);
await route.fulfill({
response,
json: body,
});
});

return this;
}
}

0 comments on commit 36e7af9

Please sign in to comment.