Skip to content

test(Toaster): add smoke visual tests #1789

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.
70 changes: 69 additions & 1 deletion src/components/Toaster/__tests__/Toast.visual.test.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
import type * as React from 'react';

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

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

import {actionsCases, isClosableCases, themeCases, titleCases} from './cases';
import {TestToast, TestToastWithIcon} from './helpers';
import {ToastStories} from './helpersPlaywright';

const wrapperOptions = {
Expand Down Expand Up @@ -84,4 +88,68 @@ test.describe('Toast', {tag: '@Toaster'}, () => {

await expectScreenshot();
});

smokeTest('', async ({mount, expectScreenshot}) => {
const smokeScenarios = createSmokeScenarios<ToastProps>(
{
name: 'toast',
content: <div>toast content</div>,
},
{
title: titleCases,
theme: themeCases,
actions: actionsCases,
isClosable: isClosableCases,
},
);

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

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

smokeTest('with custom icon', async ({mount, expectScreenshot}) => {
const smokeScenarios = createSmokeScenarios<ToastProps>(
{
name: 'toast',
content: <div>toast content</div>,
},
{
title: titleCases,
theme: themeCases,
actions: actionsCases,
isClosable: isClosableCases,
},
);

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

await expectScreenshot({
themes: ['light'],
});
});
});
29 changes: 29 additions & 0 deletions src/components/Toaster/__tests__/Toaster.visual.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import {smokeTest, test} from '~playwright/core';

import type {ToastProps} from '../types';

import {ToasterQA} from './constants';
import {TestToaster} from './helpers';

test.describe('Toaster', {tag: '@Toaster'}, () => {
smokeTest('', async ({mount, page, expectScreenshot}) => {
await page.setViewportSize({width: 500, height: 500});

const toastProps: ToastProps = {
name: 'toast',
content: <div>toast content</div>,
};

const root = await mount(<TestToaster toastProps={toastProps} />);

await root.locator(`button[data-qa="${ToasterQA.trigger}"]`).click();

// wait show toast & end animations
await page.waitForTimeout(2000);

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

export const titleCases: Cases<ToastProps['title']> = ['Title'];
export const themeCases: Cases<ToastProps['theme']> = [
'normal',
'info',
'success',
'warning',
'danger',
'utility',
];
export const isClosableCases: Cases<ToastProps['isClosable']> = [true];
export const actionsCases: CasesWithName<ToastProps['actions']> = [
[
'one action',
[
{
onClick: () => {},
label: 'one action',
},
],
],
[
'two actions',
[
{
onClick: () => {},
label: 'one action',
},
{
onClick: () => {},
label: 'two action',
},
],
],
];
3 changes: 3 additions & 0 deletions src/components/Toaster/__tests__/constants.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export const ToasterQA = {
trigger: 'trigger',
};
56 changes: 56 additions & 0 deletions src/components/Toaster/__tests__/helpers.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
import {TrashBin} from '@gravity-ui/icons';

import {Icon} from '../../Icon';
import {ToasterProvider} from '../Provider/ToasterProvider';
import {Toast} from '../Toast/Toast';
import {ToasterComponent} from '../ToasterComponent/ToasterComponent';
import {useToaster} from '../hooks/useToaster';
import type {ToastProps} from '../types';

import {ToasterQA} from './constants';

const TestToasterTrigger = (props: {toastProps: ToastProps}) => {
const toaster = useToaster();

const handleClick = () => {
toaster.add(props.toastProps);
};

return (
<button data-qa={ToasterQA.trigger} onClick={handleClick}>
trigger
</button>
);
};

export const TestToaster = (props: {toastProps: ToastProps}) => {
return (
<ToasterProvider>
<TestToasterTrigger toastProps={props.toastProps} />
<ToasterComponent hasPortal={false} />
</ToasterProvider>
);
};

export const TestToast = (props: ToastProps) => {
return (
<Toast
{...props}
removeCallback={() => {
// noop
}}
/>
);
};

export const TestToastWithIcon = (props: ToastProps) => {
return (
<Toast
{...props}
removeCallback={() => {
// noop
}}
renderIcon={() => <Icon data={TrashBin} />}
/>
);
};
Loading