Skip to content

Commit 52fae61

Browse files
committed
Refactor AuditPage
1 parent 9e5a59e commit 52fae61

File tree

6 files changed

+130
-178
lines changed

6 files changed

+130
-178
lines changed
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
import type { Meta, StoryObj } from "@storybook/react";
2+
import { AuditLogDescription } from "./AuditLogDescription";
3+
import {
4+
MockAuditLog,
5+
MockAuditLogSuccessfulLogin,
6+
MockAuditLogUnsuccessfulLoginKnownUser,
7+
MockAuditLogWithWorkspaceBuild,
8+
MockWorkspaceCreateAuditLogForDifferentOwner,
9+
} from "testHelpers/entities";
10+
11+
const meta: Meta<typeof AuditLogDescription> = {
12+
title: "components/AuditLogDescription",
13+
component: AuditLogDescription,
14+
};
15+
16+
export default meta;
17+
type Story = StoryObj<typeof AuditLogDescription>;
18+
19+
export const WorkspaceCreate: Story = {
20+
args: {
21+
auditLog: MockAuditLog,
22+
},
23+
};
24+
25+
export const WorkspaceBuildStop: Story = {
26+
args: {
27+
auditLog: MockAuditLogWithWorkspaceBuild,
28+
},
29+
};
30+
31+
export const WorkspaceBuildDuplicatedWord: Story = {
32+
args: {
33+
auditLog: {
34+
...MockAuditLogWithWorkspaceBuild,
35+
additional_fields: {
36+
workspace_name: "workspace",
37+
},
38+
},
39+
},
40+
};
41+
42+
export const CreateWorkspaceWithDiffOwner: Story = {
43+
args: {
44+
auditLog: MockWorkspaceCreateAuditLogForDifferentOwner,
45+
},
46+
};
47+
48+
export const SuccessLogin: Story = {
49+
args: {
50+
auditLog: MockAuditLogSuccessfulLogin,
51+
},
52+
};
53+
54+
export const UnsuccessfulLoginForUnkownUser: Story = {
55+
args: {
56+
auditLog: MockAuditLogUnsuccessfulLoginKnownUser,
57+
},
58+
};

site/src/pages/AuditPage/AuditLogRow/AuditLogDescription/AuditLogDescription.test.tsx

Lines changed: 0 additions & 106 deletions
This file was deleted.

site/src/pages/AuditPage/AuditLogRow/AuditLogDescription/index.ts

Lines changed: 0 additions & 1 deletion
This file was deleted.

site/src/pages/AuditPage/AuditLogRow/AuditLogDiff/index.ts

Lines changed: 0 additions & 2 deletions
This file was deleted.

site/src/pages/AuditPage/AuditLogRow/AuditLogRow.stories.tsx

Lines changed: 72 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -4,97 +4,109 @@ import TableCell from "@mui/material/TableCell";
44
import TableContainer from "@mui/material/TableContainer";
55
import TableHead from "@mui/material/TableHead";
66
import TableRow from "@mui/material/TableRow";
7-
import { ComponentMeta, Story } from "@storybook/react";
87
import {
98
MockAuditLog,
109
MockAuditLog2,
1110
MockAuditLogWithWorkspaceBuild,
1211
MockAuditLogWithDeletedResource,
1312
MockAuditLogGitSSH,
1413
} from "testHelpers/entities";
15-
import { AuditLogRow, AuditLogRowProps } from "./AuditLogRow";
14+
import { AuditLogRow } from "./AuditLogRow";
15+
import type { Meta, StoryObj } from "@storybook/react";
1616

17-
export default {
17+
const meta: Meta<typeof AuditLogRow> = {
1818
title: "components/AuditLogRow",
1919
component: AuditLogRow,
20-
} as ComponentMeta<typeof AuditLogRow>;
20+
decorators: [
21+
(Story) => (
22+
<TableContainer>
23+
<Table>
24+
<TableHead>
25+
<TableRow>
26+
<TableCell style={{ paddingLeft: 32 }}>Logs</TableCell>
27+
</TableRow>
28+
</TableHead>
29+
<TableBody>
30+
<Story />
31+
</TableBody>
32+
</Table>
33+
</TableContainer>
34+
),
35+
],
36+
};
2137

22-
const Template: Story<AuditLogRowProps> = (args) => (
23-
<TableContainer>
24-
<Table>
25-
<TableHead>
26-
<TableRow>
27-
<TableCell style={{ paddingLeft: 32 }}>Logs</TableCell>
28-
</TableRow>
29-
</TableHead>
30-
<TableBody>
31-
<AuditLogRow {...args} />
32-
</TableBody>
33-
</Table>
34-
</TableContainer>
35-
);
38+
export default meta;
39+
type Story = StoryObj<typeof AuditLogRow>;
3640

37-
export const NoDiff = Template.bind({});
38-
NoDiff.args = {
39-
auditLog: {
40-
...MockAuditLog,
41-
diff: {},
41+
export const NoDiff: Story = {
42+
args: {
43+
auditLog: {
44+
...MockAuditLog,
45+
diff: {},
46+
},
4247
},
4348
};
4449

45-
export const WithDiff = Template.bind({});
46-
WithDiff.args = {
47-
auditLog: MockAuditLog2,
48-
defaultIsDiffOpen: true,
50+
export const WithDiff: Story = {
51+
args: {
52+
auditLog: MockAuditLog2,
53+
defaultIsDiffOpen: true,
54+
},
4955
};
5056

51-
export const WithLongDiffRow = Template.bind({});
52-
WithLongDiffRow.args = {
53-
auditLog: {
54-
...MockAuditLog2,
55-
diff: {
56-
...MockAuditLog2.diff,
57-
icon: {
58-
old: "https://www.google.com/url?sa=i&url=https%3A%2F%2Fwww.docker.com%2Fcompany%2Fnewsroom%2Fmedia-resources%2F&psig=AOvVaw3hLg_lm0tzXPBt74XZD2GC&ust=1666892413988000&source=images&cd=vfe&ved=0CAwQjRxqFwoTCPDsiKa4_voCFQAAAAAdAAAAABAD",
59-
new: "https://www.google.com/url?sa=i&url=https%3A%2F%2Fwww.kindpng.com%2Fimgv%2FhRowRxi_docker-icon-png-transparent-png%2F&psig=AOvVaw3hLg_lm0tzXPBt74XZD2GC&ust=1666892413988000&source=images&cd=vfe&ved=0CAwQjRxqFwoTCPDsiKa4_voCFQAAAAAdAAAAABAI",
60-
secret: false,
57+
export const WithLongDiffRow: Story = {
58+
args: {
59+
auditLog: {
60+
...MockAuditLog2,
61+
diff: {
62+
...MockAuditLog2.diff,
63+
icon: {
64+
old: "https://www.google.com/url?sa=i&url=https%3A%2F%2Fwww.docker.com%2Fcompany%2Fnewsroom%2Fmedia-resources%2F&psig=AOvVaw3hLg_lm0tzXPBt74XZD2GC&ust=1666892413988000&source=images&cd=vfe&ved=0CAwQjRxqFwoTCPDsiKa4_voCFQAAAAAdAAAAABAD",
65+
new: "https://www.google.com/url?sa=i&url=https%3A%2F%2Fwww.kindpng.com%2Fimgv%2FhRowRxi_docker-icon-png-transparent-png%2F&psig=AOvVaw3hLg_lm0tzXPBt74XZD2GC&ust=1666892413988000&source=images&cd=vfe&ved=0CAwQjRxqFwoTCPDsiKa4_voCFQAAAAAdAAAAABAI",
66+
secret: false,
67+
},
6168
},
6269
},
70+
defaultIsDiffOpen: true,
6371
},
64-
defaultIsDiffOpen: true,
6572
};
6673

67-
export const WithStoppedWorkspaceBuild = Template.bind({});
68-
WithStoppedWorkspaceBuild.args = {
69-
auditLog: {
70-
...MockAuditLogWithWorkspaceBuild,
71-
action: "stop",
74+
export const WithStoppedWorkspaceBuild: Story = {
75+
args: {
76+
auditLog: {
77+
...MockAuditLogWithWorkspaceBuild,
78+
action: "stop",
79+
},
7280
},
7381
};
7482

75-
export const WithStartedWorkspaceBuild = Template.bind({});
76-
WithStartedWorkspaceBuild.args = {
77-
auditLog: {
78-
...MockAuditLogWithWorkspaceBuild,
79-
action: "start",
83+
export const WithStartedWorkspaceBuild: Story = {
84+
args: {
85+
auditLog: {
86+
...MockAuditLogWithWorkspaceBuild,
87+
action: "start",
88+
},
8089
},
8190
};
8291

83-
export const WithDeletedWorkspaceBuild = Template.bind({});
84-
WithDeletedWorkspaceBuild.args = {
85-
auditLog: {
86-
...MockAuditLogWithWorkspaceBuild,
87-
action: "delete",
88-
is_deleted: true,
92+
export const WithDeletedWorkspaceBuild: Story = {
93+
args: {
94+
auditLog: {
95+
...MockAuditLogWithWorkspaceBuild,
96+
action: "delete",
97+
is_deleted: true,
98+
},
8999
},
90100
};
91101

92-
export const DeletedResource = Template.bind({});
93-
DeletedResource.args = {
94-
auditLog: MockAuditLogWithDeletedResource,
102+
export const DeletedResource: Story = {
103+
args: {
104+
auditLog: MockAuditLogWithDeletedResource,
105+
},
95106
};
96107

97-
export const SecretDiffValue = Template.bind({});
98-
SecretDiffValue.args = {
99-
auditLog: MockAuditLogGitSSH,
108+
export const SecretDiffValue: Story = {
109+
args: {
110+
auditLog: MockAuditLogGitSSH,
111+
},
100112
};

site/src/pages/AuditPage/AuditPage.test.tsx

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -59,15 +59,6 @@ describe("AuditPage", () => {
5959
);
6060
});
6161

62-
it("shows the audit logs", async () => {
63-
// When
64-
await renderPage();
65-
66-
// Then
67-
await screen.findByTestId(`audit-log-row-${MockAuditLog.id}`);
68-
screen.getByTestId(`audit-log-row-${MockAuditLog2.id}`);
69-
});
70-
7162
it("renders page 5", async () => {
7263
// Given
7364
const page = 5;

0 commit comments

Comments
 (0)