Reorganize repo structure and standards references

This commit is contained in:
david committed 2026-06-29 05:03:42 +02:00
1 parent 3cb93a81be
commit be2054274d
5885 files changed
+2588 -195

No files matched your search

@@ -0,0 +1,76 @@
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 TenantActivityLogToolbar from "~/components/activity/TenantActivityLogToolbar";
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: "actor", title: "models.log.actor" },
];
function renderToolbar(initialEntry: string) {
return render(
<MemoryRouter initialEntries={[initialEntry]}>
<TenantActivityLogToolbar filters={filters} />
</MemoryRouter>
);
}
describe("TenantActivityLogToolbar", () => {
it("renders the provided filters", () => {
renderToolbar("/acme/settings/logs?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.log.actor")).toBeInTheDocument();
});
it("preserves active filters while replacing stale pagination with CSV export", () => {
renderToolbar("/acme/settings/logs?q=login&action=auth&url=%2Flogin&actor=Grace&page=3&pageSize=25");
const exportUrl = new URL(screen.getByRole("link", { name: "Export" }).getAttribute("href") ?? "", "https://example.test");
expect(exportUrl.pathname).toBe("/acme/settings/logs");
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("actor")).toBe("Grace");
expect(exportUrl.searchParams.get("pageSize")).toBe("25");
expect(exportUrl.searchParams.get("tenantId")).toBeNull();
expect(exportUrl.searchParams.get("page")).toBeNull();
expect(exportUrl.searchParams.get("export")).toBe("csv");
});
it("replaces an existing export value with csv", () => {
renderToolbar("/acme/settings/logs?export=json&actor=user-1");
const exportUrl = new URL(screen.getByRole("link", { name: "Export" }).getAttribute("href") ?? "", "https://example.test");
expect(exportUrl.pathname).toBe("/acme/settings/logs");
expect(exportUrl.searchParams.get("actor")).toBe("user-1");
expect(exportUrl.searchParams.get("export")).toBe("csv");
});
it("creates a valid tenant-relative CSV export href without existing search params", () => {
renderToolbar("/acme/settings/logs");
expect(screen.getByRole("link", { name: "Export" })).toHaveAttribute("href", "/acme/settings/logs?export=csv");
});
});
@@ -0,0 +1,34 @@
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";
type Props = {
filters: FilterablePropertyDto[];
};
export default function TenantActivityLogToolbar({ 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 = `${location.pathname}?${exportSearchParams.toString()}`;
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;
}