|
1 | 1 | import type { Meta, StoryObj } from "@storybook/react-vite"; |
| 2 | +import { action } from "storybook/actions"; |
| 3 | +import { expect, userEvent, within } from "storybook/test"; |
| 4 | +import type { AssignableRoles } from "#/api/typesGenerated"; |
2 | 5 | import { |
| 6 | + MockOrganization, |
3 | 7 | MockOrganizationAuditorRole, |
4 | 8 | MockRoleWithOrgPermissions, |
5 | 9 | } from "#/testHelpers/entities"; |
6 | 10 | import { CustomRolesPageView } from "./CustomRolesPageView"; |
7 | 11 |
|
| 12 | +const mockOrgRoles: AssignableRoles[] = [ |
| 13 | + { |
| 14 | + name: "organization-workspace-access", |
| 15 | + display_name: "Organization Workspace Access", |
| 16 | + organization_id: MockOrganization.id, |
| 17 | + site_permissions: [], |
| 18 | + organization_permissions: [], |
| 19 | + organization_member_permissions: [], |
| 20 | + user_permissions: [], |
| 21 | + assignable: true, |
| 22 | + built_in: true, |
| 23 | + }, |
| 24 | + { |
| 25 | + name: "organization-admin", |
| 26 | + display_name: "Organization Admin", |
| 27 | + organization_id: MockOrganization.id, |
| 28 | + site_permissions: [], |
| 29 | + organization_permissions: [], |
| 30 | + organization_member_permissions: [], |
| 31 | + user_permissions: [], |
| 32 | + assignable: true, |
| 33 | + built_in: true, |
| 34 | + }, |
| 35 | + { |
| 36 | + name: "agents-access", |
| 37 | + display_name: "Agents Access", |
| 38 | + organization_id: MockOrganization.id, |
| 39 | + site_permissions: [], |
| 40 | + organization_permissions: [], |
| 41 | + organization_member_permissions: [], |
| 42 | + user_permissions: [], |
| 43 | + assignable: true, |
| 44 | + built_in: true, |
| 45 | + }, |
| 46 | +]; |
| 47 | + |
8 | 48 | const meta: Meta<typeof CustomRolesPageView> = { |
9 | 49 | title: "pages/OrganizationCustomRolesPage", |
10 | 50 | component: CustomRolesPageView, |
11 | 51 | args: { |
| 52 | + organization: MockOrganization, |
12 | 53 | builtInRoles: [MockRoleWithOrgPermissions], |
13 | 54 | customRoles: [MockRoleWithOrgPermissions], |
14 | 55 | canCreateOrgRole: true, |
| 56 | + canEditDefaultRoles: true, |
15 | 57 | isCustomRolesEnabled: true, |
16 | 58 | }, |
17 | 59 | }; |
@@ -66,3 +108,98 @@ export const EmptyTableUserWithPermission: Story = { |
66 | 108 | customRoles: [], |
67 | 109 | }, |
68 | 110 | }; |
| 111 | + |
| 112 | +export const DefaultRolesHidden: Story = { |
| 113 | + args: { |
| 114 | + defaultRolesEnabled: false, |
| 115 | + availableOrgRoles: mockOrgRoles, |
| 116 | + onUpdateDefaultRoles: async () => { |
| 117 | + action("onUpdateDefaultRoles")(); |
| 118 | + }, |
| 119 | + }, |
| 120 | + play: async ({ canvasElement }) => { |
| 121 | + const body = within(canvasElement.ownerDocument.body); |
| 122 | + expect(body.queryByText("Default Roles")).toBeNull(); |
| 123 | + }, |
| 124 | +}; |
| 125 | + |
| 126 | +export const DefaultRolesEnabled: Story = { |
| 127 | + args: { |
| 128 | + defaultRolesEnabled: true, |
| 129 | + defaultRolesEntitled: true, |
| 130 | + availableOrgRoles: mockOrgRoles, |
| 131 | + onUpdateDefaultRoles: async () => { |
| 132 | + action("onUpdateDefaultRoles")(); |
| 133 | + }, |
| 134 | + }, |
| 135 | +}; |
| 136 | + |
| 137 | +export const DefaultRolesNotEntitled: Story = { |
| 138 | + args: { |
| 139 | + defaultRolesEnabled: true, |
| 140 | + defaultRolesEntitled: false, |
| 141 | + availableOrgRoles: mockOrgRoles, |
| 142 | + onUpdateDefaultRoles: async () => { |
| 143 | + action("onUpdateDefaultRoles")(); |
| 144 | + }, |
| 145 | + }, |
| 146 | + play: async ({ canvasElement }) => { |
| 147 | + const body = within(canvasElement.ownerDocument.body); |
| 148 | + const editButton = await body.findByRole("button", { |
| 149 | + name: /edit default roles/i, |
| 150 | + }); |
| 151 | + expect(editButton).toBeDisabled(); |
| 152 | + await body.findByText(/requires a Premium license/i); |
| 153 | + }, |
| 154 | +}; |
| 155 | + |
| 156 | +export const DefaultRolesEmpty: Story = { |
| 157 | + args: { |
| 158 | + organization: { |
| 159 | + ...MockOrganization, |
| 160 | + default_org_member_roles: [], |
| 161 | + }, |
| 162 | + defaultRolesEnabled: true, |
| 163 | + defaultRolesEntitled: true, |
| 164 | + availableOrgRoles: mockOrgRoles, |
| 165 | + onUpdateDefaultRoles: async () => { |
| 166 | + action("onUpdateDefaultRoles")(); |
| 167 | + }, |
| 168 | + }, |
| 169 | +}; |
| 170 | + |
| 171 | +export const DefaultRolesHiddenWithoutEditPermission: Story = { |
| 172 | + args: { |
| 173 | + defaultRolesEnabled: true, |
| 174 | + defaultRolesEntitled: true, |
| 175 | + canEditDefaultRoles: false, |
| 176 | + availableOrgRoles: mockOrgRoles, |
| 177 | + onUpdateDefaultRoles: async () => { |
| 178 | + action("onUpdateDefaultRoles")(); |
| 179 | + }, |
| 180 | + }, |
| 181 | + play: async ({ canvasElement }) => { |
| 182 | + const body = within(canvasElement.ownerDocument.body); |
| 183 | + expect(body.queryByText("Default Roles")).toBeNull(); |
| 184 | + }, |
| 185 | +}; |
| 186 | + |
| 187 | +export const DefaultRolesEditDialog: Story = { |
| 188 | + args: { |
| 189 | + defaultRolesEnabled: true, |
| 190 | + defaultRolesEntitled: true, |
| 191 | + availableOrgRoles: mockOrgRoles, |
| 192 | + onUpdateDefaultRoles: async () => { |
| 193 | + action("onUpdateDefaultRoles")(); |
| 194 | + }, |
| 195 | + }, |
| 196 | + play: async ({ canvasElement }) => { |
| 197 | + const user = userEvent.setup(); |
| 198 | + const body = within(canvasElement.ownerDocument.body); |
| 199 | + const editButton = await body.findByRole("button", { |
| 200 | + name: /edit default roles/i, |
| 201 | + }); |
| 202 | + await user.click(editButton); |
| 203 | + await body.findByRole("heading", { name: /edit default roles/i }); |
| 204 | + }, |
| 205 | +}; |
0 commit comments