Fixhancement: crowdsec widget improvements (#7075)
Docker CI / Docker Build & Push (push) Has been cancelled
Release Drafter / Update Release Draft (push) Has been cancelled
Release Drafter / Auto Label PR (push) Has been cancelled
Lint / Linting Checks (push) Has been cancelled
Tests / vitest (1) (push) Has been cancelled
Tests / vitest (2) (push) Has been cancelled
Tests / vitest (3) (push) Has been cancelled
Tests / vitest (4) (push) Has been cancelled

This commit is contained in:
shamoon
2026-08-29 23:43:19 -07:00
committed by GitHub
parent e6ad43a76c
commit f6dca0c5ad
4 changed files with 49 additions and 12 deletions
+37 -3
View File
@@ -17,15 +17,25 @@ describe("widgets/crowdsec/component", () => {
vi.clearAllMocks();
});
it("selects alerts24h endpoint when limit24h is enabled", () => {
it("requests the alerts and bans endpoints", () => {
useWidgetAPI.mockImplementation(() => ({ data: undefined, error: undefined }));
renderWithProviders(<Component service={{ widget: { type: "crowdsec" } }} />, {
settings: { hideErrors: false },
});
expect(useWidgetAPI).toHaveBeenNthCalledWith(1, expect.any(Object), "alerts");
expect(useWidgetAPI).toHaveBeenNthCalledWith(2, expect.any(Object), "bans");
});
it("ignores the deprecated limit24h option", () => {
useWidgetAPI.mockImplementation(() => ({ data: undefined, error: undefined }));
renderWithProviders(<Component service={{ widget: { type: "crowdsec", limit24h: true } }} />, {
settings: { hideErrors: false },
});
expect(useWidgetAPI).toHaveBeenNthCalledWith(1, expect.any(Object), "alerts24h");
expect(useWidgetAPI).toHaveBeenNthCalledWith(2, expect.any(Object), "bans");
expect(useWidgetAPI).toHaveBeenNthCalledWith(1, expect.any(Object), "alerts");
});
it("renders placeholders when both alerts and bans are missing", () => {
@@ -52,4 +62,28 @@ describe("widgets/crowdsec/component", () => {
expectBlockValue(container, "crowdsec.alerts", 0);
expectBlockValue(container, "crowdsec.bans", 0);
});
it("marks the alert count as truncated at the API limit", () => {
useWidgetAPI
.mockReturnValueOnce({ data: new Array(500).fill({}), error: undefined })
.mockReturnValueOnce({ data: [], error: undefined });
renderWithProviders(<Component service={{ widget: { type: "crowdsec" } }} />, {
settings: { hideErrors: false },
});
expect(screen.getByText("500+")).toBeInTheDocument();
});
it("does not mark the alert count below the API limit", () => {
useWidgetAPI
.mockReturnValueOnce({ data: new Array(499).fill({}), error: undefined })
.mockReturnValueOnce({ data: [], error: undefined });
const { container } = renderWithProviders(<Component service={{ widget: { type: "crowdsec" } }} />, {
settings: { hideErrors: false },
});
expectBlockValue(container, "crowdsec.alerts", 499);
});
});