Skip to content

chore: add stories for Popover #12387

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 1 commit into from
Mar 1, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
57 changes: 57 additions & 0 deletions site/src/components/Popover/Popover.stories.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
import Button from "@mui/material/Button";
import type { Meta, StoryObj } from "@storybook/react";
import { expect, screen, userEvent, within, waitFor } from "@storybook/test";
import { Popover, PopoverTrigger, PopoverContent } from "./Popover";

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

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

const content = `
According to all known laws of aviation, there is no way a bee should be able to fly.
Its wings are too small to get its fat little body off the ground. The bee, of course,
flies anyway because bees don't care what humans think is impossible.
`;

export const Example: Story = {
args: {
children: (
<>
<PopoverTrigger>
<Button>Click here!</Button>
</PopoverTrigger>
<PopoverContent>{content}</PopoverContent>
</>
),
},
play: async ({ canvasElement, step }) => {
const canvas = within(canvasElement);

await step("click to open", async () => {
await userEvent.click(canvas.getByRole("button"));
await waitFor(() =>
expect(
screen.getByText(/according to all known laws/i),
).toBeInTheDocument(),
);
});
},
};

export const Horizontal: Story = {
args: {
children: (
<>
<PopoverTrigger>
<Button>Click here!</Button>
</PopoverTrigger>
<PopoverContent horizontal="right">{content}</PopoverContent>
</>
),
},
play: Example.play,
};
7 changes: 2 additions & 5 deletions site/src/modules/dashboard/Navbar/NavbarView.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import { MockPrimaryWorkspaceProxy, MockUser } from "testHelpers/entities";
import { renderWithAuth } from "testHelpers/renderHelpers";
import { Language as navLanguage, NavbarView } from "./NavbarView";
import { ProxyContextValue } from "contexts/ProxyContext";
import { action } from "@storybook/addon-actions";

const proxyContextValue: ProxyContextValue = {
proxy: {
Expand All @@ -14,15 +13,13 @@ const proxyContextValue: ProxyContextValue = {
isLoading: false,
isFetched: true,
setProxy: jest.fn(),
clearProxy: action("clearProxy"),
clearProxy: jest.fn(),
refetchProxyLatencies: jest.fn(),
proxyLatencies: {},
};

describe("NavbarView", () => {
const noop = () => {
return;
};
const noop = jest.fn();

it("workspaces nav link has the correct href", async () => {
renderWithAuth(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import type { Meta, StoryObj } from "@storybook/react";
import { expect, screen, userEvent, within, waitFor } from "@storybook/test";
import { MockBuildInfo, MockUser } from "testHelpers/entities";
import { UserDropdown } from "./UserDropdown";
import type { Meta, StoryObj } from "@storybook/react";

const meta: Meta<typeof UserDropdown> = {
title: "modules/dashboard/UserDropdown",
component: UserDropdown,
args: {
user: MockUser,
isDefaultOpen: true,
buildInfo: MockBuildInfo,
supportLinks: [
{ icon: "docs", name: "Documentation", target: "" },
Expand All @@ -21,6 +21,17 @@ const meta: Meta<typeof UserDropdown> = {
export default meta;
type Story = StoryObj<typeof UserDropdown>;

const Example: Story = {};
const Example: Story = {
play: async ({ canvasElement, step }) => {
const canvas = within(canvasElement);

await step("click to open", async () => {
await userEvent.click(canvas.getByRole("button"));
await waitFor(() =>
expect(screen.getByText(/v99\.999\.9999/i)).toBeInTheDocument(),
);
});
},
};

export { Example as UserDropdown };
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ export interface UserDropdownProps {
buildInfo?: TypesGen.BuildInfoResponse;
supportLinks?: TypesGen.LinkConfig[];
onSignOut: () => void;
isDefaultOpen?: boolean;
children?: ReactNode;
}

Expand All @@ -26,12 +25,11 @@ export const UserDropdown: FC<UserDropdownProps> = ({
user,
supportLinks,
onSignOut,
isDefaultOpen,
}) => {
const theme = useTheme();

return (
<Popover isDefaultOpen={isDefaultOpen}>
<Popover>
{(popover) => (
<>
<PopoverTrigger>
Expand Down