feat(glossary) : allow shared shortcuts and show item images
CI / Verify (push) Successful in 1m11s
CI / Build immutable images and deploy (push) Successful in 1m54s

This commit is contained in:
2026-09-13 14:21:11 +07:00 Unverified
parent bcdb0b9266
commit f188251082
6 changed files with 2760 additions and 6 deletions
+28
View File
@@ -1,8 +1,36 @@
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");