Skip to content

Commit

Permalink
test(message): refactor tests to use beforeEach for page navigation
Browse files Browse the repository at this point in the history
  • Loading branch information
max-umain committed Dec 16, 2024
1 parent 297e483 commit 379992e
Show file tree
Hide file tree
Showing 9 changed files with 27 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,16 @@ import { expect } from '@playwright/test';
const componentTestPath = 'src/components/message/test/basic/index.html';

test.describe.parallel('tds-message-basic', () => {
test('is basic message rendered correctly', async ({ page }) => {
test.beforeEach(async ({ page }) => {
await page.goto(componentTestPath);
});

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

test('has icon', async ({ page }) => {
await page.goto(componentTestPath);
const messageIcon = page.getByRole('img');
await expect(messageIcon).toHaveCount(1);
await expect(messageIcon).toBeVisible();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,29 +4,28 @@ import { expect } from '@playwright/test';
const componentTestPath = 'src/components/message/test/error/index.html';

test.describe.parallel('tds-message-error', () => {
test('is error message rendered correctly', async ({ page }) => {
test.beforeEach(async ({ page }) => {
await page.goto(componentTestPath);
});

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

test('has header text', async ({ page }) => {
await page.goto(componentTestPath);
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
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@ import { expect } from '@playwright/test';
const componentTestPath = 'src/components/message/test/information/primary/darkmode/index.html';

test.describe('tds-message-information-primary-darkmode', () => {
test('is information message rendered correctly', async ({ page }) => {
test.beforeEach(async ({ page }) => {
await page.goto(componentTestPath);
});

test('is information message rendered correctly', async ({ page }) => {
/* Take screenshot */
await expect(page).toHaveScreenshot({ maxDiffPixels: 0 });
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@ import { expect } from '@playwright/test';
const componentTestPath = 'src/components/message/test/information/primary/lightmode/index.html';

test.describe('tds-message-information-primary-lightmode', () => {
test('is information message rendered correctly', async ({ page }) => {
test.beforeEach(async ({ page }) => {
await page.goto(componentTestPath);
});

test('is information message rendered correctly', async ({ page }) => {
/* Take screenshot */
await expect(page).toHaveScreenshot({ maxDiffPixels: 0 });
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@ import { expect } from '@playwright/test';
const componentTestPath = 'src/components/message/test/information/secondary/darkmode/index.html';

test.describe('tds-message-information-secondary-darkmode', () => {
test('is information message rendered correctly', async ({ page }) => {
test.beforeEach(async ({ page }) => {
await page.goto(componentTestPath);
});

test('is information message rendered correctly', async ({ page }) => {
/* Take screenshot */
await expect(page).toHaveScreenshot({ maxDiffPixels: 0 });
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@ import { expect } from '@playwright/test';
const componentTestPath = 'src/components/message/test/information/secondary/lightmode/index.html';

test.describe('tds-message-information-secondary-lightmode', () => {
test('is information message rendered correctly', async ({ page }) => {
test.beforeEach(async ({ page }) => {
await page.goto(componentTestPath);
});

test('is information message rendered correctly', async ({ page }) => {
/* Take screenshot */
await expect(page).toHaveScreenshot({ maxDiffPixels: 0 });
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@ import { expect } from '@playwright/test';
const componentTestPath = 'src/components/message/test/information/unspecified/index.html';

test.describe('tds-message-information', () => {
test('is information message rendered correctly', async ({ page }) => {
test.beforeEach(async ({ page }) => {
await page.goto(componentTestPath);
});

test('is information message rendered correctly', async ({ page }) => {
/* Take screenshot */
await expect(page).toHaveScreenshot({ maxDiffPixels: 0 });
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@ import { expect } from '@playwright/test';
const componentTestPath = 'src/components/message/test/success/index.html';

test.describe('tds-message-success', () => {
test('is success message rendered correctly', async ({ page }) => {
test.beforeEach(async ({ page }) => {
await page.goto(componentTestPath);
});

test('is success message rendered correctly', async ({ page }) => {
/* Take screenshot */
await expect(page).toHaveScreenshot({ maxDiffPixels: 0 });
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@ import { expect } from '@playwright/test';
const componentTestPath = 'src/components/message/test/warning/index.html';

test.describe('tds-message-warning', () => {
test('is warning message rendered correctly', async ({ page }) => {
test.beforeEach(async ({ page }) => {
await page.goto(componentTestPath);
});

test('is warning message rendered correctly', async ({ page }) => {
/* Take screenshot */
await expect(page).toHaveScreenshot({ maxDiffPixels: 0 });
});
Expand Down

0 comments on commit 379992e

Please sign in to comment.