content-explorer/ui/lib/sort-rows.test.ts
tegwick a6e360aaa5 Port the explorer shell: tokens, header, hero, and a generic table.
CONTENT-WP-0002-T01 adapts the pinned OnCo visual system under ui/ without the corpus, mark, or kind routes.

Assistant: grok
Assistant-Session: 01a1346c-fdff-7741-b1af-b7283661554b
2026-10-13 22:51:00 +02:00

23 lines
1 KiB
TypeScript

import { describe, expect, it } from "vitest";
import { nextSort, sortRows } from "./sort-rows";
const rows = [
{ title: "Emergence" },
{ title: "Feedback" },
{ title: "Requisite variety" },
];
describe("sortRows", () => {
it("orders by the selected key and flips with the direction", () => {
const ascending = sortRows(rows, { key: "title", dir: 1 }, (row, key) => row[key as "title"]);
expect(ascending.map((row) => row.title)).toEqual(["Emergence", "Feedback", "Requisite variety"]);
const descending = sortRows(rows, { key: "title", dir: -1 }, (row, key) => row[key as "title"]);
expect(descending.map((row) => row.title)).toEqual(["Requisite variety", "Feedback", "Emergence"]);
});
it("toggles direction when the same key is chosen again", () => {
expect(nextSort(undefined, "title")).toEqual({ key: "title", dir: 1 });
expect(nextSort({ key: "title", dir: 1 }, "title")).toEqual({ key: "title", dir: -1 });
expect(nextSort({ key: "title", dir: -1 }, "kindLabel")).toEqual({ key: "kindLabel", dir: 1 });
});
});