-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' of github.com:Telefonica/mistica-web into OBVIV…
…O-2814
- Loading branch information
Showing
20 changed files
with
722 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file added
BIN
+22.3 KB
...t-tsx-drawer-desktop-actions-false-dismissible-true-content-length-1-1-snap.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+27.4 KB
...st-tsx-drawer-desktop-actions-true-dismissible-true-content-length-1-1-snap.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+31.7 KB
...sx-drawer-mobile-ios-actions-false-dismissible-true-content-length-1-1-snap.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+40.4 KB
...sx-drawer-mobile-ios-actions-true-dismissible-false-content-length-1-1-snap.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+40.8 KB
...tsx-drawer-mobile-ios-actions-true-dismissible-true-content-length-1-1-snap.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+47.7 KB
...tsx-drawer-mobile-ios-actions-true-dismissible-true-content-length-5-1-snap.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+17.8 KB
...st-tsx-drawer-tablet-actions-false-dismissible-true-content-length-1-1-snap.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+22.1 KB
...est-tsx-drawer-tablet-actions-true-dismissible-true-content-length-1-1-snap.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
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, contentLength}) => { | ||
const page = await openStoryPage({ | ||
id: 'components-modals-drawer--default', | ||
device: device as Device, | ||
args: { | ||
showButton: withActions, | ||
showSecondaryButton: withActions, | ||
showButtonLink: withActions, | ||
onDismissHandler: dismissible, | ||
contentLength, | ||
}, | ||
}); | ||
|
||
const button = await screen.findByRole('button', {name: 'Open Drawer'}); | ||
await button.click(); | ||
|
||
const image = await page.screenshot(); | ||
expect(image).toMatchImageSnapshot(); | ||
} | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
import * as React from 'react'; | ||
import Drawer from '../drawer'; | ||
import {Placeholder} from '../placeholder'; | ||
import Stack from '../stack'; | ||
import {ButtonPrimary} from '../button'; | ||
import {Text3} from '../text'; | ||
|
||
export default { | ||
title: 'Components/Modals/Drawer', | ||
component: Drawer, | ||
argTypes: { | ||
width: { | ||
control: {type: 'range', min: 300, max: 1000, step: 1}, | ||
}, | ||
}, | ||
}; | ||
|
||
type Args = { | ||
title: string; | ||
subtitle: string; | ||
description: string; | ||
contentLength: number; | ||
onDismissHandler: boolean; | ||
showButton: boolean; | ||
showSecondaryButton: boolean; | ||
showButtonLink: boolean; | ||
width: number; | ||
}; | ||
|
||
export const Default = ({ | ||
title, | ||
subtitle, | ||
description, | ||
contentLength, | ||
onDismissHandler, | ||
showButton, | ||
showSecondaryButton, | ||
showButtonLink, | ||
width, | ||
}: Args): JSX.Element => { | ||
const [isOpen, setIsOpen] = React.useState(false); | ||
const [result, setResult] = React.useState(''); | ||
const content = ( | ||
<Stack space={16}> | ||
{Array.from({length: contentLength}).map((_, index) => ( | ||
<Placeholder key={index} height={200} /> | ||
))} | ||
</Stack> | ||
); | ||
|
||
return ( | ||
<> | ||
<Stack space={16}> | ||
<ButtonPrimary onPress={() => setIsOpen(true)}>Open Drawer</ButtonPrimary> | ||
<Text3 regular> | ||
Result: <span data-testid="result">{result}</span> | ||
</Text3> | ||
</Stack> | ||
{isOpen && ( | ||
<Drawer | ||
width={width} | ||
title={title} | ||
subtitle={subtitle} | ||
description={description} | ||
onClose={() => setIsOpen(false)} | ||
onDismiss={onDismissHandler ? () => setResult('dismiss') : undefined} | ||
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> | ||
)} | ||
</> | ||
); | ||
}; | ||
|
||
Default.storyName = 'Drawer'; | ||
|
||
Default.args = { | ||
title: 'Title', | ||
subtitle: 'Subtitle', | ||
description: 'Description', | ||
contentLength: 2, | ||
onDismissHandler: true, | ||
showButton: true, | ||
showSecondaryButton: true, | ||
showButtonLink: true, | ||
width: 0, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,115 @@ | ||
import * as React from 'react'; | ||
import {makeTheme} from './test-utils'; | ||
import {render, screen, waitFor} from '@testing-library/react'; | ||
import ThemeContextProvider from '../theme-context-provider'; | ||
import Drawer from '../drawer'; | ||
import userEvent from '@testing-library/user-event'; | ||
|
||
const DrawerTest = ({ | ||
onDismiss, | ||
onButtonPrimaryPress, | ||
onButtonSecondaryPress, | ||
onButtonLinkPress, | ||
}: { | ||
onDismiss?: () => void; | ||
onButtonPrimaryPress?: () => void; | ||
onButtonSecondaryPress?: () => void; | ||
onButtonLinkPress?: () => void; | ||
}) => { | ||
const [isOpen, setIsOpen] = React.useState(false); | ||
return ( | ||
<ThemeContextProvider theme={makeTheme()}> | ||
<button onClick={() => setIsOpen(true)}>open</button> | ||
{isOpen && ( | ||
<Drawer | ||
dismissLabel="CustomDismissLabel" | ||
onDismiss={onDismiss} | ||
onClose={() => setIsOpen(false)} | ||
button={{text: 'Primary', onPress: onButtonPrimaryPress}} | ||
secondaryButton={{text: 'Secondary', onPress: onButtonSecondaryPress}} | ||
buttonLink={{text: 'Link', onPress: onButtonLinkPress}} | ||
/> | ||
)} | ||
</ThemeContextProvider> | ||
); | ||
}; | ||
|
||
test.each(['esc', 'overlay', 'x'])('Drawer dismiss: %s', async (dismissMethod: string) => { | ||
const onDismissSpy = jest.fn(); | ||
render(<DrawerTest onDismiss={onDismissSpy} />); | ||
|
||
const openButton = screen.getByRole('button', {name: 'open'}); | ||
await userEvent.click(openButton); | ||
|
||
const drawer = await screen.findByRole('dialog'); | ||
|
||
switch (dismissMethod) { | ||
case 'esc': | ||
await userEvent.keyboard('{Escape}'); | ||
break; | ||
case 'overlay': | ||
await userEvent.click(screen.getByTestId('drawerOverlay')); | ||
break; | ||
case 'x': | ||
await userEvent.click(screen.getByRole('button', {name: 'CustomDismissLabel'})); | ||
break; | ||
default: | ||
throw new Error('unexpected dismiss method'); | ||
} | ||
|
||
await waitFor(() => { | ||
expect(onDismissSpy).toHaveBeenCalledTimes(1); | ||
expect(drawer).not.toBeInTheDocument(); | ||
}); | ||
}); | ||
|
||
test.each(['primary', 'secondary', 'link'])('Drawer close: %s', async (closeMethod: string) => { | ||
const onButtonPrimaryPress = jest.fn(); | ||
const onButtonSecondaryPress = jest.fn(); | ||
const onButtonLinkPress = jest.fn(); | ||
|
||
render( | ||
<DrawerTest | ||
onButtonPrimaryPress={onButtonPrimaryPress} | ||
onButtonSecondaryPress={onButtonSecondaryPress} | ||
onButtonLinkPress={onButtonLinkPress} | ||
/> | ||
); | ||
|
||
const openButton = screen.getByRole('button', {name: 'open'}); | ||
await userEvent.click(openButton); | ||
|
||
const drawer = await screen.findByRole('dialog'); | ||
|
||
switch (closeMethod) { | ||
case 'primary': | ||
await userEvent.click(screen.getByRole('button', {name: 'Primary'})); | ||
break; | ||
case 'secondary': | ||
await userEvent.click(screen.getByRole('button', {name: 'Secondary'})); | ||
break; | ||
case 'link': | ||
await userEvent.click(screen.getByRole('button', {name: 'Link'})); | ||
break; | ||
default: | ||
throw new Error('unexpected dismiss method'); | ||
} | ||
|
||
await waitFor(() => { | ||
expect(drawer).not.toBeInTheDocument(); | ||
}); | ||
|
||
switch (closeMethod) { | ||
case 'primary': | ||
expect(onButtonPrimaryPress).toHaveBeenCalledTimes(1); | ||
break; | ||
case 'secondary': | ||
expect(onButtonSecondaryPress).toHaveBeenCalledTimes(1); | ||
break; | ||
case 'link': | ||
expect(onButtonLinkPress).toHaveBeenCalledTimes(1); | ||
break; | ||
default: | ||
throw new Error('unexpected dismiss method'); | ||
} | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.