Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test(TextInput): add smoke visual tests #1778

Merged
merged 5 commits into from
Dec 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
@@ -0,0 +1,152 @@
import {expect} from '@playwright/experimental-ct-react';

import {smokeTest, test} from '~playwright/core';

import {createSmokeScenarios} from '../../../../stories/tests-factory/create-smoke-scenarios';
import {CONTROL_ERROR_ICON_QA} from '../../utils';
import type {TextInputProps} from '../TextInput';
import {TextInput} from '../TextInput';

import {
disabledCases,
endContentCases,
errorPlacementCases,
hasClearCases,
labelCases,
noteCases,
pinCases,
sizeCases,
startContentCases,
validationStateCases,
viewCases,
} from './cases';

test.describe('TextInput', {tag: '@TextInput'}, () => {
const defaultProps: TextInputProps = {
placeholder: 'Placeholder',
};

const commonPropCases = {
pin: pinCases,
size: sizeCases,
view: viewCases,
note: noteCases,
validationState: validationStateCases,
startContent: startContentCases,
endContent: endContentCases,
disabled: disabledCases,
hasClear: hasClearCases,
label: labelCases,
} as const;

smokeTest('empty', async ({mount, expectScreenshot}) => {
const smokeScenarios = createSmokeScenarios<TextInputProps>(
{
...defaultProps,
},
commonPropCases,
);

await mount(
<div>
{smokeScenarios.map(([title, props]) => (
<div key={title}>
<h4>{title}</h4>
<div>
<TextInput {...props} />
</div>
</div>
))}
</div>,
);

await expectScreenshot({
themes: ['light'],
});
});

smokeTest('with value', async ({mount, expectScreenshot}) => {
const smokeScenarios = createSmokeScenarios<TextInputProps>(
{
...defaultProps,
value: 'Text',
},
commonPropCases,
);

await mount(
<div>
{smokeScenarios.map(([title, props]) => (
<div key={title}>
<h4>{title}</h4>
<div>
<TextInput {...props} />
</div>
</div>
))}
</div>,
);

await expectScreenshot({
themes: ['light'],
});
});

smokeTest('with error', async ({mount, expectScreenshot}) => {
const smokeScenarios = createSmokeScenarios(
{
...defaultProps,
value: 'Text',
validationState: 'invalid',
errorMessage: 'Test error message',
} as const,
{
errorPlacement: errorPlacementCases,
},
);

await mount(
<div>
{smokeScenarios.map(([title, props]) => (
<div key={title}>
<h4>{title}</h4>
<div>
<TextInput {...props} />
</div>
</div>
))}
</div>,
);

await expectScreenshot({
themes: ['light'],
});
});

smokeTest('inside error placement tooltip', async ({mount, page, expectScreenshot}) => {
const props: TextInputProps = {
...defaultProps,
value: 'Text',
validationState: 'invalid',
errorMessage: 'Test error message',
errorPlacement: 'inside',
};

const root = await mount(
<div style={{width: 250}}>
<TextInput {...props} />
</div>,
{
width: 500,
},
);

await root.getByTestId(CONTROL_ERROR_ICON_QA).hover();

await expect(page.locator('.g-popup')).toBeVisible();

await expectScreenshot({
themes: ['light'],
});
});
});
40 changes: 40 additions & 0 deletions src/components/controls/TextInput/__tests__/cases.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import type {Cases, CasesWithName} from '../../../../stories/tests-factory/models';
import type {TextInputProps} from '../TextInput';

/* eslint-disable react/jsx-key */

export const disabledCases: Array<TextInputProps['disabled']> = [true];

export const hasClearCases: Array<TextInputProps['hasClear']> = [true];

export const pinCases: Cases<TextInputProps['pin']> = [
'round-round',
'brick-brick',
'clear-clear',
'round-brick',
'brick-round',
'round-clear',
'clear-round',
'brick-clear',
'clear-brick',
];

export const validationStateCases: Cases<TextInputProps['validationState']> = ['invalid'];

export const sizeCases: Cases<TextInputProps['size']> = ['s', 'm', 'l', 'xl'];

export const viewCases: Cases<TextInputProps['view']> = ['normal', 'clear'];

export const errorPlacementCases: Cases<TextInputProps['errorPlacement']> = ['outside', 'inside'];

export const startContentCases: CasesWithName<TextInputProps['startContent']> = [
['', <div>start</div>],
];

export const endContentCases: CasesWithName<TextInputProps['endContent']> = [['', <div>end</div>]];

export const noteCases: CasesWithName<TextInputProps['note']> = [['', <div>note</div>]];

export const labelCases: CasesWithName<TextInputProps['label']> = [['', 'label']];

/* eslint-enable react/jsx-key */
Loading