Skip to content

Commit

Permalink
add all tests definitions
Browse files Browse the repository at this point in the history
  • Loading branch information
alexprudhomme committed Sep 30, 2024
1 parent b786c5a commit 555317d
Show file tree
Hide file tree
Showing 4 changed files with 115 additions and 39 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import {wrapInCommerceProductList} from '@coveo/atomic-storybook-utils/commerce/
import {wrapInProductTemplate} from '@coveo/atomic-storybook-utils/commerce/commerce-product-template-wrapper';
import {parameters} from '@coveo/atomic-storybook-utils/common/common-meta-parameters';
import {renderComponent} from '@coveo/atomic-storybook-utils/common/render-component';
import type {Meta} from '@storybook/web-components';
import type {Meta, StoryObj as Story} from '@storybook/web-components';

const {
decorator: commerceInterfaceDecorator,
Expand Down Expand Up @@ -41,16 +41,16 @@ const meta: Meta = {

export default meta;

// export const Default: Story = {
// name: 'atomic-product-image',
// args: {
// 'attributes-fallback': '2',
// play: async (context) => {
// await play(context);
// await playExecuteFirstSearch(context);
// },
// },
// };
export const Default: Story = {
name: 'atomic-product-image',
};

export const withAFallbackImage: Story = {
name: 'With a fallback image',
args: {
'attributes-fallback': 'https://sports.barca.group/logos/barca.svg',
},
};

// const {play: playWithMultipleImages} = wrapInCommerceInterface({
// engineConfig: {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,37 +1,110 @@
import {test} from './fixture';
/* eslint-disable @cspell/spellchecker */
import {test, expect} from './fixture';

// test.describe('default', async () => {
// test.describe('when clicking on the next button', async ({productImage}) => {
// test.fixme('should navigate to the next image', () => {});
// test.fixme('should not open the product', () => {});
// });
// test.describe('when clicking on the previous button', async ({productImage}) => {
// test.fixme('should navigate to the previous image', () => {});
// test.fixme('should not open the product', () => {});
// });
// });
test.describe('default', async () => {
test.beforeEach(async ({productImage}) => {
await productImage.load();
await productImage.hydrated.nth(1).waitFor();
});

// default
test('should be accessible', async ({makeAxeBuilder}) => {
const accessibilityResults = await makeAxeBuilder().analyze();
expect(accessibilityResults.violations.length).toEqual(0);
});

// accessible
test('should render the image', async ({productImage}) => {
expect(productImage.image.nth(1)).toBeVisible();
});

// image alt field
test('should have a default alt text', async ({productImage}) => {
const altText = await productImage.image.nth(1).getAttribute('alt');
expect(altText).toEqual('Image 1 out of 1 for Nublu Water Bottle');

Check failure on line 21 in packages/atomic/src/components/commerce/product-template-components/atomic-product-image/e2e/atomic-product-image.e2e.ts

View workflow job for this annotation

GitHub Actions / Run Playwright tests for Atomic (13, 24)

[chromium] › components/commerce/product-template-components/atomic-product-image/e2e/atomic-product-image.e2e.ts:19:3 › default › should have a default alt text

1) [chromium] › components/commerce/product-template-components/atomic-product-image/e2e/atomic-product-image.e2e.ts:19:3 › default › should have a default alt text Error: expect(received).toEqual(expected) // deep equality Expected: "Image 1 out of 1 for Nublu Water Bottle" Received: "Image 1 out of 1 for Waxique Epoxy Wax" 19 | test('should have a default alt text', async ({productImage}) => { 20 | const altText = await productImage.image.nth(1).getAttribute('alt'); > 21 | expect(altText).toEqual('Image 1 out of 1 for Nublu Water Bottle'); | ^ 22 | }); 23 | 24 | test('should have a 1:1 aspect ratio', async ({productImage}) => { at /home/runner/work/ui-kit/ui-kit/packages/atomic/src/components/commerce/product-template-components/atomic-product-image/e2e/atomic-product-image.e2e.ts:21:21

Check failure on line 21 in packages/atomic/src/components/commerce/product-template-components/atomic-product-image/e2e/atomic-product-image.e2e.ts

View workflow job for this annotation

GitHub Actions / Run Playwright tests for Atomic (13, 24)

[chromium] › components/commerce/product-template-components/atomic-product-image/e2e/atomic-product-image.e2e.ts:19:3 › default › should have a default alt text

1) [chromium] › components/commerce/product-template-components/atomic-product-image/e2e/atomic-product-image.e2e.ts:19:3 › default › should have a default alt text Retry #1 ─────────────────────────────────────────────────────────────────────────────────────── Error: expect(received).toEqual(expected) // deep equality Expected: "Image 1 out of 1 for Nublu Water Bottle" Received: "Image 1 out of 1 for Waxique Epoxy Wax" 19 | test('should have a default alt text', async ({productImage}) => { 20 | const altText = await productImage.image.nth(1).getAttribute('alt'); > 21 | expect(altText).toEqual('Image 1 out of 1 for Nublu Water Bottle'); | ^ 22 | }); 23 | 24 | test('should have a 1:1 aspect ratio', async ({productImage}) => { at /home/runner/work/ui-kit/ui-kit/packages/atomic/src/components/commerce/product-template-components/atomic-product-image/e2e/atomic-product-image.e2e.ts:21:21

Check failure on line 21 in packages/atomic/src/components/commerce/product-template-components/atomic-product-image/e2e/atomic-product-image.e2e.ts

View workflow job for this annotation

GitHub Actions / Run Playwright tests for Atomic (13, 24)

[chromium] › components/commerce/product-template-components/atomic-product-image/e2e/atomic-product-image.e2e.ts:19:3 › default › should have a default alt text

1) [chromium] › components/commerce/product-template-components/atomic-product-image/e2e/atomic-product-image.e2e.ts:19:3 › default › should have a default alt text Retry #2 ─────────────────────────────────────────────────────────────────────────────────────── Error: expect(received).toEqual(expected) // deep equality Expected: "Image 1 out of 1 for Nublu Water Bottle" Received: "Image 1 out of 1 for Waxique Epoxy Wax" 19 | test('should have a default alt text', async ({productImage}) => { 20 | const altText = await productImage.image.nth(1).getAttribute('alt'); > 21 | expect(altText).toEqual('Image 1 out of 1 for Nublu Water Bottle'); | ^ 22 | }); 23 | 24 | test('should have a 1:1 aspect ratio', async ({productImage}) => { at /home/runner/work/ui-kit/ui-kit/packages/atomic/src/components/commerce/product-template-components/atomic-product-image/e2e/atomic-product-image.e2e.ts:21:21
});

// fallback
test('should have a 1:1 aspect ratio', async ({productImage}) => {
const aspectRatio = await productImage.image.nth(1).getAttribute('class');
expect(aspectRatio).toEqual('aspect-square');
});
});

test.describe('with a fallback image', async () => {
test.beforeEach(async ({productImage}) => {
await productImage.withNoImage();
await productImage.load({story: 'with-a-fallback-image'});
});
test('should render the fallback image when the product image is missing', async ({
page,
}) => {
await page.waitForTimeout(11000);
});
test('should render the fallback image when the product image is invalid', () => {});
test('should render the fallback image when the product image is not a string', () => {});
});

test.describe('with an alt text field', async () => {
test.describe('when imageAltField is a string', () => {
test('should be accessible', async ({makeAxeBuilder}) => {
const accessibilityResults = await makeAxeBuilder().analyze();
expect(accessibilityResults.violations.length).toEqual(0);
});

test('should use the same alt text for all images', () => {});
});

test.describe('when imageAltField is an array of strings', () => {
test('should be accessible', async ({makeAxeBuilder}) => {
const accessibilityResults = await makeAxeBuilder().analyze();
expect(accessibilityResults.violations.length).toEqual(0);
});

// as carousel (cant make a story for this)
test('should use different alt texts for each image', () => {});
test('should correctly assign alt text for the first image', () => {});
test('should correctly assign alt text for the last image', () => {});
test('should handle missing alt text for one of the images', () => {});
test('should handle an array of alt texts shorter than the number of images', () => {});
test('should handle an array of alt texts longer than the number of images', () => {});
});

test('as carousel', async ({productImage, page}) => {
await productImage.withMoreImages();
await productImage.load();
await page.waitForTimeout(10000);
test.describe('when imageAltField is not specified', () => {
test('should be accessible', async ({makeAxeBuilder}) => {
const accessibilityResults = await makeAxeBuilder().analyze();
expect(accessibilityResults.violations.length).toEqual(0);
});

test('should generate default alt text for all images', () => {});
test('should generate alt text with correct image index and total count', () => {});
});

test.describe('when imageAltField is invalid or contains non-string values', () => {
test('should be accessible', async ({makeAxeBuilder}) => {
const accessibilityResults = await makeAxeBuilder().analyze();
expect(accessibilityResults.violations.length).toEqual(0);
});

test('should generate fallback alt text when imageAltField is not a string or array', () => {});
});

test.describe('when imageAltField is an empty array', () => {
test('', () => {});
test('should handle a null or undefined value for imageAltField', () => {});
});
});

test('when the image url is not valid, should render the component with fallback image & output error message', () => {});
test('when the image url is not a string, should render the component with fallback image & output error message', () => {});
test.describe('as a carousel', async () => {
test('should be accessible', async ({makeAxeBuilder}) => {
const accessibilityResults = await makeAxeBuilder().analyze();
expect(accessibilityResults.violations.length).toEqual(0);
});

test('should render the first image by default', () => {});

test.describe('when clicking the next button', () => {
test('should navigate to the next image', () => {});
test('should not open the product', () => {});
});

test('when rendered as a single image', async ({productImage, page}) => {
await productImage.withNoImage();
await productImage.load();
await page.waitForTimeout(10000);
test.describe('when clicking the previous button', () => {
test('should navigate to the previous image', () => {});
test('should not open the product', () => {});
});
});
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import {SortBy} from '@coveo/headless/commerce';
import {CommerceSuccessResponse} from '@coveo/headless/dist/definitions/api/commerce/common/response';
import {test as base, Page} from '@playwright/test';
import {
AxeFixture,
Expand Down Expand Up @@ -63,7 +62,7 @@ export async function setImages(page: Page, urls: string[]) {
availableSorts: [],
},
triggers: [],
} as CommerceSuccessResponse),
}),
});
});
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ export class ProductImageObject extends BasePageObject<'atomic-product-image'> {
super(page, 'atomic-product-image');
}

get image() {
return this.page.getByRole('img');
}

async withMoreImages() {
await this.page.route('**/commerce/v2/listing', async (route) => {
const response = await route.fetch();
Expand Down

0 comments on commit 555317d

Please sign in to comment.