Skip to content

Commit

Permalink
test(Divider): add smoke visual tests (#1784)
Browse files Browse the repository at this point in the history
  • Loading branch information
itwillwork authored Dec 26, 2024
1 parent cc6b6dd commit 8eefdd1
Show file tree
Hide file tree
Showing 4 changed files with 69 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.
34 changes: 34 additions & 0 deletions src/components/Divider/__tests__/Divider.visual.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import {smokeTest, test} from '~playwright/core';

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

import {orientationCases} from './cases';
import {ListWithDivider} from './helpers';

test.describe('Divider', {tag: '@Divider'}, () => {
smokeTest('smoke', async ({mount, expectScreenshot}) => {
const defaultProps: DividerProps = {};

const smokeScenarios = createSmokeScenarios(defaultProps, {
orientation: orientationCases,
});

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

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

export const orientationCases: Cases<DividerProps['orientation']> = ['vertical', 'horizontal'];
31 changes: 31 additions & 0 deletions src/components/Divider/__tests__/helpers.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import * as React from 'react';

import {Card} from '../../Card';
import {ListItem} from '../../List';
import {Flex} from '../../layout';
import type {DividerProps} from '../Divider';
import {Divider} from '../Divider';

const listItems = ['one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight'];

export const ListWithDivider = (props: DividerProps) => {
return (
<Card theme="normal" type="container">
<Flex direction={props.orientation === 'vertical' ? 'row' : 'column'}>
{listItems.map((value, index) => (
<React.Fragment key={index}>
<ListItem
item={value}
itemIndex={index}
active={false}
selected={false}
onActivate={() => {}}
/>

{index < listItems.length - 1 && <Divider {...props} />}
</React.Fragment>
))}
</Flex>
</Card>
);
};

0 comments on commit 8eefdd1

Please sign in to comment.