Skip to content

Commit

Permalink
test(Label): add smoke visual tests (#1810)
Browse files Browse the repository at this point in the history
Co-authored-by: Georgy Malkov <[email protected]>
  • Loading branch information
itwillwork and goshander authored Dec 26, 2024
1 parent e5a8e8a commit 1c39424
Show file tree
Hide file tree
Showing 18 changed files with 161 additions and 8 deletions.
5 changes: 5 additions & 0 deletions src/components/Label/Label.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ import {Icon} from '../Icon';
import type {QAProps} from '../types';
import {block} from '../utils/cn';

import {LabelQa} from './constants';

import './Label.scss';

const b = block('label');
Expand Down Expand Up @@ -122,6 +124,7 @@ export const Label = React.forwardRef(function Label(
side: 'end',
type: 'button',
})}
data-qa={LabelQa.copyButton}
>
<ClipboardIcon status={status || 'pending'} size={copyIconSize} />
</button>
Expand All @@ -137,6 +140,7 @@ export const Label = React.forwardRef(function Label(
side: 'end',
type: 'button',
})}
data-qa={LabelQa.closeButton}
>
<Icon size={closeIconSize} data={Xmark} />
</button>
Expand Down Expand Up @@ -165,6 +169,7 @@ export const Label = React.forwardRef(function Label(
type="button"
onClick={onClick}
className={b('main-button')}
data-qa={LabelQa.mainButton}
>
{content}
</button>
Expand Down
Binary file not shown.
Binary file not shown.
Binary file not shown.
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.
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.
126 changes: 123 additions & 3 deletions src/components/Label/__tests__/Label.visual.test.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,15 @@
import {test} from '~playwright/core';
import {smokeTest, test} from '~playwright/core';

import {LabelStories} from './helpersPlaywright';
import {createSmokeScenarios} from '../../../stories/tests-factory/create-smoke-scenarios';
import type {LabelProps} from '../Label';
import {Label} from '../Label';

test.describe('Label', () => {
import {disabledCases, sizeCases, themeCases} from './cases';
import {LabelStories, TestLabelWithIcon} from './helpersPlaywright';

const qa = 'label';

test.describe('Label', {tag: '@Label'}, () => {
test('render story: <Default>', async ({mount, expectScreenshot}) => {
await mount(<LabelStories.Default />);

Expand Down Expand Up @@ -62,4 +69,117 @@ test.describe('Label', () => {

await expectScreenshot();
});

const defaultProps: LabelProps = {
children: 'Label',
qa,
type: 'default',
};

smokeTest('', async ({mount, expectScreenshot}) => {
const smokeScenarios = createSmokeScenarios<LabelProps>(defaultProps, {
theme: themeCases,
size: sizeCases,
disabled: disabledCases,
});

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

await expectScreenshot({});
});

smokeTest('with custom icon', async ({mount, expectScreenshot}) => {
const smokeScenarios = createSmokeScenarios<LabelProps>(defaultProps, {
theme: themeCases,
size: sizeCases,
disabled: disabledCases,
});

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

await expectScreenshot({});
});

smokeTest('with copy', async ({mount, expectScreenshot}) => {
const smokeScenarios = createSmokeScenarios<LabelProps>(
{
...defaultProps,
type: 'copy',
copyText: 'Copy text',
onCopy: () => {},
},
{
theme: themeCases,
size: sizeCases,
disabled: disabledCases,
},
);

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

await expectScreenshot({});
});

smokeTest('with close', async ({mount, expectScreenshot}) => {
const smokeScenarios = createSmokeScenarios<LabelProps>(
{
...defaultProps,
type: 'close',
onCloseClick: () => {},
},
{
theme: themeCases,
size: sizeCases,
disabled: disabledCases,
},
);

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

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

export const disabledCases: Cases<LabelProps['disabled']> = [true];
export const themeCases: Cases<LabelProps['theme']> = [
'normal',
'info',
'danger',
'warning',
'success',
'utility',
'unknown',
'clear',
];
export const sizeCases: Cases<LabelProps['size']> = ['xs', 's', 'm'];
5 changes: 0 additions & 5 deletions src/components/Label/__tests__/helpersPlaywright.ts

This file was deleted.

13 changes: 13 additions & 0 deletions src/components/Label/__tests__/helpersPlaywright.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import {Rocket} from '@gravity-ui/icons';
import {composeStories} from '@storybook/react';

import {Icon} from '../../Icon';
import type {LabelProps} from '../Label';
import {Label} from '../Label';
import * as DefaultLabelStories from '../__stories__/Label.stories';

export const LabelStories = composeStories(DefaultLabelStories);

export const TestLabelWithIcon = (props: Partial<LabelProps>) => {
return <Label icon={<Icon data={Rocket} />} {...props} />;
};
5 changes: 5 additions & 0 deletions src/components/Label/constants.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export const LabelQa = {
copyButton: 'copy-button',
closeButton: 'close-button',
mainButton: 'main-button',
};

0 comments on commit 1c39424

Please sign in to comment.