Skip to content

Commit

Permalink
more menu tests
Browse files Browse the repository at this point in the history
  • Loading branch information
shaneeza committed Oct 7, 2024
1 parent 8e8142f commit d2e1025
Show file tree
Hide file tree
Showing 4 changed files with 102 additions and 29 deletions.
21 changes: 21 additions & 0 deletions packages/combobox/src/Combobox.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
StoryType,
} from '@lg-tools/storybook-utils';
import { StoryFn } from '@storybook/react';
import { userEvent, within } from '@storybook/testing-library';

import Button from '@leafygreen-ui/button';
import { css } from '@leafygreen-ui/emotion';
Expand Down Expand Up @@ -278,3 +279,23 @@ DisabledInput.parameters = {
},
},
};

export const InitialLongComboboxOpen = {
render: () => {
return (
<Combobox
multiselect={false}
label="Choose a fruit"
description="Please pick one"
placeholder="Select fruit"
>
{getComboboxOptions()}
</Combobox>
);
},
play: async ctx => {
const { findByRole } = within(ctx.canvasElement.parentElement!);
const trigger = await findByRole('combobox');
userEvent.click(trigger);
},
};
2 changes: 1 addition & 1 deletion packages/menu/src/Menu.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ export const Generated = {
},
} satisfies StoryObj<typeof Menu>;

export const InitialLongMenuOpen = {
export const InitialLongMenuOpen: StoryObj<typeof Menu> = {
...LiveExample,
play: async ctx => {
const { findByRole } = within(ctx.canvasElement.parentElement!);
Expand Down
31 changes: 31 additions & 0 deletions packages/search-input/src/SearchInput.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
StoryMetaType,
} from '@lg-tools/storybook-utils';
import { StoryFn } from '@storybook/react';
import { userEvent, within } from '@storybook/testing-library';
import kebabCase from 'lodash/kebabCase';
import startCase from 'lodash/startCase';

Expand Down Expand Up @@ -310,3 +311,33 @@ WithResults.parameters = {
};

export const Generated = () => {};

export const InitialLongSearchOpen = {
render: () => {
return (
<div
className={css`
width: 256px;
`}
>
<SearchInput aria-label="Item">
{data.map(item => (
<SearchResult
key={item.name}
description={item.description}
onClick={() => console.log('Storybook: Clicked', item.name)}
>
{startCase(item.name)}
</SearchResult>
))}
</SearchInput>
</div>
);
},
play: async ctx => {
const { getAllByRole } = within(ctx.canvasElement.parentElement!);
const trigger = await getAllByRole('searchbox')[0];
console.log({ trigger });
userEvent.click(trigger);
},
};
77 changes: 49 additions & 28 deletions packages/select/src/Select.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,38 @@ import {
StoryMetaType,
} from '@lg-tools/storybook-utils';
import { StoryFn } from '@storybook/react';
import { userEvent, within } from '@storybook/testing-library';

import { css, cx } from '@leafygreen-ui/emotion';
import BeakerIcon from '@leafygreen-ui/icon/dist/Beaker';
import LeafyGreenProvider from '@leafygreen-ui/leafygreen-provider';

import { Option, OptionGroup, Select, type SelectProps, Size, State } from '.';

const childrenArray = [
<Option key="long" value="long" description="I know a little lorem ipsum">
Cras mattis consectetur purus sit amet fermentum. Maecenas sed diam eget
risus varius blandit sit amet non magna.
</Option>,
<OptionGroup key="Common" label="Common">
<Option value="dog">Dog</Option>
<Option value="cat">Cat</Option>
</OptionGroup>,
<OptionGroup key="Less common" label="Less common">
<Option value="hamster">Hamster</Option>
<Option value="parrot">Parrot</Option>
</OptionGroup>,
<Option key="iguana" value="iguana">
Mexican spiny-tailed iguana
</Option>,
<Option key="spider" value="spider" description="I'm chill, I swear">
Spider
</Option>,
<Option key="aardvark" value="aardvark" disabled description="Call me Arthur">
Aardvark
</Option>,
];

const meta: StoryMetaType<typeof Select> = {
title: 'Components/Select',
component: Select,
Expand Down Expand Up @@ -46,34 +71,7 @@ const meta: StoryMetaType<typeof Select> = {
disabled: false,
allowDeselect: false,
darkMode: false,
children: [
<Option key="long" value="long" description="I know a little lorem ipsum">
Cras mattis consectetur purus sit amet fermentum. Maecenas sed diam eget
risus varius blandit sit amet non magna.
</Option>,
<OptionGroup key="Common" label="Common">
<Option value="dog">Dog</Option>
<Option value="cat">Cat</Option>
</OptionGroup>,
<OptionGroup key="Less common" label="Less common">
<Option value="hamster">Hamster</Option>
<Option value="parrot">Parrot</Option>
</OptionGroup>,
<Option key="iguana" value="iguana">
Mexican spiny-tailed iguana
</Option>,
<Option key="spider" value="spider" description="I'm chill, I swear">
Spider
</Option>,
<Option
key="aardvark"
value="aardvark"
disabled
description="Call me Arthur"
>
Aardvark
</Option>,
],
children: childrenArray,
usePortal: true,
},
argTypes: {
Expand Down Expand Up @@ -164,3 +162,26 @@ NoPortal.parameters = {
};

export const Generated = () => {};

export const InitialLongSelectOpen = {
render: () => {
return (
<Select
className={cx(
css`
min-width: 200px;
max-width: 400px;
`,
)}
aria-label="hey"
// eslint-disable-next-line react/no-children-prop
children={[...childrenArray, ...childrenArray]}
/>
);
},
play: async ctx => {
const { findByRole } = within(ctx.canvasElement.parentElement!);
const trigger = await findByRole('button');
userEvent.click(trigger);
},
};

0 comments on commit d2e1025

Please sign in to comment.