diff --git a/site/src/components/Popover/Popover.stories.tsx b/site/src/components/Popover/Popover.stories.tsx new file mode 100644 index 0000000000000..b3750f34bf4eb --- /dev/null +++ b/site/src/components/Popover/Popover.stories.tsx @@ -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 = { + title: "components/Popover", + component: Popover, +}; + +export default meta; +type Story = StoryObj; + +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: ( + <> + + + + {content} + + ), + }, + 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: ( + <> + + + + {content} + + ), + }, + play: Example.play, +}; diff --git a/site/src/modules/dashboard/Navbar/NavbarView.test.tsx b/site/src/modules/dashboard/Navbar/NavbarView.test.tsx index 9a4dfda63360c..a6eae936e3258 100644 --- a/site/src/modules/dashboard/Navbar/NavbarView.test.tsx +++ b/site/src/modules/dashboard/Navbar/NavbarView.test.tsx @@ -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: { @@ -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( diff --git a/site/src/modules/dashboard/Navbar/UserDropdown/UserDropdown.stories.tsx b/site/src/modules/dashboard/Navbar/UserDropdown/UserDropdown.stories.tsx index 9e25a272e32ae..04e18fc3d49f0 100644 --- a/site/src/modules/dashboard/Navbar/UserDropdown/UserDropdown.stories.tsx +++ b/site/src/modules/dashboard/Navbar/UserDropdown/UserDropdown.stories.tsx @@ -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 = { title: "modules/dashboard/UserDropdown", component: UserDropdown, args: { user: MockUser, - isDefaultOpen: true, buildInfo: MockBuildInfo, supportLinks: [ { icon: "docs", name: "Documentation", target: "" }, @@ -21,6 +21,17 @@ const meta: Meta = { export default meta; type Story = StoryObj; -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 }; diff --git a/site/src/modules/dashboard/Navbar/UserDropdown/UserDropdown.tsx b/site/src/modules/dashboard/Navbar/UserDropdown/UserDropdown.tsx index 443a0655b9c96..f2b45448f8a3b 100644 --- a/site/src/modules/dashboard/Navbar/UserDropdown/UserDropdown.tsx +++ b/site/src/modules/dashboard/Navbar/UserDropdown/UserDropdown.tsx @@ -17,7 +17,6 @@ export interface UserDropdownProps { buildInfo?: TypesGen.BuildInfoResponse; supportLinks?: TypesGen.LinkConfig[]; onSignOut: () => void; - isDefaultOpen?: boolean; children?: ReactNode; } @@ -26,12 +25,11 @@ export const UserDropdown: FC = ({ user, supportLinks, onSignOut, - isDefaultOpen, }) => { const theme = useTheme(); return ( - + {(popover) => ( <>