Skip to content

Commit

Permalink
test(Sheet): add smoke visual tests (#1802)
Browse files Browse the repository at this point in the history
  • Loading branch information
itwillwork authored Dec 27, 2024
1 parent a29b695 commit 8df5a5c
Show file tree
Hide file tree
Showing 13 changed files with 81 additions and 5 deletions.
1 change: 1 addition & 0 deletions playwright/core/mountFixture.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ export const mountFixture: PlaywrightFixture<MountFixture> = async ({mount: base
boxSizing: options?.width ? 'content-box' : undefined,
width: options?.width ? options.width : 'fit-content',
height: 'fit-content',
...options?.rootStyle,
}}
className="playwright-wrapper-test"
>
Expand Down
5 changes: 4 additions & 1 deletion playwright/core/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,10 @@ import type {
interface ComponentFixtures {
mount<HooksConfig>(
component: React.JSX.Element,
options?: MountOptions<HooksConfig> & {width?: number | string},
options?: MountOptions<HooksConfig> & {
width?: number | string;
rootStyle?: React.CSSProperties;
},
): Promise<MountResult>;
}

Expand Down
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.
38 changes: 34 additions & 4 deletions src/components/Sheet/__tests__/Sheet.visual.test.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
import {expect} from '@playwright/test';

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

import {createSmokeScenarios} from '../../../stories/tests-factory/create-smoke-scenarios';
import type {SheetProps} from '../Sheet';
import {DEFAULT_SHEET_QA} from '../__stories__/constants';

import {hideTopBarCases, titleCases} from './cases';
import {QASheet} from './constants';
import {TestSheet} from './helpers';
import {SheetStories} from './helpersPlaywright';

test.describe('Sheet', () => {
test.describe('Sheet', {tag: '@Sheet'}, () => {
test('render story: <Default>', async ({page, mount, expectScreenshot}) => {
await mount(<SheetStories.Default />);

Expand All @@ -21,4 +24,31 @@ test.describe('Sheet', () => {
component: sheetLocator,
});
});

createSmokeScenarios<Partial<Omit<SheetProps, 'visible' | 'onClose'>>>(
{},
{
hideTopBar: hideTopBarCases,
title: titleCases,
},
).forEach(([title, props]) => {
smokeTest(title, async ({mount, page, expectScreenshot}) => {
await page.setViewportSize({width: 500, height: 500});

const root = await mount(<TestSheet {...props} />, {
rootStyle: {
padding: 0,
width: '100%',
minHeight: '500px',
},
});

await root.locator('button').click();
await expect(page.locator(`[data-qa='${QASheet.content}']`)).toBeVisible();

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

export const hideTopBarCases: Cases<SheetProps['hideTopBar']> = [true];
export const titleCases: Cases<SheetProps['title']> = ['Title'];
3 changes: 3 additions & 0 deletions src/components/Sheet/__tests__/constants.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export const QASheet = {
content: 'content',
};
34 changes: 34 additions & 0 deletions src/components/Sheet/__tests__/helpers.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import * as React from 'react';

import type {SheetProps} from '../Sheet';
import {Sheet} from '../Sheet';

import {QASheet} from './constants';

export const TestSheet = (props: Partial<Omit<SheetProps, 'visible' | 'onClose'>>) => {
const [visible, setVisible] = React.useState(false);

return (
<div>
<button onClick={() => setVisible(true)}>Show modal</button>
<Sheet
{...props}
visible={visible}
onClose={() => setVisible(false)}
qa={QASheet.content}
>
<div
style={{
minHeight: 100,
border: '1px solid tomato',
display: 'flex',
justifyContent: 'center',
alignItems: 'center',
}}
>
Sheet content
</div>
</Sheet>
</div>
);
};

0 comments on commit 8df5a5c

Please sign in to comment.