Skip to content

Commit 0ecf024

Browse files
committed
chore: add additional tests
1 parent 31b89e4 commit 0ecf024

File tree

3 files changed

+43
-1
lines changed

3 files changed

+43
-1
lines changed

site/src/pages/ManagementSettingsPage/CustomRolesPage/CreateEditRolePageView.stories.tsx

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
import type { Meta, StoryObj } from "@storybook/react";
22
import {
33
MockRoleWithOrgPermissions,
4+
MockRole2WithOrgPermissions,
45
assignableRole,
56
mockApiError,
67
} from "testHelpers/entities";
78
import { CreateEditRolePageView } from "./CreateEditRolePageView";
9+
import { userEvent, within, expect } from "@storybook/test";
810

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

30+
export const CheckboxIndeterminate: Story = {
31+
args: {
32+
role: assignableRole(MockRole2WithOrgPermissions, true),
33+
onSubmit: () => null,
34+
isLoading: false,
35+
organizationName: "my-org",
36+
canAssignOrgRole: true,
37+
},
38+
};
39+
2840
export const WithError: Story = {
2941
args: {
3042
role: assignableRole(MockRoleWithOrgPermissions, true),
@@ -61,3 +73,17 @@ export const ShowAllResources: Story = {
6173
allResources: true,
6274
},
6375
};
76+
77+
export const ToggleParentCheckbox: Story = {
78+
play: async ({ canvasElement }) => {
79+
const user = userEvent.setup();
80+
const canvas = within(canvasElement);
81+
const checkbox = await canvas
82+
.getByTestId("audit_log")
83+
.getElementsByTagName("input")[0];
84+
await user.click(checkbox);
85+
await expect(checkbox).toBeChecked();
86+
await user.click(checkbox);
87+
await expect(checkbox).not.toBeChecked();
88+
},
89+
};

site/src/pages/ManagementSettingsPage/CustomRolesPage/CreateEditRolePageView.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -334,6 +334,7 @@ const PermissionCheckboxGroup: FC<PermissionCheckboxGroupProps> = ({
334334
checkedActions.length > 0 &&
335335
checkedActions.length < Object.keys(value).length
336336
}
337+
data-testid={`${resourceKey}`}
337338
onChange={(e) =>
338339
handleResourceCheckChange(
339340
e,
@@ -416,7 +417,7 @@ const styles = {
416417
}),
417418
actionItem: {
418419
display: "grid",
419-
gridTemplateColumns: "270px 3fr",
420+
gridTemplateColumns: "270px 1fr",
420421
},
421422
} satisfies Record<string, Interpolation<Theme>>;
422423

site/src/testHelpers/entities.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -391,6 +391,21 @@ export const MockRoleWithOrgPermissions: TypesGen.Role = {
391391
user_permissions: [],
392392
};
393393

394+
export const MockRole2WithOrgPermissions: TypesGen.Role = {
395+
name: "my-role-1",
396+
display_name: "My Role 1",
397+
organization_id: MockOrganization.id,
398+
site_permissions: [],
399+
organization_permissions: [
400+
{
401+
negate: false,
402+
resource_type: "audit_log",
403+
action: "create",
404+
},
405+
],
406+
user_permissions: [],
407+
};
408+
394409
// assignableRole takes a role and a boolean. The boolean implies if the
395410
// actor can assign (add/remove) the role from other users.
396411
export function assignableRole(

0 commit comments

Comments
 (0)