Skip to content

Commit

Permalink
WEB-2113 add screenshot tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Pedro Ladaria committed Dec 19, 2024
1 parent fda0071 commit 1fadd9c
Show file tree
Hide file tree
Showing 10 changed files with 45 additions and 3 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.
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.
35 changes: 35 additions & 0 deletions src/__screenshot_tests__/drawer-screenshot-test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import {openStoryPage, screen} from '../test-utils';

import type {Device} from '../test-utils';

test.each`
device | withActions | dismissible | contentLength
${'MOBILE_IOS'} | ${true} | ${true} | ${1}
${'MOBILE_IOS'} | ${true} | ${true} | ${5}
${'MOBILE_IOS'} | ${true} | ${false} | ${1}
${'DESKTOP'} | ${true} | ${true} | ${1}
${'TABLET'} | ${true} | ${true} | ${1}
${'MOBILE_IOS'} | ${false} | ${true} | ${1}
${'DESKTOP'} | ${false} | ${true} | ${1}
${'TABLET'} | ${false} | ${true} | ${1}
`(
'Drawer $device actions:$withActions dismissible:$dismissible contentLength:$contentLength',
async ({device, withActions, dismissible}) => {
const page = await openStoryPage({
id: 'components-modals-drawer--default',
device: device as Device,
args: {
showButton: withActions,
showSecondaryButton: withActions,
showButtonLink: withActions,
onDismissHandler: dismissible,
},
});

const button = await screen.findByRole('button', {name: 'Open Drawer'});
await button.click();

const image = await page.screenshot();
expect(image).toMatchImageSnapshot();
}
);
13 changes: 10 additions & 3 deletions src/__stories__/drawer-story.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ export const Default = ({
description,
contentLength,
onDismissHandler,
showButton,
showSecondaryButton,
showButtonLink,
}: Args): JSX.Element => {
const [isOpen, setIsOpen] = React.useState(false);
const [result, setResult] = React.useState('');
Expand All @@ -52,9 +55,13 @@ export const Default = ({
description={description}
onClose={() => setIsOpen(false)}
onDismiss={onDismissHandler ? () => setResult('dismiss') : undefined}
button={{text: 'Primary', onPress: () => setResult('primary')}}
secondaryButton={{text: 'Secondary', onPress: () => setResult('secondary')}}
buttonLink={{text: 'Link', onPress: () => setResult('link')}}
button={showButton ? {text: 'Primary', onPress: () => setResult('primary')} : undefined}
secondaryButton={
showSecondaryButton
? {text: 'Secondary', onPress: () => setResult('secondary')}
: undefined
}
buttonLink={showButtonLink ? {text: 'Link', onPress: () => setResult('link')} : undefined}
>
{content}
</Drawer>
Expand Down

0 comments on commit 1fadd9c

Please sign in to comment.