Skip to content

Commit

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

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

import {
childrenCases,
onClickCases,
onCloseClickCases,
sizeCases,
typeCases,
viewCases,
} from './cases';
import {TestUserLabel, TestUserLabelWithEmail, TestUserLabelWithPerson} from './helpers';

test.describe('UserLabel', {tag: '@UserLabel'}, () => {
smokeTest('user', async ({mount, expectScreenshot}) => {
const smokeScenarios = createSmokeScenarios<Partial<UserLabelProps>>(
{},
{
size: sizeCases,
view: viewCases,
type: typeCases,
children: childrenCases,
onClick: onClickCases,
onCloseClick: onCloseClickCases,
},
);

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

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

smokeTest('person', async ({mount, expectScreenshot}) => {
const smokeScenarios = createSmokeScenarios<Partial<UserLabelProps>>(
{},
{
size: sizeCases,
view: viewCases,
children: childrenCases,
onClick: onClickCases,
onCloseClick: onCloseClickCases,
},
);

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

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

smokeTest('email', async ({mount, expectScreenshot}) => {
const smokeScenarios = createSmokeScenarios<Partial<UserLabelProps>>(
{},
{
size: sizeCases,
view: viewCases,
children: childrenCases,
onClick: onClickCases,
onCloseClick: onCloseClickCases,
},
);

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

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

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

export const viewCases: Cases<UserLabelProps['view']> = ['outlined', 'clear'];

export const typeCases: Cases<UserLabelProps['type']> = ['person', 'email', 'empty'];

export const childrenCases: CasesWithName<UserLabelProps['children']> = [
[
'long label',
'Charles DarwinCharles DarwinCharles DarwinCharles DarwinCharles DarwinCharles DarwinCharles DarwinCharles DarwinCharles DarwinCharles DarwinCharles DarwinCharles DarwinCharles DarwinCharles DarwinCharles DarwinCharles DarwinCharles DarwinCharles DarwinCharles DarwinCharles DarwinCharles DarwinCharles DarwinCharles DarwinCharles DarwinCharles DarwinCharles DarwinCharles DarwinCharles DarwinCharles DarwinCharles DarwinCharles DarwinCharles DarwinCharles DarwinCharles DarwinCharles DarwinCharles DarwinCharles DarwinCharles DarwinCharles DarwinCharles DarwinCharles DarwinCharles DarwinCharles DarwinCharles DarwinCharles DarwinCharles DarwinCharles DarwinCharles DarwinCharles DarwinCharles DarwinCharles DarwinCharles DarwinCharles DarwinCharles DarwinCharles DarwinCharles DarwinCharles DarwinCharles DarwinCharles DarwinCharles DarwinCharles DarwinCharles DarwinCharles DarwinCharles DarwinCharles DarwinCharles DarwinCharles DarwinCharles DarwinCharles DarwinCharles DarwinCharles DarwinCharles DarwinCharles DarwinCharles DarwinCharles DarwinCharles DarwinCharles DarwinCharles DarwinCharles DarwinCharles DarwinCharles DarwinCharles DarwinCharles DarwinCharles DarwinCharles DarwinCharles DarwinCharles DarwinCharles DarwinCharles DarwinCharles DarwinCharles DarwinCharles DarwinCharles DarwinCharles DarwinCharles DarwinCharles DarwinCharles DarwinCharles DarwinCharles DarwinCharles Darwin',
],
];

export const onCloseClickCases: CasesWithName<UserLabelProps['onCloseClick']> = [
['closable', () => {}],
];

export const onClickCases: CasesWithName<UserLabelProps['onClick']> = [['clickable', () => {}]];
45 changes: 45 additions & 0 deletions src/components/UserLabel/__tests__/helpers.tsx

Large diffs are not rendered by default.

0 comments on commit cc6b6dd

Please sign in to comment.