Skip to content

chore: add stories for MoreMenu #12464

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Mar 8, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 55 additions & 0 deletions site/src/components/MoreMenu/MoreMenu.stories.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
import GrassIcon from "@mui/icons-material/Grass";
import KitesurfingIcon from "@mui/icons-material/Kitesurfing";
import type { Meta, StoryObj } from "@storybook/react";
import {
MoreMenu,
MoreMenuContent,
MoreMenuItem,
MoreMenuTrigger,
ThreeDotsButton,
} from "./MoreMenu";
import { action } from "@storybook/addon-actions";
import { expect, screen, userEvent, waitFor, within } from "@storybook/test";

const meta: Meta<typeof MoreMenu> = {
title: "components/MoreMenu",
component: MoreMenu,
};

export default meta;
type Story = StoryObj<typeof MoreMenu>;

const Example: Story = {
args: {
children: (
<>
<MoreMenuTrigger>
<ThreeDotsButton />
</MoreMenuTrigger>
<MoreMenuContent>
<MoreMenuItem onClick={() => action("grass")}>
<GrassIcon />
Touch grass
</MoreMenuItem>
<MoreMenuItem onClick={() => action("water")}>
<KitesurfingIcon />
Touch water
</MoreMenuItem>
</MoreMenuContent>
</>
),
},
play: async ({ canvasElement, step }) => {
const canvas = within(canvasElement);

await step("Open menu", async () => {
await userEvent.click(canvas.getByRole("button"));
await waitFor(() => {
expect(screen.getByText(/touch grass/i)).toBeInTheDocument();
expect(screen.getByText(/touch water/i)).toBeInTheDocument();
});
});
},
};

export { Example as MoreMenu };
8 changes: 2 additions & 6 deletions site/src/components/MoreMenu/MoreMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -111,11 +111,7 @@ export const MoreMenuItem: FC<MoreMenuItemProps> = ({
danger = false,
...menuItemProps
}) => {
const ctx = useContext(MoreMenuContext);

if (!ctx) {
throw new Error("MoreMenuItem must be used inside of MoreMenu");
}
const menu = useMoreMenuContext();

return (
<MenuItem
Expand All @@ -131,7 +127,7 @@ export const MoreMenuItem: FC<MoreMenuItemProps> = ({
onClick={(e) => {
menuItemProps.onClick && menuItemProps.onClick(e);
if (closeOnClick) {
ctx.close();
menu.close();
}
}}
/>
Expand Down