mirror of
https://github.com/Termix-SSH/Termix.git
synced 2026-10-27 21:55:24 +00:00
* feat: add an auto or fixed columns picker to card grids * feat: add safe mode that only runs layout and theme plugins * docs: add simple layout to plugin table * fix: ask for local network access in the macOS app * feat: allow plugin registries on listed private hosts (#1705) * chore: add private registry hosts to the changelog * feat: use the proxy for plugin registry downloads * fix: allow changing connection origin on shared hosts * chore: update translations and plugin pins * chore: lint, format, and bump version to 26.10.5 --------- Co-authored-by: Lukas <80832688+0skater0@users.noreply.github.com>
78 lines
2.1 KiB
TypeScript
78 lines
2.1 KiB
TypeScript
import { afterEach, describe, expect, it, vi } from "vitest";
|
|
import { cleanup, fireEvent, render, screen } from "@testing-library/react";
|
|
import { DataView } from "@/components/data-view";
|
|
|
|
afterEach(cleanup);
|
|
|
|
const items = [
|
|
{ id: "a", name: "alpha" },
|
|
{ id: "b", name: "beta" },
|
|
];
|
|
|
|
function renderView(view: "grid" | "list", onRowClick = vi.fn()) {
|
|
return render(
|
|
<DataView
|
|
items={items}
|
|
view={view}
|
|
density="compact"
|
|
getKey={(item) => item.id}
|
|
renderCard={(item) => <div>card {item.name}</div>}
|
|
columns={{ base: 1, md: 2 }}
|
|
listColumns={[
|
|
{ key: "name", header: "Name", width: "1fr", cell: (i) => i.name },
|
|
]}
|
|
onRowClick={onRowClick}
|
|
empty={<span>nothing</span>}
|
|
/>,
|
|
);
|
|
}
|
|
|
|
describe("DataView", () => {
|
|
it("renders cards in grid mode", () => {
|
|
renderView("grid");
|
|
expect(screen.getByText("card alpha")).toBeTruthy();
|
|
expect(screen.queryByText("Name")).toBeNull();
|
|
});
|
|
|
|
it("uses the picked size over breakpoint columns", () => {
|
|
const { container } = render(
|
|
<DataView
|
|
items={items}
|
|
view="grid"
|
|
getKey={(item) => item.id}
|
|
renderCard={(item) => <div>card {item.name}</div>}
|
|
columns={{ base: 1, md: 2 }}
|
|
size="3"
|
|
listColumns={[]}
|
|
empty={null}
|
|
/>,
|
|
);
|
|
const grid = container.firstElementChild as HTMLElement;
|
|
expect(grid.className).not.toContain("md:grid-cols-2");
|
|
expect(grid.style.gridTemplateColumns).toContain("/ 3");
|
|
});
|
|
|
|
it("renders a header and clickable rows in list mode", () => {
|
|
const onRowClick = vi.fn();
|
|
renderView("list", onRowClick);
|
|
expect(screen.getByText("Name")).toBeTruthy();
|
|
fireEvent.click(screen.getByText("beta"));
|
|
expect(onRowClick).toHaveBeenCalledWith(items[1]);
|
|
});
|
|
|
|
it("shows the empty state with no items", () => {
|
|
render(
|
|
<DataView
|
|
items={[]}
|
|
view="grid"
|
|
getKey={() => ""}
|
|
renderCard={() => null}
|
|
columns={{}}
|
|
listColumns={[]}
|
|
empty={<span>nothing</span>}
|
|
/>,
|
|
);
|
|
expect(screen.getByText("nothing")).toBeTruthy();
|
|
});
|
|
});
|