Skip to content

Commit

Permalink
test(PinInput): add smoke visual tests (#1814)
Browse files Browse the repository at this point in the history
  • Loading branch information
itwillwork authored Dec 28, 2024
1 parent 1d63b35 commit f8dfee1
Show file tree
Hide file tree
Showing 5 changed files with 123 additions and 0 deletions.
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.
112 changes: 112 additions & 0 deletions src/components/PinInput/__tests__/PinInput.visual.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
import {smokeTest, test} from '~playwright/core';

import {createSmokeScenarios} from '../../../stories/tests-factory/create-smoke-scenarios';
import type {PinInputProps} from '../PinInput';
import {PinInput} from '../PinInput';

import {
disabledCases,
lengthCases,
maskCases,
noteCases,
placeholderCases,
responsiveCases,
sizeCases,
validationStateCases,
} from './cases';

test.describe('PinInput', {tag: '@PinInput'}, () => {
const commonPropsCases = {
placeholder: placeholderCases,
length: lengthCases,
disabled: disabledCases,
responsive: responsiveCases,
note: noteCases,
mask: maskCases,
size: sizeCases,
validationState: validationStateCases,
} as const;

smokeTest('empty', async ({mount, expectScreenshot}) => {
const smokeScenarios = createSmokeScenarios<PinInputProps>(
{
type: 'numeric',
errorMessage: 'Test error message',
},
commonPropsCases,
);

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

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

smokeTest('number', async ({mount, expectScreenshot}) => {
const smokeScenarios = createSmokeScenarios<PinInputProps>(
{
type: 'numeric',
errorMessage: 'Test error message',
value: ['1', '2', '3', '4'],
},
commonPropsCases,
);

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

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

smokeTest('alphabetic', async ({mount, expectScreenshot}) => {
const smokeScenarios = createSmokeScenarios<PinInputProps>(
{
type: 'alphanumeric',
errorMessage: 'Test error message',
value: ['a', 'b', 'c', 'd'],
},
commonPropsCases,
);

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

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

export const sizeCases: Cases<PinInputProps['size']> = ['s', 'm', 'l', 'xl'];
export const maskCases: Cases<PinInputProps['mask']> = [true];
export const placeholderCases: Cases<PinInputProps['placeholder']> = ['*'];
export const validationStateCases: Cases<PinInputProps['validationState']> = ['invalid'];
export const lengthCases: Cases<PinInputProps['length']> = [4, 6];
export const disabledCases: Cases<PinInputProps['disabled']> = [true];
export const responsiveCases: Cases<PinInputProps['responsive']> = [true];
export const noteCases: Cases<PinInputProps['note']> = ['note'];

0 comments on commit f8dfee1

Please sign in to comment.