Skip to content
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

test(Avatar): add smoke visual tests #1771

Merged
merged 5 commits into from
Dec 26, 2024
Merged
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.
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.
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.
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.
121 changes: 118 additions & 3 deletions src/components/Avatar/__tests__/Avatar.visual.test.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,23 @@
import {expect} from '@playwright/experimental-ct-react';

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

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

import {createSmokeScenarios} from '../../../stories/tests-factory/create-smoke-scenarios';
import {Avatar} from '../Avatar';
import type {AvatarProps} from '../types/main';

import {
backgroundColorCases,
borderColorCases,
sizeCases,
themeCases,
titleCases,
viewCases,
} from './cases';
import {TestAvatarWithIcon, TestAvatarWithImage} from './helpersPlaywright';
import {AvatarStories} from './stories';

test.describe('Avatar', () => {
test.describe('Avatar', {tag: '@Avatar'}, () => {
test('render story: <Image>', async ({mount}) => {
const component = await mount(<AvatarStories.Image />);

Expand Down Expand Up @@ -48,4 +61,106 @@ test.describe('Avatar', () => {

await expect(component).toHaveScreenshot();
});

const defaultProps: AvatarProps = {};

const commonCases = {
size: sizeCases,
theme: themeCases,
view: viewCases,
backgroundColor: backgroundColorCases,
borderColor: borderColorCases,
title: titleCases,
} as const;

smokeTest('with image', async ({mount, expectScreenshot}) => {
const smokeScenarios = createSmokeScenarios(
defaultProps,
{
...commonCases,
},
{
scenarioName: 'image specific',
},
);

await mount(
<div style={{width: 400}}>
{smokeScenarios.map(([title, props]) => (
<div key={title}>
<h4>{title}</h4>
<div>
<TestAvatarWithImage {...props} />
</div>
</div>
))}
</div>,
);

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

smokeTest('with icon', async ({mount, expectScreenshot}) => {
const smokeScenarios = createSmokeScenarios(
defaultProps,
{
...commonCases,
},
{
scenarioName: 'icon specific',
},
);

await mount(
<div style={{width: 400}}>
{smokeScenarios.map(([title, props]) => (
<div key={title}>
<h4>{title}</h4>
<div>
<TestAvatarWithIcon {...props} />
</div>
</div>
))}
</div>,
);

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

smokeTest('with text', async ({mount, expectScreenshot}) => {
const smokeScenarios = createSmokeScenarios(
{
...defaultProps,
text: 'Text',
color: 'black',
},
{
...commonCases,
},
{
scenarioName: 'text specific',
},
);

await mount(
<div style={{width: 400}}>
{smokeScenarios.map(([title, props]) => (
<div key={title}>
<h4>{title}</h4>
<div>
<Avatar {...props} />
</div>
</div>
))}
</div>,
);

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

export const sizeCases: Cases<AvatarProps['size']> = ['xs', 's', 'm', 'l', 'xl'];
export const themeCases: Cases<AvatarProps['theme']> = ['normal', 'brand'];
export const viewCases: Cases<AvatarProps['view']> = ['filled', 'outlined'];
export const backgroundColorCases: Cases<AvatarProps['backgroundColor']> = ['darkblue'];
export const borderColorCases: Cases<AvatarProps['borderColor']> = ['tomato'];
export const titleCases: Cases<AvatarProps['title']> = ['Title'];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Try to compose it into one object

19 changes: 19 additions & 0 deletions src/components/Avatar/__tests__/helpersPlaywright.tsx

Large diffs are not rendered by default.

Loading