Skip to content

feat: show summary if unable to edit org #14214

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 3 commits into from
Aug 9, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Use Storybook for non-redirect org settings tests
  • Loading branch information
code-asher committed Aug 9, 2024
commit 920b21060b3300a07b1694848bb6be54cc39b46a
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
import type { Meta, StoryObj } from "@storybook/react";
import { reactRouterParameters } from "storybook-addon-remix-react-router";
import { MockDefaultOrganization, MockUser } from "testHelpers/entities";
import { withAuthProvider, withDashboardProvider } from "testHelpers/storybook";
import OrganizationSettingsPage from "./OrganizationSettingsPage";

const meta: Meta<typeof OrganizationSettingsPage> = {
title: "pages/OrganizationSettingsPage",
component: OrganizationSettingsPage,
decorators: [withAuthProvider, withDashboardProvider],
parameters: {
user: MockUser,
permissions: { viewDeploymentValues: true },
queries: [
{
key: ["organizations", [MockDefaultOrganization.id], "permissions"],
data: {},
},
],
},
};

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

export const NoRedirectableOrganizations: Story = {};

export const OrganizationDoesNotExist: Story = {
parameters: {
reactRouter: reactRouterParameters({
location: { pathParams: { organization: "does-not-exist" } },
routing: { path: "/organizations/:organization" },
}),
},
};

export const CannotEditOrganization: Story = {
parameters: {
reactRouter: reactRouterParameters({
location: { pathParams: { organization: MockDefaultOrganization.name } },
routing: { path: "/organizations/:organization" },
}),
},
};

export const CanEditOrganization: Story = {
parameters: {
reactRouter: reactRouterParameters({
location: { pathParams: { organization: MockDefaultOrganization.name } },
routing: { path: "/organizations/:organization" },
}),
queries: [
{
key: ["organizations", [MockDefaultOrganization.id], "permissions"],
data: {
[MockDefaultOrganization.id]: {
editOrganization: true,
},
},
},
],
},
};
Original file line number Diff line number Diff line change
Expand Up @@ -13,39 +13,15 @@ import OrganizationSettingsPage from "./OrganizationSettingsPage";

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

const renderRootPage = async () => {
const renderPage = async () => {
renderWithManagementSettingsLayout(<OrganizationSettingsPage />, {
route: "/organizations",
path: "/organizations/:organization?",
});
await waitForLoaderToBeRemoved();
};

const renderPage = async (orgName: string) => {
renderWithManagementSettingsLayout(<OrganizationSettingsPage />, {
route: `/organizations/${orgName}`,
path: "/organizations/:organization",
});
await waitForLoaderToBeRemoved();
};

describe("OrganizationSettingsPage", () => {
it("has no organizations", async () => {
server.use(
http.get("/api/v2/organizations", () => {
return HttpResponse.json([]);
}),
http.post("/api/v2/authcheck", async () => {
return HttpResponse.json({
[`${MockDefaultOrganization.id}.editOrganization`]: true,
viewDeploymentValues: true,
});
}),
);
await renderRootPage();
await screen.findByText("No organizations found");
});

it("has no editable organizations", async () => {
server.use(
http.get("/api/v2/organizations", () => {
Expand All @@ -57,7 +33,7 @@ describe("OrganizationSettingsPage", () => {
});
}),
);
await renderRootPage();
await renderPage();
await screen.findByText("No organizations found");
});

Expand All @@ -75,7 +51,7 @@ describe("OrganizationSettingsPage", () => {
});
}),
);
await renderRootPage();
await renderPage();
const form = screen.getByTestId("org-settings-form");
expect(within(form).getByRole("textbox", { name: "Name" })).toHaveValue(
MockDefaultOrganization.name,
Expand All @@ -94,46 +70,10 @@ describe("OrganizationSettingsPage", () => {
});
}),
);
await renderRootPage();
await renderPage();
const form = screen.getByTestId("org-settings-form");
expect(within(form).getByRole("textbox", { name: "Name" })).toHaveValue(
MockOrganization2.name,
);
});

it("cannot find organization", async () => {
server.use(
http.get("/api/v2/organizations", () => {
return HttpResponse.json([MockDefaultOrganization, MockOrganization2]);
}),
http.post("/api/v2/authcheck", async () => {
return HttpResponse.json({
[`${MockOrganization2.id}.editOrganization`]: true,
viewDeploymentValues: true,
});
}),
);
await renderPage("the-endless-void");
await screen.findByText("Organization not found");
});

it("cannot edit organization", async () => {
server.use(
http.get("/api/v2/organizations", () => {
return HttpResponse.json([MockDefaultOrganization]);
}),
http.post("/api/v2/authcheck", async () => {
return HttpResponse.json({
viewDeploymentValues: true,
});
}),
);
// No form since they cannot edit, instead sees the summary view.
await renderPage(MockDefaultOrganization.name);
expect(screen.queryByTestId("org-settings-form")).not.toBeInTheDocument();
await screen.findByRole("heading", {
level: 1,
name: MockDefaultOrganization.display_name,
});
});
});
Loading