Skip to content

Commit

Permalink
Merge branch 'main' into add-smoke-tests/Modal
Browse files Browse the repository at this point in the history
  • Loading branch information
itwillwork authored Dec 27, 2024
2 parents 4e1aeaf + 652d725 commit 0c662bb
Show file tree
Hide file tree
Showing 37 changed files with 340 additions and 5 deletions.
1 change: 1 addition & 0 deletions playwright/core/mountFixture.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ export const mountFixture: PlaywrightFixture<MountFixture> = async ({mount: base
boxSizing: options?.width ? 'content-box' : undefined,
width: options?.width ? options.width : 'fit-content',
height: 'fit-content',
...options?.rootStyle,
}}
className="playwright-wrapper-test"
>
Expand Down
5 changes: 4 additions & 1 deletion playwright/core/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,10 @@ import type {
interface ComponentFixtures {
mount<HooksConfig>(
component: React.JSX.Element,
options?: MountOptions<HooksConfig> & {width?: number | string},
options?: MountOptions<HooksConfig> & {
width?: number | string;
rootStyle?: React.CSSProperties;
},
): Promise<MountResult>;
}

Expand Down
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.
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.
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
import {expect} from '@playwright/experimental-ct-react';

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

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

import {placementCases} from './cases';

test.describe('ActionTooltip', {tag: '@ActionTooltip'}, () => {
const defaultProps: ActionTooltipProps = {
title: 'Title',
hotkey: 'mod+a',
description: 'Description',
children: <div>trigger</div>,
};

const smokeScenarios = createSmokeScenarios<ActionTooltipProps>(defaultProps, {
placement: placementCases,
});

smokeScenarios.forEach(([title, props]) => {
smokeTest(title, async ({mount, page, expectScreenshot}) => {
const root = await mount(
<div>
<h4>{title}</h4>
<div
style={{
width: '400px',
height: '400px',
display: 'flex',
justifyContent: 'center',
alignItems: 'center',
}}
>
<div>
<ActionTooltip {...props}>
<div
data-qa="trigger"
style={{
width: '200px',
height: '200px',
display: 'flex',
justifyContent: 'center',
alignItems: 'center',
border: '1px tomato dotted',
}}
>
trigger block
</div>
</ActionTooltip>
</div>
</div>
</div>,
);

await root.getByTestId('trigger').hover();
await expect(page.locator("[role='tooltip']")).toBeVisible({timeout: 1000});

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

export const placementCases: Cases<ActionTooltipProps['placement']> = [
'auto',
'auto-start',
'auto-end',
'top',
'bottom',
'right',
'left',
'top-start',
'top-end',
'bottom-start',
'bottom-end',
'right-start',
'right-end',
'left-start',
'left-end',
];
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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.
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.
38 changes: 34 additions & 4 deletions src/components/Sheet/__tests__/Sheet.visual.test.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
import {expect} from '@playwright/test';

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

import {createSmokeScenarios} from '../../../stories/tests-factory/create-smoke-scenarios';
import type {SheetProps} from '../Sheet';
import {DEFAULT_SHEET_QA} from '../__stories__/constants';

import {hideTopBarCases, titleCases} from './cases';
import {QASheet} from './constants';
import {TestSheet} from './helpers';
import {SheetStories} from './helpersPlaywright';

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

Expand All @@ -21,4 +24,31 @@ test.describe('Sheet', () => {
component: sheetLocator,
});
});

createSmokeScenarios<Partial<Omit<SheetProps, 'visible' | 'onClose'>>>(
{},
{
hideTopBar: hideTopBarCases,
title: titleCases,
},
).forEach(([title, props]) => {
smokeTest(title, async ({mount, page, expectScreenshot}) => {
await page.setViewportSize({width: 500, height: 500});

const root = await mount(<TestSheet {...props} />, {
rootStyle: {
padding: 0,
width: '100%',
minHeight: '500px',
},
});

await root.locator('button').click();
await expect(page.locator(`[data-qa='${QASheet.content}']`)).toBeVisible();

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

export const hideTopBarCases: Cases<SheetProps['hideTopBar']> = [true];
export const titleCases: Cases<SheetProps['title']> = ['Title'];
3 changes: 3 additions & 0 deletions src/components/Sheet/__tests__/constants.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export const QASheet = {
content: 'content',
};
34 changes: 34 additions & 0 deletions src/components/Sheet/__tests__/helpers.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import * as React from 'react';

import type {SheetProps} from '../Sheet';
import {Sheet} from '../Sheet';

import {QASheet} from './constants';

export const TestSheet = (props: Partial<Omit<SheetProps, 'visible' | 'onClose'>>) => {
const [visible, setVisible] = React.useState(false);

return (
<div>
<button onClick={() => setVisible(true)}>Show modal</button>
<Sheet
{...props}
visible={visible}
onClose={() => setVisible(false)}
qa={QASheet.content}
>
<div
style={{
minHeight: 100,
border: '1px solid tomato',
display: 'flex',
justifyContent: 'center',
alignItems: 'center',
}}
>
Sheet content
</div>
</Sheet>
</div>
);
};
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.
161 changes: 161 additions & 0 deletions src/components/Slider/__tests__/Slider.visual.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,161 @@
import type * as React from 'react';

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

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

import {
availableValuesCases,
disabledCases,
hasTooltipCases,
marksCountCases,
sizeCases,
stepCases,
validationStateCases,
} from './cases';

test.describe('Slider', {tag: '@Slider'}, () => {
const defaultWrapStyle: React.CSSProperties = {
width: 300,
height: 50,
paddingBottom: 20,
};

const defaultProps: SliderProps = {
value: 40,
min: 0,
max: 100,
onUpdate: () => {},
};

smokeTest('', async ({mount, expectScreenshot}) => {
const smokeScenarios = createSmokeScenarios(defaultProps, {
size: sizeCases,
disabled: disabledCases,
validationState: validationStateCases,
hasTooltip: hasTooltipCases,
marksCount: marksCountCases,
step: stepCases,
availableValues: availableValuesCases,
});

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

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

smokeTest('with error', async ({mount, expectScreenshot}) => {
const smokeScenarios = createSmokeScenarios<SliderProps>(
{
...defaultProps,
validationState: 'invalid',
errorMessage: 'Error message',
},
{
hasTooltip: hasTooltipCases,
marksCount: marksCountCases,
step: stepCases,
},
);

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

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

const defaultRangeProps: SliderProps = {
value: [20, 40],
min: 0,
max: 100,
onUpdate: () => {},
};

smokeTest('range value', async ({mount, expectScreenshot}) => {
const smokeScenarios = createSmokeScenarios<SliderProps>(defaultRangeProps, {
size: sizeCases,
disabled: disabledCases,
validationState: validationStateCases,
hasTooltip: hasTooltipCases,
marksCount: marksCountCases,
step: stepCases,
availableValues: availableValuesCases,
});

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

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

smokeTest('range value with error', async ({mount, expectScreenshot}) => {
const smokeScenarios = createSmokeScenarios<SliderProps>(
{
...defaultRangeProps,
validationState: 'invalid',
errorMessage: 'Error message',
},
{
hasTooltip: hasTooltipCases,
marksCount: marksCountCases,
step: stepCases,
},
);

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

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

export const sizeCases: Cases<SliderProps['size']> = ['s', 'm', 'l', 'xl'];
export const disabledCases: Cases<SliderProps['disabled']> = [true];
export const validationStateCases: Cases<SliderProps['validationState']> = ['invalid'];
export const hasTooltipCases: Cases<SliderProps['hasTooltip']> = [true];
export const marksCountCases: Cases<SliderProps['marksCount']> = [4];
export const stepCases: Cases<SliderProps['step']> = [5];
export const availableValuesCases: CasesWithName<SliderProps['availableValues']> = [
['10-20-50-55-65-80', [10, 20, 50, 55, 65, 80]],
];

0 comments on commit 0c662bb

Please sign in to comment.