Skip to content

Commit

Permalink
test(Toaster): basic cases (#1893)
Browse files Browse the repository at this point in the history
  • Loading branch information
ogonkov authored Oct 10, 2024
1 parent 235ea21 commit a7e04b7
Show file tree
Hide file tree
Showing 33 changed files with 126 additions and 16 deletions.
13 changes: 7 additions & 6 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@
"@babel/preset-typescript": "^7.23.3",
"@commitlint/cli": "^18.6.0",
"@commitlint/config-conventional": "^18.6.0",
"@faker-js/faker": "^8.4.0",
"@faker-js/faker": "^9.0.3",
"@gravity-ui/eslint-config": "^3.1.1",
"@gravity-ui/prettier-config": "^1.1.0",
"@gravity-ui/stylelint-config": "^4.0.1",
Expand Down
8 changes: 7 additions & 1 deletion playwright/core/mountFixture.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,13 @@ export const mountFixture: PlaywrightFixture<MountFixture> = async ({mount: base
const mount: MountFixture = async (component, options) => {
return await baseMount(
<div
style={{padding: 20, width: 'fit-content', height: 'fit-content'}}
style={{
padding: 20,
// When we set width we didn't expect that paddings for better screenshots would be included
boxSizing: options?.width ? 'content-box' : undefined,
width: options?.width ? options.width : 'fit-content',
height: 'fit-content',
}}
className="playwright-wrapper-test"
>
{component}
Expand Down
6 changes: 4 additions & 2 deletions playwright/core/types.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import type React from 'react';

import type {MountOptions, MountResult} from '@playwright/experimental-ct-react';
import type {
Locator,
Expand All @@ -11,8 +13,8 @@ import type {

interface ComponentFixtures {
mount<HooksConfig>(
component: JSX.Element,
options?: MountOptions<HooksConfig>,
component: React.JSX.Element,
options?: MountOptions<HooksConfig> & {width?: number},
): Promise<MountResult>;
}

Expand Down
3 changes: 1 addition & 2 deletions playwright/playwright/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import React from 'react';

import {beforeMount} from '@playwright/experimental-ct-react/hooks';

import {ToasterComponent, ToasterProvider} from '../../src/components/Toaster';
import {ToasterProvider} from '../../src/components/Toaster';
import {MobileProvider} from '../../src/components/mobile/MobileProvider';
import {ThemeProvider} from '../../src/components/theme/ThemeProvider';

Expand All @@ -14,7 +14,6 @@ beforeMount(async ({App}) => {
<MobileProvider>
<ToasterProvider>
<App />
<ToasterComponent />
</ToasterProvider>
</MobileProvider>
</ThemeProvider>
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.
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.
9 changes: 7 additions & 2 deletions src/components/Toaster/__stories__/Toaster.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ export const ToastPlayground: Story = {
renderIcon: disabledControl,
removeCallback: disabledControl,
},
render: (args) => {
render: (args, context) => {
// eslint-disable-next-line react-hooks/rules-of-hooks
const toaster = useToaster();

Expand All @@ -143,6 +143,11 @@ export const ToastPlayground: Story = {
return () => toaster.remove(toastId);
}, [args, toaster]);

return <ToasterComponent mobile={args.mobile} />;
return (
<ToasterComponent
mobile={args.mobile}
hasPortal={context.globals.screenshotTests !== true}
/>
);
},
};
87 changes: 87 additions & 0 deletions src/components/Toaster/__tests__/Toast.visual.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
import React from 'react';

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

import type {Toast} from '../Toast/Toast';

import {ToastStories} from './helpersPlaywright';

const wrapperOptions = {
width: 312,
};

function getToastActions(contrastButton = true): React.ComponentProps<typeof Toast>['actions'] {
return [
{onClick() {}, label: 'Action', view: contrastButton ? 'normal-contrast' : 'normal'},
{onClick() {}, label: 'Something More', view: 'outlined'},
];
}

const simpleToastProps: React.ComponentProps<typeof Toast> = {
actions: getToastActions(),
removeCallback: () => {},
name: 'simple-toast',
isClosable: true,
title: 'Do some actions',
content: 'We address you some concerns regarding your last actions in UI',
};

test.describe('Toast', {tag: '@Toaster'}, () => {
test('render story: <ToastPlayground> (normal)', async ({mount, expectScreenshot}) => {
await mount(
<ToastStories.ToastPlayground
{...simpleToastProps}
actions={getToastActions(false)}
theme="normal"
/>,
wrapperOptions,
);

await expectScreenshot();
});

test('render story: <ToastPlayground> (info)', async ({mount, expectScreenshot}) => {
await mount(
<ToastStories.ToastPlayground {...simpleToastProps} theme="info" />,
wrapperOptions,
);

await expectScreenshot();
});

test('render story: <ToastPlayground> (success)', async ({mount, expectScreenshot}) => {
await mount(
<ToastStories.ToastPlayground {...simpleToastProps} theme="success" />,
wrapperOptions,
);

await expectScreenshot();
});

test('render story: <ToastPlayground> (warning)', async ({mount, expectScreenshot}) => {
await mount(
<ToastStories.ToastPlayground {...simpleToastProps} theme="warning" />,
wrapperOptions,
);

await expectScreenshot();
});

test('render story: <ToastPlayground> (danger)', async ({mount, expectScreenshot}) => {
await mount(
<ToastStories.ToastPlayground {...simpleToastProps} theme="danger" />,
wrapperOptions,
);

await expectScreenshot();
});

test('render story: <ToastPlayground> (utility)', async ({mount, expectScreenshot}) => {
await mount(
<ToastStories.ToastPlayground {...simpleToastProps} theme="utility" />,
wrapperOptions,
);

await expectScreenshot();
});
});
9 changes: 9 additions & 0 deletions src/components/Toaster/__tests__/helpersPlaywright.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import {composeStories} from '@storybook/react';

import * as ToastStoriesImport from '../__stories__/Toaster.stories';

export const ToastStories = composeStories(ToastStoriesImport, {
globals: {
screenshotTests: true,
},
});
5 changes: 3 additions & 2 deletions src/components/UserLabel/__stories__/UserLabel.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,9 @@ export default meta;
type Story = StoryObj<typeof UserLabel>;

const person = 'Charles Darwin';
const email = faker.internet.email(...person.split(' '));
const personImg = faker.internet.avatar();
const [firstName, lastName] = person.split(' ');
const email = faker.internet.email({firstName, lastName});
const personImg = faker.image.avatar();

export const Default: Story = {
args: {
Expand Down

0 comments on commit a7e04b7

Please sign in to comment.