Skip to content

feat: improve custom roles create/edit page #14456

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 5 commits into from
Aug 28, 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
Next Next commit
chore: add additional tests
  • Loading branch information
jaaydenh committed Aug 28, 2024
commit 0ecf02421f494ce367515ff640ed7e23c2743677
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import type { Meta, StoryObj } from "@storybook/react";
import {
MockRoleWithOrgPermissions,
MockRole2WithOrgPermissions,
assignableRole,
mockApiError,
} from "testHelpers/entities";
import { CreateEditRolePageView } from "./CreateEditRolePageView";
import { userEvent, within, expect } from "@storybook/test";

const meta: Meta<typeof CreateEditRolePageView> = {
title: "pages/OrganizationCreateEditRolePage",
Expand All @@ -25,6 +27,16 @@ export const Default: Story = {
},
};

export const CheckboxIndeterminate: Story = {
args: {
role: assignableRole(MockRole2WithOrgPermissions, true),
onSubmit: () => null,
isLoading: false,
organizationName: "my-org",
canAssignOrgRole: true,
},
};

export const WithError: Story = {
args: {
role: assignableRole(MockRoleWithOrgPermissions, true),
Expand Down Expand Up @@ -61,3 +73,17 @@ export const ShowAllResources: Story = {
allResources: true,
},
};

export const ToggleParentCheckbox: Story = {
play: async ({ canvasElement }) => {
const user = userEvent.setup();
const canvas = within(canvasElement);
const checkbox = await canvas
.getByTestId("audit_log")
.getElementsByTagName("input")[0];
await user.click(checkbox);
await expect(checkbox).toBeChecked();
await user.click(checkbox);
await expect(checkbox).not.toBeChecked();
},
};
Original file line number Diff line number Diff line change
Expand Up @@ -334,6 +334,7 @@ const PermissionCheckboxGroup: FC<PermissionCheckboxGroupProps> = ({
checkedActions.length > 0 &&
checkedActions.length < Object.keys(value).length
}
data-testid={`${resourceKey}`}
onChange={(e) =>
handleResourceCheckChange(
e,
Expand Down Expand Up @@ -416,7 +417,7 @@ const styles = {
}),
actionItem: {
display: "grid",
gridTemplateColumns: "270px 3fr",
gridTemplateColumns: "270px 1fr",
},
} satisfies Record<string, Interpolation<Theme>>;

Expand Down
15 changes: 15 additions & 0 deletions site/src/testHelpers/entities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -391,6 +391,21 @@ export const MockRoleWithOrgPermissions: TypesGen.Role = {
user_permissions: [],
};

export const MockRole2WithOrgPermissions: TypesGen.Role = {
name: "my-role-1",
display_name: "My Role 1",
organization_id: MockOrganization.id,
site_permissions: [],
organization_permissions: [
{
negate: false,
resource_type: "audit_log",
action: "create",
},
],
user_permissions: [],
};

// assignableRole takes a role and a boolean. The boolean implies if the
// actor can assign (add/remove) the role from other users.
export function assignableRole(
Expand Down
Loading