Skip to content

Commit

Permalink
test(Text): add smoke visual tests (#1798)
Browse files Browse the repository at this point in the history
  • Loading branch information
itwillwork authored Dec 25, 2024
1 parent 453aa84 commit c8ba447
Show file tree
Hide file tree
Showing 8 changed files with 168 additions and 0 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.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
86 changes: 86 additions & 0 deletions src/components/Text/__tests__/Text.visual.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
import React from 'react';

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

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

import {colorCases, ellipsisCases, variantCases, whiteSpaceCases, wordBreakCases} from './cases';
import {TestText} from './helpersPlaywright';
import {TextStories} from './stories';

const longText =
'Lorem ipsum dolor sit, amet consectetur adipisicing elit. Voluptates asperiores accusamus est, ab rerum harum hic delectus fuga veniam! Hic, atque, quia sunt consectetur eius corrupti, expedita sapiente exercitationem aperiam quibusdam libero ipsa veritatis quisquam! Debitis eos unde, blanditiis ipsam adipisci, soluta incidunt architecto quidem, repellat commodi tempore! Enim assumenda nam esse laudantium sequi quaerat maiores, voluptatum quibusdam temporibus nulla perspiciatis! Corrupti error aliquid iure asperiores voluptate. Nisi temporibus nesciunt quasi animi, accusamus officia debitis voluptatum ratione ullam delectus, adipisci, repellendus vitae in amet sit magni iste impedit? Exercitationem rerum impedit sed earum iusto modi et officia aspernatur quibusdam? Fugit.';

test.describe('Text', {tag: '@Text'}, () => {
smokeTest('regular', async ({mount, expectScreenshot}) => {
const smokeScenarios = createSmokeScenarios<TextProps>(
{},
{
color: colorCases,
variant: variantCases,
},
);

await mount(
<div style={{backgroundColor: '#F5F5F5'}}>
{smokeScenarios.map(([title, props]) => (
<div key={title}>
<h4>{title}</h4>
<div>
<TestText {...props}>Text</TestText>
</div>
</div>
))}
</div>,
);

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

smokeTest('long text', async ({mount, expectScreenshot}) => {
const smokeScenarios = createSmokeScenarios<TextProps>(
{},
{
ellipsis: ellipsisCases,
whiteSpace: whiteSpaceCases,
wordBreak: wordBreakCases,
},
);

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

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

smokeTest('render story <Ellipsis />', async ({mount, expectScreenshot}) => {
await mount(<TextStories.Ellipsis />);

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

smokeTest('render story <WordBreak />', async ({mount, expectScreenshot}) => {
await mount(<TextStories.WordBreak />);

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

export const colorCases: Cases<TextProps['color']> = [
'primary',
'complementary',
'secondary',
'hint',
'info',
'info-heavy',
'positive',
'positive-heavy',
'warning',
'warning-heavy',
'danger',
'danger-heavy',
'utility',
'utility-heavy',
'misc',
'misc-heavy',
'brand',
'link',
'link-hover',
'link-visited',
'link-visited-hover',
'dark-primary',
'dark-complementary',
'dark-secondary',
'light-primary',
'light-complementary',
'light-secondary',
'light-hint',
'inverted-primary',
'inverted-complementary',
'inverted-secondary',
'inverted-hint',
];
export const variantCases: Cases<TextProps['variant']> = [
'display-4',
'display-3',
'display-2',
'display-1',
'header-2',
'header-1',
'subheader-3',
'subheader-2',
'subheader-1',
'body-3',
'body-2',
'body-1',
'body-short',
'caption-2',
'caption-1',
'code-3',
'code-inline-3',
'code-2',
'code-inline-2',
'code-1',
'code-inline-1',
];
export const ellipsisCases: Cases<TextProps['ellipsis']> = [true];
export const whiteSpaceCases: Cases<TextProps['whiteSpace']> = ['nowrap', 'break-spaces'];
export const wordBreakCases: Cases<TextProps['wordBreak']> = ['break-all', 'break-word'];
14 changes: 14 additions & 0 deletions src/components/Text/__tests__/helpersPlaywright.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import React from 'react';

import type {TextProps} from '../Text';
import {Text} from '../Text';

export const TestText = (props: Partial<TextProps>) => {
return (
<Text
// eslint-disable-next-line react/no-children-prop
children={<span>Text</span>}
{...props}
/>
);
};
5 changes: 5 additions & 0 deletions src/components/Text/__tests__/stories.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import {composeStories} from '@storybook/react';

import * as CSFStories from '../__stories__/Text.stories';

export const TextStories = composeStories(CSFStories);

0 comments on commit c8ba447

Please sign in to comment.