Skip to content

Commit

Permalink
add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
alexprudhomme committed Sep 26, 2024
1 parent 89544fd commit b70fb2a
Show file tree
Hide file tree
Showing 5 changed files with 145 additions and 14 deletions.
16 changes: 16 additions & 0 deletions packages/atomic/playwright-utils/base-page-object.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,22 @@ export class BasePageObject<
return this;
}

async noRecommendations() {
await this.page.route('**/commerce/v2/recommendations', async (route) => {
const response = await route.fetch();
const body = await response.json();
body.products = [];
console.log(body);

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]) => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,103 @@
import {test} from './fixture';
import {test, expect} from './fixture';

test.describe('default', () => {
test('should be A11Y compliant', async () => {});
test.describe('before query is loaded', () => {
test.beforeEach(async ({recommendationList}) => {
await recommendationList.load({story: 'before-query'});
await recommendationList.hydrated.waitFor();
});

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

test('should have placeholders', async ({recommendationList}) => {
await expect(recommendationList.placeholder.first()).toBeVisible();
});
});

test.describe('after query is loaded', () => {
test.beforeEach(async ({recommendationList}) => {
await recommendationList.load({story: 'default'});
await recommendationList.hydrated.waitFor();
});

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

test('should have recommendations', async ({recommendationList}) => {
await expect(recommendationList.recommendation.first()).toBeVisible();
});
});

test.describe('with a full result template', () => {
test.beforeEach(async ({recommendationList}) => {
await recommendationList.load({story: 'with-full-template'});
await recommendationList.hydrated.waitFor();
});

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

test('should have recommendations', async ({recommendationList}) => {
await expect(recommendationList.recommendation.first()).toBeVisible();
});
});

test.describe('with a carousel', () => {
test.beforeEach(async ({recommendationList}) => {
await recommendationList.load({story: 'as-carousel'});
await recommendationList.hydrated.waitFor();
});

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

test('should have recommendations', async ({recommendationList}) => {
await expect(recommendationList.recommendation.first()).toBeVisible();
});

test('should support going forward and backward', async ({
recommendationList,
}) => {
await recommendationList.nextButton.click();
await expect(recommendationList.indicators.nth(1)).toHaveAttribute(
'part',
'indicator active-indicator'
);

await recommendationList.prevButton.click();
await recommendationList.prevButton.click();
await expect(recommendationList.indicators.nth(2)).toHaveAttribute(

Check failure on line 77 in packages/atomic/src/components/commerce/atomic-commerce-recommendation-list/e2e/atomic-commerce-recommendation-list.e2e.ts

View workflow job for this annotation

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

[chromium] › components/commerce/atomic-commerce-recommendation-list/e2e/atomic-commerce-recommendation-list.e2e.ts:66:3 › with a carousel › should support going forward and backward

1) [chromium] › components/commerce/atomic-commerce-recommendation-list/e2e/atomic-commerce-recommendation-list.e2e.ts:66:3 › with a carousel › should support going forward and backward Error: Timed out 7000ms waiting for expect(locator).toHaveAttribute(expected) Locator: getByRole('listitem').nth(2) Expected string: "indicator active-indicator" Received string: "indicator " Call log: - expect.toHaveAttribute with timeout 7000ms - waiting for getByRole('listitem').nth(2) - locator resolved to <li part="indicator " class="h-1 w-12 rounded-md bg-neutral"></li> - unexpected value "indicator " - locator resolved to <li part="indicator " class="h-1 w-12 rounded-md bg-neutral"></li> - unexpected value "indicator " - locator resolved to <li part="indicator " class="h-1 w-12 rounded-md bg-neutral"></li> - unexpected value "indicator " - locator resolved to <li part="indicator " class="h-1 w-12 rounded-md bg-neutral"></li> - unexpected value "indicator " - locator resolved to <li part="indicator " class="h-1 w-12 rounded-md bg-neutral"></li> - unexpected value "indicator " - locator resolved to <li part="indicator " class="h-1 w-12 rounded-md bg-neutral"></li> - unexpected value "indicator " - locator resolved to <li part="indicator " class="h-1 w-12 rounded-md bg-neutral"></li> - unexpected value "indicator " - locator resolved to <li part="indicator " class="h-1 w-12 rounded-md bg-neutral"></li> - unexpected value "indicator " - locator resolved to <li part="indicator " class="h-1 w-12 rounded-md bg-neutral"></li> - unexpected value "indicator " - locator resolved to <li part="indicator " class="h-1 w-12 rounded-md bg-neutral"></li> - unexpected value "indicator " - locator resolved to <li part="indicator " class="h-1 w-12 rounded-md bg-neutral"></li> - unexpected value "indicator " 75 | await recommendationList.prevButton.click(); 76 | await recommendationList.prevButton.click(); > 77 | await expect(recommendationList.indicators.nth(2)).toHaveAttribute( | ^ 78 | 'part', 79 | 'indicator active-indicator' 80 | ); at /home/runner/work/ui-kit/ui-kit/packages/atomic/src/components/commerce/atomic-commerce-recommendation-list/e2e/atomic-commerce-recommendation-list.e2e.ts:77:56

Check failure on line 77 in packages/atomic/src/components/commerce/atomic-commerce-recommendation-list/e2e/atomic-commerce-recommendation-list.e2e.ts

View workflow job for this annotation

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

[chromium] › components/commerce/atomic-commerce-recommendation-list/e2e/atomic-commerce-recommendation-list.e2e.ts:66:3 › with a carousel › should support going forward and backward

1) [chromium] › components/commerce/atomic-commerce-recommendation-list/e2e/atomic-commerce-recommendation-list.e2e.ts:66:3 › with a carousel › should support going forward and backward Retry #1 ─────────────────────────────────────────────────────────────────────────────────────── Error: Timed out 7000ms waiting for expect(locator).toHaveAttribute(expected) Locator: getByRole('listitem').nth(2) Expected string: "indicator active-indicator" Received string: "indicator " Call log: - expect.toHaveAttribute with timeout 7000ms - waiting for getByRole('listitem').nth(2) - locator resolved to <li part="indicator " class="h-1 w-12 rounded-md bg-neutral"></li> - unexpected value "indicator " - locator resolved to <li part="indicator " class="h-1 w-12 rounded-md bg-neutral"></li> - unexpected value "indicator " - locator resolved to <li part="indicator " class="h-1 w-12 rounded-md bg-neutral"></li> - unexpected value "indicator " - locator resolved to <li part="indicator " class="h-1 w-12 rounded-md bg-neutral"></li> - unexpected value "indicator " - locator resolved to <li part="indicator " class="h-1 w-12 rounded-md bg-neutral"></li> - unexpected value "indicator " - locator resolved to <li part="indicator " class="h-1 w-12 rounded-md bg-neutral"></li> - unexpected value "indicator " - locator resolved to <li part="indicator " class="h-1 w-12 rounded-md bg-neutral"></li> - unexpected value "indicator " - locator resolved to <li part="indicator " class="h-1 w-12 rounded-md bg-neutral"></li> - unexpected value "indicator " - locator resolved to <li part="indicator " class="h-1 w-12 rounded-md bg-neutral"></li> - unexpected value "indicator " - locator resolved to <li part="indicator " class="h-1 w-12 rounded-md bg-neutral"></li> - unexpected value "indicator " - locator resolved to <li part="indicator " class="h-1 w-12 rounded-md bg-neutral"></li> - unexpected value "indicator " 75 | await recommendationList.prevButton.click(); 76 | await recommendationList.prevButton.click(); > 77 | await expect(recommendationList.indicators.nth(2)).toHaveAttribute( | ^ 78 | 'part', 79 | 'indicator active-indicator' 80 | ); at /home/runner/work/ui-kit/ui-kit/packages/atomic/src/components/commerce/atomic-commerce-recommendation-list/e2e/atomic-commerce-recommendation-list.e2e.ts:77:56

Check failure on line 77 in packages/atomic/src/components/commerce/atomic-commerce-recommendation-list/e2e/atomic-commerce-recommendation-list.e2e.ts

View workflow job for this annotation

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

[chromium] › components/commerce/atomic-commerce-recommendation-list/e2e/atomic-commerce-recommendation-list.e2e.ts:66:3 › with a carousel › should support going forward and backward

1) [chromium] › components/commerce/atomic-commerce-recommendation-list/e2e/atomic-commerce-recommendation-list.e2e.ts:66:3 › with a carousel › should support going forward and backward Retry #2 ─────────────────────────────────────────────────────────────────────────────────────── Error: Timed out 7000ms waiting for expect(locator).toHaveAttribute(expected) Locator: getByRole('listitem').nth(2) Expected string: "indicator active-indicator" Received string: "indicator " Call log: - expect.toHaveAttribute with timeout 7000ms - waiting for getByRole('listitem').nth(2) - locator resolved to <li part="indicator " class="h-1 w-12 rounded-md bg-neutral"></li> - unexpected value "indicator " - locator resolved to <li part="indicator " class="h-1 w-12 rounded-md bg-neutral"></li> - unexpected value "indicator " - locator resolved to <li part="indicator " class="h-1 w-12 rounded-md bg-neutral"></li> - unexpected value "indicator " - locator resolved to <li part="indicator " class="h-1 w-12 rounded-md bg-neutral"></li> - unexpected value "indicator " - locator resolved to <li part="indicator " class="h-1 w-12 rounded-md bg-neutral"></li> - unexpected value "indicator " - locator resolved to <li part="indicator " class="h-1 w-12 rounded-md bg-neutral"></li> - unexpected value "indicator " - locator resolved to <li part="indicator " class="h-1 w-12 rounded-md bg-neutral"></li> - unexpected value "indicator " - locator resolved to <li part="indicator " class="h-1 w-12 rounded-md bg-neutral"></li> - unexpected value "indicator " - locator resolved to <li part="indicator " class="h-1 w-12 rounded-md bg-neutral"></li> - unexpected value "indicator " - locator resolved to <li part="indicator " class="h-1 w-12 rounded-md bg-neutral"></li> - unexpected value "indicator " - locator resolved to <li part="indicator " class="h-1 w-12 rounded-md bg-neutral"></li> - unexpected value "indicator " 75 | await recommendationList.prevButton.click(); 76 | await recommendationList.prevButton.click(); > 77 | await expect(recommendationList.indicators.nth(2)).toHaveAttribute( | ^ 78 | 'part', 79 | 'indicator active-indicator' 80 | ); at /home/runner/work/ui-kit/ui-kit/packages/atomic/src/components/commerce/atomic-commerce-recommendation-list/e2e/atomic-commerce-recommendation-list.e2e.ts:77:56
'part',
'indicator active-indicator'
);

await recommendationList.nextButton.click();
await expect(recommendationList.indicators.nth(0)).toHaveAttribute(
'part',
'indicator active-indicator'
);
});
});

test('with no recommendations returned by the API, should render placeholders', async ({
recommendationList,
page,
}) => {
await recommendationList.noRecommendations();
await recommendationList.load({story: 'default'});
await page.waitForTimeout(2000); // Wait for atomic components to render
await expect
.poll(async () => await recommendationList.recommendation.count())
.toBe(0);
await expect
.poll(async () => await recommendationList.placeholder.count())
.toBe(0);
});
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,26 @@ export class AtomicCommerceRecommendationList extends BasePageObject<'atomic-com
constructor(page: Page) {
super(page, 'atomic-commerce-recommendation-list');
}

get placeholder() {
return this.page.locator('.placeholder');
}

get recommendation() {
return this.page.locator(
'[part="result-list-grid-clickable-container outline"]'
);
}

get indicators() {
return this.page.getByRole('listitem');
}

get nextButton() {
return this.page.getByLabel('Next');
}

get prevButton() {
return this.page.getByLabel('Previous');
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ test.describe('before query is loaded', () => {
await recsList.hydrated.waitFor();
});

test('should be ally compliant', async ({makeAxeBuilder}) => {
test('should be a11y compliant', async ({makeAxeBuilder}) => {
const accessibilityResults = await makeAxeBuilder().analyze();
expect(accessibilityResults.violations.length).toEqual(0);
});
Expand All @@ -22,7 +22,7 @@ test.describe('after query is loaded', () => {
await recsList.hydrated.waitFor();
});

test('should be ally compliant', async ({makeAxeBuilder}) => {
test('should be a11y compliant', async ({makeAxeBuilder}) => {
const accessibilityResults = await makeAxeBuilder().analyze();
expect(accessibilityResults.violations.length).toEqual(0);
});
Expand All @@ -38,7 +38,7 @@ test.describe('with a full result template', () => {
await recsList.hydrated.waitFor();
});

test('should be ally compliant', async ({makeAxeBuilder}) => {
test('should be a11y compliant', async ({makeAxeBuilder}) => {
const accessibilityResults = await makeAxeBuilder().analyze();
expect(accessibilityResults.violations.length).toEqual(0);
});
Expand All @@ -54,7 +54,7 @@ test.describe('with a carousel', () => {
await recsList.hydrated.waitFor();
});

test('should be ally compliant', async ({makeAxeBuilder}) => {
test('should be a11y compliant', async ({makeAxeBuilder}) => {
const accessibilityResults = await makeAxeBuilder().analyze();
expect(accessibilityResults.violations.length).toEqual(0);
});
Expand Down
9 changes: 2 additions & 7 deletions packages/atomic/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
{
"extends": "./tsconfig.stencil.json",
"exclude": [
"node_modules",
"src/external-builds",
"**/*.stories.tsx",
"**/*.stories.ts",
"**/*.stories.js"
]

"exclude": ["node_modules", "src/external-builds"]
}

0 comments on commit b70fb2a

Please sign in to comment.