Skip to content

Commit

Permalink
test(popover-canvas): add screenshot tests using reusable test code (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
max-umain authored Jan 15, 2025
1 parent 718499b commit 416d572
Show file tree
Hide file tree
Showing 12 changed files with 79 additions and 29 deletions.
Original file line number Diff line number Diff line change
@@ -1,22 +1,39 @@
import { test } from 'stencil-playwright';
import { expect } from '@playwright/test';
import {
testConfigurations,
getTestDescribeText,
setupPage,
} from '../../../../utils/testConfiguration';

const componentTestPath = 'src/components/popover-canvas/test/default/index.html';
const componentName = 'tds-popover-canvas';
const testDescription = 'tds-popover-canvas-default';

test.describe.parallel('tds-popover-canvas-default', () => {
test('renders default popover-canvas correctly', async ({ page }) => {
await page.goto(componentTestPath);
const triggerButton = page.getByRole('button');
await triggerButton.click();
testConfigurations.basic.forEach((config) => {
test.describe.parallel(getTestDescribeText(config, testDescription), () => {
test.beforeEach(async ({ page }) => {
await setupPage(page, config, componentTestPath, componentName);
});

test('renders default popover-canvas correctly', async ({ page }) => {
const triggerButton = page.getByRole('button');
await triggerButton.click();

/* Check diff on screenshot */
await expect(page).toHaveScreenshot({ maxDiffPixels: 0 });
});
});
});

/* Check diff on screenshot */
await expect(page).toHaveScreenshot({ maxDiffPixels: 0 });
test.describe.parallel(componentName, () => {
test.beforeEach(async ({ page }) => {
await page.goto(componentTestPath);
});

test('make sure popover canvas shows after trigger button is pressed and content is displayed', async ({
page,
}) => {
await page.goto(componentTestPath);
const triggerButton = page.getByRole('button');
const popoverCanvasHeader = page.getByRole('heading');
const popoverCanvasBody = page.getByText('Where you can put anything you want!', {
Expand All @@ -37,7 +54,6 @@ test.describe.parallel('tds-popover-canvas-default', () => {
});

test('activating close method should close the dialog', async ({ page }) => {
await page.goto(componentTestPath);
const triggerButton = page.getByRole('button');
await triggerButton.click();

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.
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -1,22 +1,39 @@
import { test } from 'stencil-playwright';
import { expect } from '@playwright/test';
import {
testConfigurations,
getTestDescribeText,
setupPage,
} from '../../../../utils/testConfiguration';

const componentTestPath = 'src/components/popover-canvas/test/show-false/index.html';
const componentName = 'tds-popover-canvas';
const testDescription = 'tds-popover-canvas-show-false';

test.describe.parallel('tds-popover-canvas-show-false', () => {
test('renders show=false popover-canvas correctly', async ({ page }) => {
await page.goto(componentTestPath);
const triggerButton = page.getByRole('button');
await triggerButton.click();
testConfigurations.basic.forEach((config) => {
test.describe.parallel(getTestDescribeText(config, testDescription), () => {
test.beforeEach(async ({ page }) => {
await setupPage(page, config, componentTestPath, componentName);
});

test('renders show=false popover-canvas correctly', async ({ page }) => {
const triggerButton = page.getByRole('button');
await triggerButton.click();

/* Check diff on screenshot */
await expect(page).toHaveScreenshot({ maxDiffPixels: 0 });
/* Check diff on screenshot */
await expect(page).toHaveScreenshot({ maxDiffPixels: 0 });
});
});
});

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

test('make sure popover canvas does not show after trigger button is pressed and content is not displayed before or after button click', async ({
page,
}) => {
await page.goto(componentTestPath);
const triggerButton = page.getByRole('button');
const popoverCanvasHeader = page.getByRole('heading');
const popoverCanvasBody = page.getByText('Where you can put anything you want!', {
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.
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -1,28 +1,45 @@
import { test } from 'stencil-playwright';
import { expect } from '@playwright/test';
import {
testConfigurations,
getTestDescribeText,
setupPage,
} from '../../../../utils/testConfiguration';

const componentTestPath = 'src/components/popover-canvas/test/show-true/index.html';
const componentName = 'tds-popover-canvas';
const testDescription = 'tds-popover-canvas-show-true';

test.describe.parallel('tds-popover-canvas-show-true', () => {
test('renders show=true popover-canvas correctly', async ({ page }) => {
await page.goto(componentTestPath);
const triggerButton = page.getByRole('button');
await triggerButton.click();
testConfigurations.basic.forEach((config) => {
test.describe.parallel(getTestDescribeText(config, testDescription), () => {
test.beforeEach(async ({ page }) => {
await setupPage(page, config, componentTestPath, componentName);
});

test('renders show=true popover-canvas correctly', async ({ page }) => {
const triggerButton = page.getByRole('button');
await triggerButton.click();

// get popover element
const popover = page.locator('tds-popover-core');
// get popover element
const popover = page.locator('tds-popover-core');

// wait for it to be visible
await popover.waitFor({ state: 'visible' });
// wait for it to be visible
await popover.waitFor({ state: 'visible' });

/* Check diff on screenshot */
await expect(page).toHaveScreenshot({ maxDiffPixelRatio: 0.05 });
/* Check diff on screenshot */
await expect(page).toHaveScreenshot({ maxDiffPixelRatio: 0.05 });
});
});
});

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

test('make sure the popover canvas content is displayed both before and after the trigger button is pressed', async ({
page,
}) => {
await page.goto(componentTestPath);
const triggerButton = page.getByRole('button');
const popoverCanvasHeader = page.getByRole('heading');
const popoverCanvasBody = page.getByText('Where you can put anything you want!', {
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.
Binary file not shown.

0 comments on commit 416d572

Please sign in to comment.