Skip to content

Commit 920b210

Browse files
committed
Use Storybook for non-redirect org settings tests
1 parent 7f520e7 commit 920b210

File tree

2 files changed

+67
-64
lines changed

2 files changed

+67
-64
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
import type { Meta, StoryObj } from "@storybook/react";
2+
import { reactRouterParameters } from "storybook-addon-remix-react-router";
3+
import { MockDefaultOrganization, MockUser } from "testHelpers/entities";
4+
import { withAuthProvider, withDashboardProvider } from "testHelpers/storybook";
5+
import OrganizationSettingsPage from "./OrganizationSettingsPage";
6+
7+
const meta: Meta<typeof OrganizationSettingsPage> = {
8+
title: "pages/OrganizationSettingsPage",
9+
component: OrganizationSettingsPage,
10+
decorators: [withAuthProvider, withDashboardProvider],
11+
parameters: {
12+
user: MockUser,
13+
permissions: { viewDeploymentValues: true },
14+
queries: [
15+
{
16+
key: ["organizations", [MockDefaultOrganization.id], "permissions"],
17+
data: {},
18+
},
19+
],
20+
},
21+
};
22+
23+
export default meta;
24+
type Story = StoryObj<typeof OrganizationSettingsPage>;
25+
26+
export const NoRedirectableOrganizations: Story = {};
27+
28+
export const OrganizationDoesNotExist: Story = {
29+
parameters: {
30+
reactRouter: reactRouterParameters({
31+
location: { pathParams: { organization: "does-not-exist" } },
32+
routing: { path: "/organizations/:organization" },
33+
}),
34+
},
35+
};
36+
37+
export const CannotEditOrganization: Story = {
38+
parameters: {
39+
reactRouter: reactRouterParameters({
40+
location: { pathParams: { organization: MockDefaultOrganization.name } },
41+
routing: { path: "/organizations/:organization" },
42+
}),
43+
},
44+
};
45+
46+
export const CanEditOrganization: Story = {
47+
parameters: {
48+
reactRouter: reactRouterParameters({
49+
location: { pathParams: { organization: MockDefaultOrganization.name } },
50+
routing: { path: "/organizations/:organization" },
51+
}),
52+
queries: [
53+
{
54+
key: ["organizations", [MockDefaultOrganization.id], "permissions"],
55+
data: {
56+
[MockDefaultOrganization.id]: {
57+
editOrganization: true,
58+
},
59+
},
60+
},
61+
],
62+
},
63+
};

site/src/pages/ManagementSettingsPage/OrganizationSettingsPage.test.tsx

+4-64
Original file line numberDiff line numberDiff line change
@@ -13,39 +13,15 @@ import OrganizationSettingsPage from "./OrganizationSettingsPage";
1313

1414
jest.spyOn(console, "error").mockImplementation(() => {});
1515

16-
const renderRootPage = async () => {
16+
const renderPage = async () => {
1717
renderWithManagementSettingsLayout(<OrganizationSettingsPage />, {
1818
route: "/organizations",
1919
path: "/organizations/:organization?",
2020
});
2121
await waitForLoaderToBeRemoved();
2222
};
2323

24-
const renderPage = async (orgName: string) => {
25-
renderWithManagementSettingsLayout(<OrganizationSettingsPage />, {
26-
route: `/organizations/${orgName}`,
27-
path: "/organizations/:organization",
28-
});
29-
await waitForLoaderToBeRemoved();
30-
};
31-
3224
describe("OrganizationSettingsPage", () => {
33-
it("has no organizations", async () => {
34-
server.use(
35-
http.get("/api/v2/organizations", () => {
36-
return HttpResponse.json([]);
37-
}),
38-
http.post("/api/v2/authcheck", async () => {
39-
return HttpResponse.json({
40-
[`${MockDefaultOrganization.id}.editOrganization`]: true,
41-
viewDeploymentValues: true,
42-
});
43-
}),
44-
);
45-
await renderRootPage();
46-
await screen.findByText("No organizations found");
47-
});
48-
4925
it("has no editable organizations", async () => {
5026
server.use(
5127
http.get("/api/v2/organizations", () => {
@@ -57,7 +33,7 @@ describe("OrganizationSettingsPage", () => {
5733
});
5834
}),
5935
);
60-
await renderRootPage();
36+
await renderPage();
6137
await screen.findByText("No organizations found");
6238
});
6339

@@ -75,7 +51,7 @@ describe("OrganizationSettingsPage", () => {
7551
});
7652
}),
7753
);
78-
await renderRootPage();
54+
await renderPage();
7955
const form = screen.getByTestId("org-settings-form");
8056
expect(within(form).getByRole("textbox", { name: "Name" })).toHaveValue(
8157
MockDefaultOrganization.name,
@@ -94,46 +70,10 @@ describe("OrganizationSettingsPage", () => {
9470
});
9571
}),
9672
);
97-
await renderRootPage();
73+
await renderPage();
9874
const form = screen.getByTestId("org-settings-form");
9975
expect(within(form).getByRole("textbox", { name: "Name" })).toHaveValue(
10076
MockOrganization2.name,
10177
);
10278
});
103-
104-
it("cannot find organization", async () => {
105-
server.use(
106-
http.get("/api/v2/organizations", () => {
107-
return HttpResponse.json([MockDefaultOrganization, MockOrganization2]);
108-
}),
109-
http.post("/api/v2/authcheck", async () => {
110-
return HttpResponse.json({
111-
[`${MockOrganization2.id}.editOrganization`]: true,
112-
viewDeploymentValues: true,
113-
});
114-
}),
115-
);
116-
await renderPage("the-endless-void");
117-
await screen.findByText("Organization not found");
118-
});
119-
120-
it("cannot edit organization", async () => {
121-
server.use(
122-
http.get("/api/v2/organizations", () => {
123-
return HttpResponse.json([MockDefaultOrganization]);
124-
}),
125-
http.post("/api/v2/authcheck", async () => {
126-
return HttpResponse.json({
127-
viewDeploymentValues: true,
128-
});
129-
}),
130-
);
131-
// No form since they cannot edit, instead sees the summary view.
132-
await renderPage(MockDefaultOrganization.name);
133-
expect(screen.queryByTestId("org-settings-form")).not.toBeInTheDocument();
134-
await screen.findByRole("heading", {
135-
level: 1,
136-
name: MockDefaultOrganization.display_name,
137-
});
138-
});
13979
});

0 commit comments

Comments
 (0)