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
23 lines
1 KiB
TypeScript
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 });
|
|
});
|
|
});
|