Track HiveGrid Cloud planning reference
This commit is contained in:
1 parent
b3d5ea6764
commit
e341c5938a
5784 files changed
+1104929
-3
No files matched your search
@@ -0,0 +1,74 @@
|
||||
import "@testing-library/jest-dom";
|
||||
import { render, screen } from "@testing-library/react";
|
||||
import { MemoryRouter } from "react-router";
|
||||
import { describe, expect, it, vi } from "vitest";
|
||||
import AdminAuditLogToolbar from "./AdminAuditLogToolbar";
|
||||
|
||||
vi.mock("react-i18next", () => ({
|
||||
useTranslation: () => ({ t: (key: string) => key }),
|
||||
}));
|
||||
|
||||
vi.mock("~/components/ui/input/InputFilters", () => ({
|
||||
default: ({ filters }: { filters: { name: string; title: string }[] }) => (
|
||||
<div data-testid="input-filters">
|
||||
{filters.map((filter) => (
|
||||
<span key={filter.name}>{filter.title}</span>
|
||||
))}
|
||||
</div>
|
||||
),
|
||||
}));
|
||||
|
||||
const filters = [
|
||||
{ name: "action", title: "models.log.action" },
|
||||
{ name: "url", title: "models.log.url" },
|
||||
{ name: "tenantId", title: "models.tenant.object" },
|
||||
];
|
||||
|
||||
function renderToolbar(initialEntry: string) {
|
||||
return render(
|
||||
<MemoryRouter initialEntries={[initialEntry]}>
|
||||
<AdminAuditLogToolbar filters={filters} />
|
||||
</MemoryRouter>
|
||||
);
|
||||
}
|
||||
|
||||
describe("AdminAuditLogToolbar", () => {
|
||||
it("renders the provided filters", () => {
|
||||
renderToolbar("/audit-trails?action=create");
|
||||
|
||||
expect(screen.getByTestId("input-filters")).toBeInTheDocument();
|
||||
expect(screen.getByText("models.log.action")).toBeInTheDocument();
|
||||
expect(screen.getByText("models.log.url")).toBeInTheDocument();
|
||||
expect(screen.getByText("models.tenant.object")).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it("preserves active filters while replacing stale pagination with CSV export", () => {
|
||||
renderToolbar("/audit-trails?q=login&action=auth&url=%2Flogin&tenantId=tenant-1&page=3&pageSize=25");
|
||||
|
||||
const exportUrl = new URL(screen.getByRole("link", { name: "Export" }).getAttribute("href") ?? "", "https://example.test");
|
||||
|
||||
expect(exportUrl.pathname).toBe("/audit-trails");
|
||||
expect(exportUrl.searchParams.get("q")).toBe("login");
|
||||
expect(exportUrl.searchParams.get("action")).toBe("auth");
|
||||
expect(exportUrl.searchParams.get("url")).toBe("/login");
|
||||
expect(exportUrl.searchParams.get("tenantId")).toBe("tenant-1");
|
||||
expect(exportUrl.searchParams.get("pageSize")).toBe("25");
|
||||
expect(exportUrl.searchParams.get("page")).toBeNull();
|
||||
expect(exportUrl.searchParams.get("export")).toBe("csv");
|
||||
});
|
||||
|
||||
it("replaces an existing export value with csv", () => {
|
||||
renderToolbar("/audit-trails?export=json&userId=user-1");
|
||||
|
||||
const exportUrl = new URL(screen.getByRole("link", { name: "Export" }).getAttribute("href") ?? "", "https://example.test");
|
||||
|
||||
expect(exportUrl.searchParams.get("userId")).toBe("user-1");
|
||||
expect(exportUrl.searchParams.get("export")).toBe("csv");
|
||||
});
|
||||
|
||||
it("creates a valid CSV export href without existing search params", () => {
|
||||
renderToolbar("/audit-trails");
|
||||
|
||||
expect(screen.getByRole("link", { name: "Export" })).toHaveAttribute("href", "/audit-trails?export=csv");
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,35 @@
|
||||
import { Link, useLocation } from "react-router";
|
||||
import { useTranslation } from "react-i18next";
|
||||
import { FilterablePropertyDto } from "~/application/dtos/data/FilterablePropertyDto";
|
||||
import InputFilters from "~/components/ui/input/InputFilters";
|
||||
import { Button } from "~/components/ui/button";
|
||||
import { adminPath } from "~/utils/app/CanonicalUrlUtils";
|
||||
|
||||
type Props = {
|
||||
filters: FilterablePropertyDto[];
|
||||
};
|
||||
|
||||
export default function AdminAuditLogToolbar({ filters }: Props) {
|
||||
const { t } = useTranslation();
|
||||
const location = useLocation();
|
||||
const exportLabel = getFallbackTranslation(t("shared.export"), "Export");
|
||||
const exportSearchParams = new URLSearchParams(location.search);
|
||||
exportSearchParams.delete("page");
|
||||
exportSearchParams.set("export", "csv");
|
||||
const exportHref = adminPath(`audit-trails?${exportSearchParams.toString()}`, { mode: "host-aware" });
|
||||
|
||||
return (
|
||||
<div className="flex items-center gap-2">
|
||||
<Button asChild variant="outline">
|
||||
<Link to={exportHref} reloadDocument>
|
||||
{exportLabel}
|
||||
</Link>
|
||||
</Button>
|
||||
<InputFilters filters={filters} />
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
function getFallbackTranslation(value: string, fallback: string) {
|
||||
return value === "shared.export" ? fallback : value;
|
||||
}
|
||||
Reference in new issue
Block a user