49 lines
1.9 KiB
TypeScript
49 lines
1.9 KiB
TypeScript
import { describe, expect, it } from "vitest";
|
|
import { getTableConfig } from "drizzle-orm/pg-core";
|
|
|
|
import { glossaryAliases } from "../db/schema";
|
|
import { aliasesByItem, normalizeGlossaryAlias } from "./glossary";
|
|
import { searchItems } from "./search";
|
|
|
|
describe("glossary aliases", () => {
|
|
it("limits duplicate shortcuts to the same catalog item", () => {
|
|
const uniqueIndexes = getTableConfig(glossaryAliases).indexes.filter((index) => index.config.unique);
|
|
expect(uniqueIndexes).toHaveLength(1);
|
|
expect(uniqueIndexes[0].config.columns.map((column) => "name" in column ? column.name : undefined)).toEqual([
|
|
"kind",
|
|
"catalog_key",
|
|
"normalized_alias",
|
|
]);
|
|
});
|
|
|
|
it("finds multiple weapons sharing the same shortcut", () => {
|
|
const weapons = [
|
|
{ key: "ballad", name: "Ballad of the Fjords" },
|
|
{ key: "favonius", name: "Favonius Greatsword" },
|
|
{ key: "homa", name: "Staff of Homa" },
|
|
];
|
|
const grouped = aliasesByItem([
|
|
{ kind: "weapon", catalogKey: "ballad", alias: "bp" },
|
|
{ kind: "weapon", catalogKey: "favonius", alias: "bp" },
|
|
]);
|
|
const names = (weapon: (typeof weapons)[number]) => [weapon.name, ...(grouped.weapon.get(weapon.key) ?? [])];
|
|
expect(searchItems(weapons, "BP", (weapon) => names(weapon).join(" "), names).items)
|
|
.toEqual(weapons.slice(0, 2));
|
|
});
|
|
|
|
it("normalizes case, spacing, and unicode", () => {
|
|
expect(normalizeGlossaryAlias(" HoMa ")).toBe("homa");
|
|
expect(normalizeGlossaryAlias("ATK")).toBe("atk");
|
|
});
|
|
|
|
it("groups aliases by item and ignores unknown kinds", () => {
|
|
const grouped = aliasesByItem([
|
|
{ kind: "weapon", catalogKey: "homa", alias: "SoH" },
|
|
{ kind: "weapon", catalogKey: "homa", alias: "Homa" },
|
|
{ kind: "unknown", catalogKey: "x", alias: "x" },
|
|
]);
|
|
expect(grouped.weapon.get("homa")).toEqual(["SoH", "Homa"]);
|
|
expect(grouped.character.size).toBe(0);
|
|
});
|
|
});
|