Skip to content

Commit

Permalink
test(text-field): add screenshot tests using reusable test code (#956)
Browse files Browse the repository at this point in the history
  • Loading branch information
max-umain committed Jan 20, 2025
1 parent e3b69e6 commit e1152b3
Show file tree
Hide file tree
Showing 32 changed files with 169 additions and 63 deletions.
Original file line number Diff line number Diff line change
@@ -1,22 +1,37 @@
import { test } from 'stencil-playwright';
import { expect } from '@playwright/test';
import {
testConfigurations,
getTestDescribeText,
setupPage,
} from '../../../../utils/testConfiguration';

// Defined once for reuse
const componentTestPath = 'src/components/text-field/test/default/index.html';
const componentName = 'tds-text-field';
const testDescription = 'TdsTextField - default state';

const textFieldSelector = 'tds-text-field';

test.describe.parallel('TdsTextField - default state', () => {
test.beforeEach(async ({ page }) => {
// Navigate to the component test page before each test
await page.goto(componentTestPath);
});
testConfigurations.withModeVariants.forEach((config) => {
test.describe.parallel(getTestDescribeText(config, testDescription), () => {
test.beforeEach(async ({ page }) => {
await setupPage(page, config, componentTestPath, componentName);
});

test('renders default text-field correctly', async ({ page }) => {
const textField = page.locator(textFieldSelector);
await expect(textField).toHaveCount(1);
test('renders default text-field correctly', async ({ page }) => {
const textField = page.locator(textFieldSelector);
await expect(textField).toHaveCount(1);

/* 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('should have type "text"', async ({ page }) => {
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.
Original file line number Diff line number Diff line change
@@ -1,22 +1,37 @@
import { test } from 'stencil-playwright';
import { expect } from '@playwright/test';
import {
testConfigurations,
getTestDescribeText,
setupPage,
} from '../../../../utils/testConfiguration';

// Defined once for reuse
const componentTestPath = 'src/components/text-field/test/disabled/index.html';
const componentName = 'tds-text-field';
const testDescription = 'TdsTextField - default state';

const textFieldSelector = 'tds-text-field';

test.describe.parallel('TdsTextField - default state', () => {
test.beforeEach(async ({ page }) => {
// Navigate to the component test page before each test
await page.goto(componentTestPath);
});
testConfigurations.withModeVariants.forEach((config) => {
test.describe.parallel(getTestDescribeText(config, testDescription), () => {
test.beforeEach(async ({ page }) => {
await setupPage(page, config, componentTestPath, componentName);
});

test('renders disabled text-field correctly', async ({ page }) => {
const textField = page.locator(textFieldSelector);
await expect(textField).toHaveCount(1);
test('renders disabled text-field correctly', async ({ page }) => {
const textField = page.locator(textFieldSelector);
await expect(textField).toHaveCount(1);

/* 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('should have disabled attribute', async ({ page }) => {
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.
Original file line number Diff line number Diff line change
@@ -1,22 +1,58 @@
import { test } from 'stencil-playwright';
import { expect } from '@playwright/test';
import {
testConfigurations,
getTestDescribeText,
setupPage,
} from '../../../../utils/testConfiguration';

// Defined once for reuse
const componentTestPath = 'src/components/text-field/test/password-error/index.html';
const componentName = 'tds-text-field';
const testDescription = 'TdsTextField - password type with error state';

const textFieldSelector = 'tds-text-field';

test.describe.parallel('TdsTextField - password type with error state', () => {
test.beforeEach(async ({ page }) => {
// Navigate to the component test page before each test
await page.goto(componentTestPath);
});
testConfigurations.withModeVariants.forEach((config) => {
test.describe.parallel(getTestDescribeText(config, testDescription), () => {
test.beforeEach(async ({ page }) => {
await setupPage(page, config, componentTestPath, componentName);
});

test('renders default text-field correctly', async ({ page }) => {
const textField = page.locator(textFieldSelector);
await expect(textField).toHaveCount(1);
test('renders default text-field correctly', async ({ page }) => {
const textField = page.locator(textFieldSelector);
await expect(textField).toHaveCount(1);

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

/* Check diff on screenshot */
await expect(page).toHaveScreenshot({ maxDiffPixels: 0 });
test('should handle hover, click, and input on text field', async ({ page }) => {
// Define the selector for the text field input
const textFieldInputSelector = 'tds-text-field input';

// Hover over the text field
await page.hover(textFieldInputSelector);

// Click on the text field to activate it
await page.click(textFieldInputSelector);

// Type 'Test text' into the text field
await page.fill(textFieldInputSelector, 'Test');

// Verify the text field contains the inputted text
const value = await page.inputValue(textFieldInputSelector);
expect(value).toBe('Test');

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

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

test('should have state "error"', async ({ page }) => {
Expand Down Expand Up @@ -48,25 +84,4 @@ test.describe.parallel('TdsTextField - password type with error state', () => {
const textFieldLabelSelector = page.locator('div >> text="Label"');
await expect(textFieldLabelSelector).toHaveCount(1);
});

test('should handle hover, click, and input on text field', async ({ page }) => {
// Define the selector for the text field input
const textFieldInputSelector = 'tds-text-field input';

// Hover over the text field
await page.hover(textFieldInputSelector);

// Click on the text field to activate it
await page.click(textFieldInputSelector);

// Type 'Test text' into the text field
await page.fill(textFieldInputSelector, 'Test');

// Verify the text field contains the inputted text
const value = await page.inputValue(textFieldInputSelector);
expect(value).toBe('Test');

/* Check diff on screenshot */
await expect(page).toHaveScreenshot({ maxDiffPixels: 0 });
});
});
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.
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,22 +1,37 @@
import { test } from 'stencil-playwright';
import { expect } from '@playwright/test';
import {
testConfigurations,
getTestDescribeText,
setupPage,
} from '../../../../utils/testConfiguration';

// Defined once for reuse
const componentTestPath = 'src/components/text-field/test/read-only-success/index.html';
const componentName = 'tds-text-field';
const testDescription = 'TdsTextField - read-only success state';

const textFieldSelector = 'tds-text-field';

test.describe.parallel('TdsTextField - read-only success state', () => {
test.beforeEach(async ({ page }) => {
// Navigate to the component test page before each test
await page.goto(componentTestPath);
});
testConfigurations.withModeVariants.forEach((config) => {
test.describe.parallel(getTestDescribeText(config, testDescription), () => {
test.beforeEach(async ({ page }) => {
await setupPage(page, config, componentTestPath, componentName);
});

test('renders readonly success state of text-field correctly', async ({ page }) => {
const textField = page.locator(textFieldSelector);
await expect(textField).toHaveCount(1);
test('renders readonly success state of text-field correctly', async ({ page }) => {
const textField = page.locator(textFieldSelector);
await expect(textField).toHaveCount(1);

/* 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('should have state "success"', async ({ page }) => {
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.
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
Expand Up @@ -2,10 +2,14 @@ import { test } from 'stencil-playwright';
import { expect } from '@playwright/test';

const componentTestPath = 'src/components/text-field/test/read-only-with-suffix/index.html';
const testDescription = 'TdsTextField - readOnly prop effect';

test.describe('TdsTextField - readOnly prop effect', () => {
test('should hide the suffix icon when readOnly is true', async ({ page }) => {
test.describe.parallel(testDescription, () => {
test.beforeEach(async ({ page }) => {
await page.goto(componentTestPath);
});

test('should hide the suffix icon when readOnly is true', async ({ page }) => {
const suffixIcon = await page.locator('.text-field-slot-wrap-suffix');
await expect(suffixIcon).toBeHidden();
});
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<!DOCTYPE html>
<html lang="en" dir="ltr">
<head>
<meta charset="UTF-8" />
<title>Text Field - With helper text</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0" />
<link rel="stylesheet" href="../../../../../dist/tegel/tegel.css" />
<script type="module">
import { defineCustomElements } from '../../../../../loader/index.es2017.js';
defineCustomElements();
</script>
</head>

<body>
<tds-text-field placeholder="Placeholder" helper="Helper text"></tds-text-field>
</body>
</html>
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { test } from 'stencil-playwright';
import { expect } from '@playwright/test';
import {
testConfigurations,
getTestDescribeText,
setupPage,
} from '../../../../utils/testConfiguration';

// Defined once for reuse
const componentTestPath = 'src/components/text-field/test/with-helper-text/index.html';
const componentName = 'tds-text-field';
const testDescription = 'TdsTextField - with helper text';

testConfigurations.withModeVariants.forEach((config) => {
test.describe.parallel(getTestDescribeText(config, testDescription), () => {
test.beforeEach(async ({ page }) => {
await setupPage(page, config, componentTestPath, componentName);
});

test('renders text-field with helper text', async ({ page }) => {
/* Check diff on screenshot */
await expect(page).toHaveScreenshot({ maxDiffPixels: 0 });
});
});
});
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 e1152b3

Please sign in to comment.