Skip to content

Commit

Permalink
Merge branch 'main' into add-smoke-tests/Table
Browse files Browse the repository at this point in the history
  • Loading branch information
itwillwork authored Dec 27, 2024
2 parents 3c78c2a + 00cd78e commit cd485e0
Show file tree
Hide file tree
Showing 22 changed files with 201 additions and 8 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.
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import {smokeTest, test} from '~playwright/core';

import type {ClipboardButtonProps} from '../ClipboardButton';
import {ClipboardButton} from '../ClipboardButton';

test.describe('ClipboardButton', {tag: '@ClipboardButton'}, () => {
const defaultProps: ClipboardButtonProps = {
text: 'Text',
onCopy: () => {},
};

smokeTest('', async ({mount, page, expectScreenshot}) => {
const root = await mount(
<div style={{padding: '100px'}}>
<ClipboardButton {...defaultProps} hasTooltip />
</div>,
);

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

await root.locator("button[type='button']").hover();

// wait for render tooltip
await page.waitForTimeout(1000);

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

await root.locator("button[type='button']").click();

await expectScreenshot({
themes: ['light'],
nameSuffix: 'after copy',
});
});
});
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 cd485e0

Please sign in to comment.