Skip to content

Commit

Permalink
test(message): add screenshot tests using reusable test code (#948)
Browse files Browse the repository at this point in the history
  • Loading branch information
max-umain authored Jan 15, 2025
1 parent 416d572 commit 2c87518
Show file tree
Hide file tree
Showing 29 changed files with 92 additions and 29 deletions.
28 changes: 22 additions & 6 deletions packages/core/src/components/message/test/basic/message.e2e.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,34 @@
import { test } from 'stencil-playwright';
import { expect } from '@playwright/test';
import {
testConfigurations,
getTestDescribeText,
setupPage,
} from '../../../../utils/testConfiguration';

const componentTestPath = 'src/components/message/test/basic/index.html';
const componentName = 'tds-message';
const testDescription = 'tds-message-basic';

test.describe.parallel('tds-message-basic', () => {
test('is basic message rendered correctly', async ({ page }) => {
await page.goto(componentTestPath);
testConfigurations.withModeVariants.forEach((config) => {
test.describe.parallel(getTestDescribeText(config, testDescription), () => {
test.beforeEach(async ({ page }) => {
await setupPage(page, config, componentTestPath, componentName);
});

/* Check diff on screenshot */
await expect(page).toHaveScreenshot({ maxDiffPixels: 0 });
test('is basic message rendered correctly', async ({ page }) => {
/* Check diff on screenshot */
await expect(page).toHaveScreenshot({ maxDiffPixels: 0 });
});
});
});

test('has icon', async ({ page }) => {
test.describe.parallel(componentName, () => {
test.beforeEach(async ({ page }) => {
await page.goto(componentTestPath);
});

test('has icon', async ({ page }) => {
const messageIcon = page.getByRole('img');
await expect(messageIcon).toHaveCount(1);
await expect(messageIcon).toBeVisible();
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
30 changes: 22 additions & 8 deletions packages/core/src/components/message/test/error/message.e2e.ts
Original file line number Diff line number Diff line change
@@ -1,32 +1,46 @@
import { test } from 'stencil-playwright';
import { expect } from '@playwright/test';
import {
testConfigurations,
getTestDescribeText,
setupPage,
} from '../../../../utils/testConfiguration';

const componentTestPath = 'src/components/message/test/error/index.html';
const componentName = 'tds-message';
const testDescription = 'tds-message-error';

test.describe.parallel('tds-message-error', () => {
test('is error message rendered correctly', async ({ page }) => {
await page.goto(componentTestPath);
testConfigurations.withModeVariants.forEach((config) => {
test.describe.parallel(getTestDescribeText(config, testDescription), () => {
test.beforeEach(async ({ page }) => {
await setupPage(page, config, componentTestPath, componentName);
});

/* Check diff on screenshot */
await expect(page).toHaveScreenshot({ maxDiffPixels: 0 });
test('is error message rendered correctly', async ({ page }) => {
/* Check diff on screenshot */
await expect(page).toHaveScreenshot({ maxDiffPixels: 0 });
});
});
});

test('has header text', async ({ page }) => {
test.describe.parallel(componentName, () => {
test.beforeEach(async ({ page }) => {
await page.goto(componentTestPath);
});

test('has header text', async ({ page }) => {
const messageComponentHeader = page.getByText('Message header', { exact: true });
await expect(messageComponentHeader).toHaveCount(1);
await expect(messageComponentHeader).toBeVisible();
});

test('has subheader text', async ({ page }) => {
await page.goto(componentTestPath);
const messageComponentSubHeader = page.getByText('Longer Message text can be placed here.');
await expect(messageComponentSubHeader).toHaveCount(1);
await expect(messageComponentSubHeader).toBeVisible();
});

test('has error icon', async ({ page }) => {
await page.goto(componentTestPath);
const messageIcon = page.getByRole('img');
await expect(messageIcon).toHaveCount(1);
await expect(messageIcon).toBeVisible();
Expand Down
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -1,13 +1,24 @@
import { test } from 'stencil-playwright';
import { expect } from '@playwright/test';
import {
testConfigurations,
getTestDescribeText,
setupPage,
} from '../../../../utils/testConfiguration';

const componentTestPath = 'src/components/message/test/information/index.html';
const componentName = 'tds-message';
const testDescription = 'tds-message-information';

test.describe('tds-message-information', () => {
test('is information message rendered correctly', async ({ page }) => {
await page.goto(componentTestPath);
testConfigurations.withModeVariants.forEach((config) => {
test.describe.parallel(getTestDescribeText(config, testDescription), () => {
test.beforeEach(async ({ page }) => {
await setupPage(page, config, componentTestPath, componentName);
});

/* Take screenshot */
await expect(page).toHaveScreenshot({ maxDiffPixels: 0 });
test('is information message rendered correctly', async ({ page }) => {
/* Take screenshot */
await expect(page).toHaveScreenshot({ maxDiffPixels: 0 });
});
});
});
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
21 changes: 16 additions & 5 deletions packages/core/src/components/message/test/success/message.e2e.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,24 @@
import { test } from 'stencil-playwright';
import { expect } from '@playwright/test';
import {
testConfigurations,
getTestDescribeText,
setupPage,
} from '../../../../utils/testConfiguration';

const componentTestPath = 'src/components/message/test/success/index.html';
const componentName = 'tds-message';
const testDescription = 'tds-message-success';

test.describe('tds-message-success', () => {
test('is success message rendered correctly', async ({ page }) => {
await page.goto(componentTestPath);
testConfigurations.withModeVariants.forEach((config) => {
test.describe.parallel(getTestDescribeText(config, testDescription), () => {
test.beforeEach(async ({ page }) => {
await setupPage(page, config, componentTestPath, componentName);
});

/* Take screenshot */
await expect(page).toHaveScreenshot({ maxDiffPixels: 0 });
test('is success message rendered correctly', async ({ page }) => {
/* Take screenshot */
await expect(page).toHaveScreenshot({ maxDiffPixels: 0 });
});
});
});
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
21 changes: 16 additions & 5 deletions packages/core/src/components/message/test/warning/message.e2e.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,24 @@
import { test } from 'stencil-playwright';
import { expect } from '@playwright/test';
import {
testConfigurations,
getTestDescribeText,
setupPage,
} from '../../../../utils/testConfiguration';

const componentTestPath = 'src/components/message/test/warning/index.html';
const componentName = 'tds-message';
const testDescription = 'tds-message-warning';

test.describe('tds-message-warning', () => {
test('is warning message rendered correctly', async ({ page }) => {
await page.goto(componentTestPath);
testConfigurations.withModeVariants.forEach((config) => {
test.describe.parallel(getTestDescribeText(config, testDescription), () => {
test.beforeEach(async ({ page }) => {
await setupPage(page, config, componentTestPath, componentName);
});

/* Take screenshot */
await expect(page).toHaveScreenshot({ maxDiffPixels: 0 });
test('is warning message rendered correctly', async ({ page }) => {
/* Take screenshot */
await expect(page).toHaveScreenshot({ maxDiffPixels: 0 });
});
});
});
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 2c87518

Please sign in to comment.