Skip to content

Commit 21b5ef1

Browse files
kathiekiwiTrigger.dev RepoOps
authored andcommitted
test(webapp): Cleanup for unnecessary tests after Alerts merge
Mono-RevId: 66417a057fa33dbdea1e4914dcbcea329cb9c5af
1 parent 5567633 commit 21b5ef1

54 files changed

Lines changed: 917 additions & 4655 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎apps/webapp/app/components/alerts/AgentManualToggle.dom.test.ts‎

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

‎apps/webapp/app/components/alerts/AlertActionsMenu.dom.test.ts‎

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// @vitest-environment jsdom
22
import { act, createElement } from "react";
33
import { createRoot } from "react-dom/client";
4+
import { renderToStaticMarkup } from "react-dom/server";
45
import { createMemoryRouter, RouterProvider } from "react-router-dom";
56
import { describe, expect, it, vi } from "vitest";
67
import { DashboardAgentProvider } from "~/components/dashboard-agent/dashboardAgentLauncher";
@@ -291,3 +292,70 @@ describe("row status actions for rows with a channel issue", () => {
291292
expect(active).not.toContain("Mark as Resolved");
292293
});
293294
});
295+
296+
describe("AlertActionsPopoverContent permissions", () => {
297+
function buttons(
298+
status: AlertListRow["status"],
299+
canWrite = true,
300+
canDelete = true,
301+
expiresAt: string | null = null
302+
) {
303+
const noop = () => {};
304+
const agent = { open: false, openWith: noop } as unknown as React.ComponentProps<
305+
typeof DashboardAgentProvider
306+
>["value"];
307+
const html = renderToStaticMarkup(
308+
createElement(
309+
OperatingSystemContextProvider,
310+
{ platform: "mac" },
311+
createElement(
312+
ShortcutsProvider,
313+
null,
314+
createElement(
315+
DashboardAgentProvider,
316+
{ value: agent },
317+
createElement(AlertActionsPopoverContent, {
318+
alert: {
319+
id: "a1",
320+
name: "Depth",
321+
conditionSummary: "> 100",
322+
status,
323+
expiresAt,
324+
} as AlertListRow,
325+
canWrite,
326+
canDelete,
327+
onClose: noop,
328+
onResolve: noop,
329+
onStop: noop,
330+
onActivate: noop,
331+
onEdit: noop,
332+
onDelete: noop,
333+
})
334+
)
335+
)
336+
)
337+
);
338+
return [...html.matchAll(/<button([^>]*)>([\s\S]*?)<\/button>|<hr/g)].map((m) =>
339+
m[0] === "<hr"
340+
? { title: "---", disabled: false }
341+
: {
342+
title: m[2]!.replace(/<[^>]+>/g, "").trim(),
343+
disabled: m[1]!.includes('disabled=""'),
344+
}
345+
);
346+
}
347+
348+
it("disables every write action without write:alerts, leaving Investigate", () => {
349+
for (const status of ["needs_attention", "active", "inactive"] as const) {
350+
for (const item of buttons(status, false).filter((b) => b.title !== "---")) {
351+
expect(item.disabled).toBe(item.title !== "Investigate");
352+
}
353+
}
354+
expect(buttons("inactive").every((item) => !item.disabled)).toBe(true);
355+
});
356+
357+
it("disables Delete without delete:alerts", () => {
358+
const disabled = buttons("inactive", true, false).filter((item) => item.disabled);
359+
expect(disabled.map((item) => item.title)).toEqual(["Delete"]);
360+
});
361+
});

‎apps/webapp/app/components/alerts/AlertActivityCell.render.test.ts‎

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

‎apps/webapp/app/components/alerts/AlertActivityTable.render.test.ts‎

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

‎apps/webapp/app/components/alerts/AlertActivityTable.tsx‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,13 +39,13 @@ const EVENT_LABEL: Record<AlertDetailEvent["type"], string> = {
3939
stopped: "Stopped",
4040
};
4141

42-
export const LEVEL_DESCRIPTIONS: Record<AlertLevel, string> = {
42+
const LEVEL_DESCRIPTIONS: Record<AlertLevel, string> = {
4343
ERROR: "The condition was met and the alert was raised.",
4444
WARN: "The alert expired or was stopped.",
4545
INFO: "The condition recovered or you resolved the alert.",
4646
};
4747

48-
export function LevelBreakdown() {
48+
function LevelBreakdown() {
4949
return (
5050
<div className="flex flex-col gap-2.5">
5151
{(Object.keys(LEVEL_DESCRIPTIONS) as AlertLevel[]).map((level) => (

‎apps/webapp/app/components/alerts/AlertChannelsBody.render.test.ts‎

Lines changed: 0 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -79,44 +79,7 @@ function render(
7979
return renderToStaticMarkup(createElement(RouterProvider, { router }));
8080
}
8181

82-
function headers(html: string) {
83-
return [...html.matchAll(/<th[^>]*>([\s\S]*?)<\/th>/g)].map((m) =>
84-
m[1].replace(/<[^>]+>/g, "").trim()
85-
);
86-
}
87-
8882
describe("AlertChannelsBody with the alerts flag off", () => {
89-
it("lists Edit, Disable and Delete in the modal menu, without Edit environments", () => {
90-
const html = render({ modal: true });
91-
expect(headers(html)).toEqual([]);
92-
expect(html).not.toContain("h-11");
93-
expect(html).toContain("min-w-0");
94-
expect(html).not.toContain("max-w-0");
95-
expect(html).not.toContain("align-top");
96-
expect(html).toContain("w-px");
97-
expect(html).toMatch(/<td class="[^"]*\bw-10 pl-2\b/);
98-
expect(html).not.toMatch(/class="[^"]*\btruncate\b[^"]*system-mono-label/);
99-
expect(html).toContain("overflow-x-hidden");
100-
expect(html).not.toContain("w-80");
101-
expect(html).not.toMatch(
102-
/<div class="[^"]*border-t[^"]*whitespace-nowrap|<div class="whitespace-nowrap[^"]*border-t/
103-
);
104-
expect(html.indexOf(">Edit<")).toBeGreaterThan(-1);
105-
expect(html.indexOf(">Edit<")).toBeLessThan(html.indexOf(">Disable<"));
106-
expect(html.indexOf(">Disable<")).toBeLessThan(html.indexOf(">Delete<"));
107-
expect(html).not.toContain("Edit environments");
108-
expect(html).not.toContain("/chan_1/edit");
109-
});
110-
111-
it("summarises environments as icons, a count and a chevron without an inline list", () => {
112-
const html = render({ modal: true });
113-
expect(html).toContain("3 environments");
114-
const trigger = html.match(/<button[^>]*aria-haspopup="dialog"[\s\S]*?<\/button>/)![0];
115-
expect(trigger.match(/<svg/g)).toHaveLength(4);
116-
expect(html).not.toContain("flex flex-col gap-1");
117-
expect(html).not.toContain("Production");
118-
});
119-
12083
it("shows an Add channel button, not the create form, until clicked", () => {
12184
const under = render({ modal: true, used: 1 });
12285
expect(under).toContain("Add channel");
@@ -209,22 +172,6 @@ describe("AlertChannelsBody with the alerts flag off", () => {
209172
container.remove();
210173
});
211174

212-
it("renders a single environment inline without a popover trigger", () => {
213-
const one = { ...channel, environmentTypes: ["PRODUCTION"] } as unknown as AlertChannelRow;
214-
const html = render({ modal: true, channels: [one] });
215-
expect(html).toContain("Production");
216-
expect(html).not.toContain("1 environment");
217-
expect(html).not.toContain('aria-haspopup="dialog"');
218-
});
219-
220-
it("drops the Add channel title and divider when there are no channels", () => {
221-
const html = render({ modal: true, used: 0, channels: [] });
222-
expect(html).toContain('id="create-alert"');
223-
expect(html).not.toContain("Add channel");
224-
expect(html).not.toContain("gap-3 border-t");
225-
expect(render({ modal: true })).not.toContain('id="create-alert"');
226-
});
227-
228175
it("opens the form on Slack with a returnTo connect link when add=slack", () => {
229176
const html = render({ modal: true, url: "/?add=slack" });
230177
expect(html).toContain('id="create-alert"');

0 commit comments

Comments
 (0)