Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit af4d0b1

Browse files
authored
chore: add stories for Popover (#12387)
1 parent 722ff50 commit af4d0b1

File tree

4 files changed

+74
-11
lines changed

4 files changed

+74
-11
lines changed
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
import Button from "@mui/material/Button";
2+
import type { Meta, StoryObj } from "@storybook/react";
3+
import { expect, screen, userEvent, within, waitFor } from "@storybook/test";
4+
import { Popover, PopoverTrigger, PopoverContent } from "./Popover";
5+
6+
const meta: Meta<typeof Popover> = {
7+
title: "components/Popover",
8+
component: Popover,
9+
};
10+
11+
export default meta;
12+
type Story = StoryObj<typeof Popover>;
13+
14+
const content = `
15+
According to all known laws of aviation, there is no way a bee should be able to fly.
16+
Its wings are too small to get its fat little body off the ground. The bee, of course,
17+
flies anyway because bees don't care what humans think is impossible.
18+
`;
19+
20+
export const Example: Story = {
21+
args: {
22+
children: (
23+
<>
24+
<PopoverTrigger>
25+
<Button>Click here!</Button>
26+
</PopoverTrigger>
27+
<PopoverContent>{content}</PopoverContent>
28+
</>
29+
),
30+
},
31+
play: async ({ canvasElement, step }) => {
32+
const canvas = within(canvasElement);
33+
34+
await step("click to open", async () => {
35+
await userEvent.click(canvas.getByRole("button"));
36+
await waitFor(() =>
37+
expect(
38+
screen.getByText(/according to all known laws/i),
39+
).toBeInTheDocument(),
40+
);
41+
});
42+
},
43+
};
44+
45+
export const Horizontal: Story = {
46+
args: {
47+
children: (
48+
<>
49+
<PopoverTrigger>
50+
<Button>Click here!</Button>
51+
</PopoverTrigger>
52+
<PopoverContent horizontal="right">{content}</PopoverContent>
53+
</>
54+
),
55+
},
56+
play: Example.play,
57+
};

site/src/modules/dashboard/Navbar/NavbarView.test.tsx

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ import { MockPrimaryWorkspaceProxy, MockUser } from "testHelpers/entities";
33
import { renderWithAuth } from "testHelpers/renderHelpers";
44
import { Language as navLanguage, NavbarView } from "./NavbarView";
55
import { ProxyContextValue } from "contexts/ProxyContext";
6-
import { action } from "@storybook/addon-actions";
76

87
const proxyContextValue: ProxyContextValue = {
98
proxy: {
@@ -14,15 +13,13 @@ const proxyContextValue: ProxyContextValue = {
1413
isLoading: false,
1514
isFetched: true,
1615
setProxy: jest.fn(),
17-
clearProxy: action("clearProxy"),
16+
clearProxy: jest.fn(),
1817
refetchProxyLatencies: jest.fn(),
1918
proxyLatencies: {},
2019
};
2120

2221
describe("NavbarView", () => {
23-
const noop = () => {
24-
return;
25-
};
22+
const noop = jest.fn();
2623

2724
it("workspaces nav link has the correct href", async () => {
2825
renderWithAuth(

site/src/modules/dashboard/Navbar/UserDropdown/UserDropdown.stories.tsx

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
1+
import type { Meta, StoryObj } from "@storybook/react";
2+
import { expect, screen, userEvent, within, waitFor } from "@storybook/test";
13
import { MockBuildInfo, MockUser } from "testHelpers/entities";
24
import { UserDropdown } from "./UserDropdown";
3-
import type { Meta, StoryObj } from "@storybook/react";
45

56
const meta: Meta<typeof UserDropdown> = {
67
title: "modules/dashboard/UserDropdown",
78
component: UserDropdown,
89
args: {
910
user: MockUser,
10-
isDefaultOpen: true,
1111
buildInfo: MockBuildInfo,
1212
supportLinks: [
1313
{ icon: "docs", name: "Documentation", target: "" },
@@ -21,6 +21,17 @@ const meta: Meta<typeof UserDropdown> = {
2121
export default meta;
2222
type Story = StoryObj<typeof UserDropdown>;
2323

24-
const Example: Story = {};
24+
const Example: Story = {
25+
play: async ({ canvasElement, step }) => {
26+
const canvas = within(canvasElement);
27+
28+
await step("click to open", async () => {
29+
await userEvent.click(canvas.getByRole("button"));
30+
await waitFor(() =>
31+
expect(screen.getByText(/v99\.999\.9999/i)).toBeInTheDocument(),
32+
);
33+
});
34+
},
35+
};
2536

2637
export { Example as UserDropdown };

site/src/modules/dashboard/Navbar/UserDropdown/UserDropdown.tsx

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ export interface UserDropdownProps {
1717
buildInfo?: TypesGen.BuildInfoResponse;
1818
supportLinks?: TypesGen.LinkConfig[];
1919
onSignOut: () => void;
20-
isDefaultOpen?: boolean;
2120
children?: ReactNode;
2221
}
2322

@@ -26,12 +25,11 @@ export const UserDropdown: FC<UserDropdownProps> = ({
2625
user,
2726
supportLinks,
2827
onSignOut,
29-
isDefaultOpen,
3028
}) => {
3129
const theme = useTheme();
3230

3331
return (
34-
<Popover isDefaultOpen={isDefaultOpen}>
32+
<Popover>
3533
{(popover) => (
3634
<>
3735
<PopoverTrigger>

0 commit comments

Comments
 (0)