add clicking on dropdown menu test (#2103)
* add clicking on dropdown menu test * add play function
This commit is contained in:
@ -1,7 +1,10 @@
|
|||||||
import { useState } from 'react';
|
import { useState } from 'react';
|
||||||
import styled from '@emotion/styled';
|
import styled from '@emotion/styled';
|
||||||
import { Decorator, Meta, StoryObj } from '@storybook/react';
|
import { Decorator, Meta, StoryObj } from '@storybook/react';
|
||||||
|
import { userEvent, within } from '@storybook/testing-library';
|
||||||
|
import { PlayFunction } from '@storybook/types';
|
||||||
|
|
||||||
|
import { Button } from '@/ui/input/button/components/Button';
|
||||||
import { DropdownMenuSkeletonItem } from '@/ui/input/relation-picker/components/skeletons/DropdownMenuSkeletonItem';
|
import { DropdownMenuSkeletonItem } from '@/ui/input/relation-picker/components/skeletons/DropdownMenuSkeletonItem';
|
||||||
import { MenuItem } from '@/ui/navigation/menu-item/components/MenuItem';
|
import { MenuItem } from '@/ui/navigation/menu-item/components/MenuItem';
|
||||||
import { MenuItemMultiSelectAvatar } from '@/ui/navigation/menu-item/components/MenuItemMultiSelectAvatar';
|
import { MenuItemMultiSelectAvatar } from '@/ui/navigation/menu-item/components/MenuItemMultiSelectAvatar';
|
||||||
@ -9,6 +12,8 @@ import { MenuItemSelectAvatar } from '@/ui/navigation/menu-item/components/MenuI
|
|||||||
import { Avatar } from '@/users/components/Avatar';
|
import { Avatar } from '@/users/components/Avatar';
|
||||||
import { ComponentDecorator } from '~/testing/decorators/ComponentDecorator';
|
import { ComponentDecorator } from '~/testing/decorators/ComponentDecorator';
|
||||||
|
|
||||||
|
import { DropdownScope } from '../../scopes/DropdownScope';
|
||||||
|
import { DropdownMenu } from '../DropdownMenu';
|
||||||
import { DropdownMenuHeader } from '../DropdownMenuHeader';
|
import { DropdownMenuHeader } from '../DropdownMenuHeader';
|
||||||
import { DropdownMenuInput } from '../DropdownMenuInput';
|
import { DropdownMenuInput } from '../DropdownMenuInput';
|
||||||
import { DropdownMenuInputContainer } from '../DropdownMenuInputContainer';
|
import { DropdownMenuInputContainer } from '../DropdownMenuInputContainer';
|
||||||
@ -18,20 +23,33 @@ import { StyledDropdownMenu } from '../StyledDropdownMenu';
|
|||||||
import { StyledDropdownMenuSeparator } from '../StyledDropdownMenuSeparator';
|
import { StyledDropdownMenuSeparator } from '../StyledDropdownMenuSeparator';
|
||||||
import { StyledDropdownMenuSubheader } from '../StyledDropdownMenuSubheader';
|
import { StyledDropdownMenuSubheader } from '../StyledDropdownMenuSubheader';
|
||||||
|
|
||||||
const meta: Meta<typeof StyledDropdownMenu> = {
|
const meta: Meta<typeof DropdownMenu> = {
|
||||||
title: 'UI/Layout/Dropdown/DropdownMenu',
|
title: 'UI/Layout/Dropdown/DropdownMenu',
|
||||||
component: StyledDropdownMenu,
|
component: DropdownMenu,
|
||||||
decorators: [ComponentDecorator],
|
|
||||||
|
decorators: [
|
||||||
|
ComponentDecorator,
|
||||||
|
(Story) => (
|
||||||
|
<DropdownScope dropdownScopeId="testDropdownMenu">
|
||||||
|
<Story />
|
||||||
|
</DropdownScope>
|
||||||
|
),
|
||||||
|
],
|
||||||
|
args: {
|
||||||
|
clickableComponent: <Button title="Open Dropdown" />,
|
||||||
|
dropdownHotkeyScope: { scope: 'testDropdownMenu' },
|
||||||
|
dropdownOffset: { x: 0, y: -8 },
|
||||||
|
},
|
||||||
argTypes: {
|
argTypes: {
|
||||||
as: { table: { disable: true } },
|
clickableComponent: { control: false },
|
||||||
children: { control: false },
|
dropdownHotkeyScope: { control: false },
|
||||||
theme: { table: { disable: true } },
|
dropdownOffset: { control: false },
|
||||||
width: { type: 'number', defaultValue: undefined },
|
dropdownComponents: { control: false },
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
export default meta;
|
export default meta;
|
||||||
type Story = StoryObj<typeof StyledDropdownMenu>;
|
type Story = StoryObj<typeof DropdownMenu>;
|
||||||
|
|
||||||
const FakeContentBelow = () => (
|
const FakeContentBelow = () => (
|
||||||
<div style={{ position: 'absolute' }}>
|
<div style={{ position: 'absolute' }}>
|
||||||
@ -167,15 +185,30 @@ const WithContentBelowDecorator: Decorator = (Story) => (
|
|||||||
</StyledFakeBelowContainer>
|
</StyledFakeBelowContainer>
|
||||||
);
|
);
|
||||||
|
|
||||||
|
const playInteraction: PlayFunction<any, any> = async ({ canvasElement }) => {
|
||||||
|
const canvas = within(canvasElement);
|
||||||
|
|
||||||
|
const button = await canvas.findByRole('button');
|
||||||
|
|
||||||
|
userEvent.click(button);
|
||||||
|
};
|
||||||
|
|
||||||
export const Empty: Story = {
|
export const Empty: Story = {
|
||||||
args: { children: <StyledFakeMenuContent /> },
|
args: {
|
||||||
|
dropdownComponents: (
|
||||||
|
<StyledDropdownMenu>
|
||||||
|
<StyledFakeMenuContent />
|
||||||
|
</StyledDropdownMenu>
|
||||||
|
),
|
||||||
|
},
|
||||||
|
play: playInteraction,
|
||||||
};
|
};
|
||||||
|
|
||||||
export const WithHeaders: Story = {
|
export const WithHeaders: Story = {
|
||||||
decorators: [WithContentBelowDecorator],
|
decorators: [WithContentBelowDecorator],
|
||||||
args: {
|
args: {
|
||||||
children: (
|
dropdownComponents: (
|
||||||
<>
|
<StyledDropdownMenu>
|
||||||
<DropdownMenuHeader>Header</DropdownMenuHeader>
|
<DropdownMenuHeader>Header</DropdownMenuHeader>
|
||||||
<StyledDropdownMenuSeparator />
|
<StyledDropdownMenuSeparator />
|
||||||
<StyledDropdownMenuSubheader>Subheader 1</StyledDropdownMenuSubheader>
|
<StyledDropdownMenuSubheader>Subheader 1</StyledDropdownMenuSubheader>
|
||||||
@ -191,31 +224,33 @@ export const WithHeaders: Story = {
|
|||||||
<MenuItem text={name} />
|
<MenuItem text={name} />
|
||||||
))}
|
))}
|
||||||
</DropdownMenuItemsContainer>
|
</DropdownMenuItemsContainer>
|
||||||
</>
|
</StyledDropdownMenu>
|
||||||
),
|
),
|
||||||
},
|
},
|
||||||
|
play: playInteraction,
|
||||||
};
|
};
|
||||||
|
|
||||||
export const SearchWithLoadingMenu: Story = {
|
export const SearchWithLoadingMenu: Story = {
|
||||||
decorators: [WithContentBelowDecorator],
|
decorators: [WithContentBelowDecorator],
|
||||||
args: {
|
args: {
|
||||||
children: (
|
dropdownComponents: (
|
||||||
<>
|
<StyledDropdownMenu>
|
||||||
<DropdownMenuSearchInput value="query" autoFocus />
|
<DropdownMenuSearchInput value="query" autoFocus />
|
||||||
<StyledDropdownMenuSeparator />
|
<StyledDropdownMenuSeparator />
|
||||||
<DropdownMenuItemsContainer hasMaxHeight>
|
<DropdownMenuItemsContainer hasMaxHeight>
|
||||||
<DropdownMenuSkeletonItem />
|
<DropdownMenuSkeletonItem />
|
||||||
</DropdownMenuItemsContainer>
|
</DropdownMenuItemsContainer>
|
||||||
</>
|
</StyledDropdownMenu>
|
||||||
),
|
),
|
||||||
},
|
},
|
||||||
|
play: playInteraction,
|
||||||
};
|
};
|
||||||
|
|
||||||
export const WithInput: Story = {
|
export const WithInput: Story = {
|
||||||
decorators: [WithContentBelowDecorator],
|
decorators: [WithContentBelowDecorator],
|
||||||
args: {
|
args: {
|
||||||
children: (
|
dropdownComponents: (
|
||||||
<>
|
<StyledDropdownMenu>
|
||||||
<DropdownMenuInputContainer>
|
<DropdownMenuInputContainer>
|
||||||
<DropdownMenuInput defaultValue="Lorem ipsum" autoFocus />
|
<DropdownMenuInput defaultValue="Lorem ipsum" autoFocus />
|
||||||
</DropdownMenuInputContainer>
|
</DropdownMenuInputContainer>
|
||||||
@ -225,29 +260,36 @@ export const WithInput: Story = {
|
|||||||
<MenuItem text={name} />
|
<MenuItem text={name} />
|
||||||
))}
|
))}
|
||||||
</DropdownMenuItemsContainer>
|
</DropdownMenuItemsContainer>
|
||||||
</>
|
</StyledDropdownMenu>
|
||||||
),
|
),
|
||||||
},
|
},
|
||||||
|
play: playInteraction,
|
||||||
};
|
};
|
||||||
|
|
||||||
export const SelectableMenuItemWithAvatar: Story = {
|
export const SelectableMenuItemWithAvatar: Story = {
|
||||||
decorators: [WithContentBelowDecorator],
|
decorators: [WithContentBelowDecorator],
|
||||||
args: {
|
args: {
|
||||||
children: (
|
dropdownComponents: (
|
||||||
<DropdownMenuItemsContainer hasMaxHeight>
|
<StyledDropdownMenu>
|
||||||
<FakeSelectableMenuItemList hasAvatar />
|
<DropdownMenuItemsContainer hasMaxHeight>
|
||||||
</DropdownMenuItemsContainer>
|
<FakeSelectableMenuItemList hasAvatar />
|
||||||
|
</DropdownMenuItemsContainer>
|
||||||
|
</StyledDropdownMenu>
|
||||||
),
|
),
|
||||||
},
|
},
|
||||||
|
play: playInteraction,
|
||||||
};
|
};
|
||||||
|
|
||||||
export const CheckableMenuItemWithAvatar: Story = {
|
export const CheckableMenuItemWithAvatar: Story = {
|
||||||
decorators: [WithContentBelowDecorator],
|
decorators: [WithContentBelowDecorator],
|
||||||
args: {
|
args: {
|
||||||
children: (
|
dropdownComponents: (
|
||||||
<DropdownMenuItemsContainer hasMaxHeight>
|
<StyledDropdownMenu>
|
||||||
<FakeCheckableMenuItemList hasAvatar />
|
<DropdownMenuItemsContainer hasMaxHeight>
|
||||||
</DropdownMenuItemsContainer>
|
<FakeCheckableMenuItemList hasAvatar />
|
||||||
|
</DropdownMenuItemsContainer>
|
||||||
|
</StyledDropdownMenu>
|
||||||
),
|
),
|
||||||
},
|
},
|
||||||
|
play: playInteraction,
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user