Skip to content

Commit ea3b13c

Browse files
authored
chore: storybook additions and cleanup (coder#14968)
1 parent 7d281c3 commit ea3b13c

File tree

3 files changed

+71
-46
lines changed

3 files changed

+71
-46
lines changed

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

+50-21
Original file line numberDiff line numberDiff line change
@@ -29,52 +29,81 @@ export const Default: Story = {
2929

3030
export const CheckboxIndeterminate: Story = {
3131
args: {
32+
...Default.args,
3233
role: assignableRole(MockRole2WithOrgPermissions, true),
33-
onSubmit: () => null,
34-
isLoading: false,
35-
organizationName: "my-org",
36-
canAssignOrgRole: true,
3734
},
3835
};
3936

4037
export const WithError: Story = {
4138
args: {
42-
role: assignableRole(MockRoleWithOrgPermissions, true),
43-
onSubmit: () => null,
39+
...Default.args,
40+
role: undefined,
41+
error: "this is an error",
42+
},
43+
};
44+
45+
export const WithValidationError: Story = {
46+
args: {
47+
...Default.args,
48+
role: undefined,
4449
error: mockApiError({
4550
message: "A role named new-role already exists.",
4651
validations: [{ field: "name", detail: "Role names must be unique" }],
4752
}),
48-
isLoading: false,
49-
organizationName: "my-org",
50-
canAssignOrgRole: true,
53+
},
54+
play: async ({ canvasElement, step }) => {
55+
const canvas = within(canvasElement);
56+
57+
await step("Enter name", async () => {
58+
const input = canvas.getByLabelText("Name");
59+
await userEvent.type(input, "new-role");
60+
input.blur();
61+
});
5162
},
5263
};
5364

54-
export const CannotEdit: Story = {
65+
export const InvalidCharsError: Story = {
5566
args: {
56-
role: assignableRole(MockRoleWithOrgPermissions, true),
57-
onSubmit: () => null,
58-
error: undefined,
59-
isLoading: false,
60-
organizationName: "my-org",
67+
...Default.args,
68+
role: undefined,
69+
},
70+
play: async ({ canvasElement, step }) => {
71+
const canvas = within(canvasElement);
72+
73+
await step("Enter name", async () => {
74+
const input = canvas.getByLabelText("Name");
75+
await userEvent.type(input, "!~@#@!");
76+
input.blur();
77+
});
78+
},
79+
};
80+
81+
export const CannotEditRoleName: Story = {
82+
args: {
83+
...Default.args,
6184
canAssignOrgRole: false,
6285
},
6386
};
6487

6588
export const ShowAllResources: Story = {
6689
args: {
67-
role: assignableRole(MockRoleWithOrgPermissions, true),
68-
onSubmit: () => null,
69-
error: undefined,
70-
isLoading: false,
71-
organizationName: "my-org",
72-
canAssignOrgRole: true,
90+
...Default.args,
7391
allResources: true,
7492
},
7593
};
7694

95+
export const Loading: Story = {
96+
args: {
97+
...Default.args,
98+
isLoading: true,
99+
},
100+
};
101+
77102
export const ToggleParentCheckbox: Story = {
103+
args: {
104+
...Default.args,
105+
role: undefined,
106+
},
78107
play: async ({ canvasElement }) => {
79108
const user = userEvent.setup();
80109
const canvas = within(canvasElement);

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

-6
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,3 @@ export const HoverOverflowPill: Story = {
4444
await userEvent.hover(canvas.getByTestId("overflow-permissions-pill"));
4545
},
4646
};
47-
48-
export const ShowAllResources: Story = {
49-
args: {
50-
permissions: MockRoleWithOrgPermissions.organization_permissions,
51-
},
52-
};

site/src/pages/ManagementSettingsPage/IdpSyncPage/IdpSyncPageView.stories.tsx

+21-19
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import type { Meta, StoryObj } from "@storybook/react";
2+
import { expect, userEvent, within } from "@storybook/test";
23
import {
34
MockGroup,
45
MockGroup2,
@@ -43,46 +44,47 @@ export const Empty: Story = {
4344
},
4445
};
4546

46-
export const HasError: Story = {
47+
export const Default: Story = {
4748
args: {
4849
groupSyncSettings: MockGroupSyncSettings,
4950
roleSyncSettings: MockRoleSyncSettings,
5051
groups: [MockGroup, MockGroup2],
5152
groupsMap,
5253
organization: MockOrganization,
53-
error: "This is a test error",
54+
error: undefined,
5455
},
5556
};
5657

57-
export const Default: Story = {
58+
export const HasError: Story = {
5859
args: {
59-
groupSyncSettings: MockGroupSyncSettings,
60-
roleSyncSettings: MockRoleSyncSettings,
61-
groups: [MockGroup, MockGroup2],
62-
groupsMap,
63-
organization: MockOrganization,
64-
error: undefined,
60+
...Default.args,
61+
error: "This is a test error",
6562
},
6663
};
6764

6865
export const MissingGroups: Story = {
6966
args: {
67+
...Default.args,
7068
groupSyncSettings: MockGroupSyncSettings2,
71-
roleSyncSettings: MockRoleSyncSettings,
72-
groups: [MockGroup, MockGroup2],
73-
groupsMap,
74-
organization: MockOrganization,
75-
error: undefined,
7669
},
7770
};
7871

7972
export const WithLegacyMapping: Story = {
8073
args: {
74+
...Default.args,
8175
groupSyncSettings: MockLegacyMappingGroupSyncSettings,
82-
roleSyncSettings: MockRoleSyncSettings,
83-
groups: [MockGroup, MockGroup2],
84-
groupsMap,
85-
organization: MockOrganization,
86-
error: undefined,
76+
},
77+
};
78+
79+
export const RolesTab: Story = {
80+
args: {
81+
...Default.args,
82+
},
83+
play: async ({ canvasElement }) => {
84+
const user = userEvent.setup();
85+
const canvas = within(canvasElement);
86+
const rolesTab = await canvas.findByText("Role Sync Settings");
87+
await user.click(rolesTab);
88+
await expect(canvas.findByText("IdP Role")).resolves.toBeVisible();
8789
},
8890
};

0 commit comments

Comments
 (0)