Skip to content

Commit

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

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

import {disabledCases, indeterminateCases, sizeCases} from './cases';

test.describe('Switch', {tag: '@Switch'}, () => {
const defaultProps: SwitchProps = {
content: 'label',
};

smokeTest('', async ({mount, expectScreenshot}) => {
const smokeScenarios = createSmokeScenarios(defaultProps, {
size: sizeCases,
disabled: disabledCases,
indeterminate: indeterminateCases,
});

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

await expectScreenshot({});
});

smokeTest('checked', async ({mount, expectScreenshot}) => {
const smokeScenarios = createSmokeScenarios(
{
...defaultProps,
checked: true,
},
{
size: sizeCases,
disabled: disabledCases,
indeterminate: indeterminateCases,
},
);

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

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

export const disabledCases: Cases<SwitchProps['disabled']> = [true];
export const indeterminateCases: Cases<SwitchProps['indeterminate']> = [true];
export const sizeCases: Cases<SwitchProps['size']> = ['m', 'l'];

0 comments on commit 6a7b2f4

Please sign in to comment.