feat(glossary) : allow shared shortcuts and show item images
This commit is contained in:
@@ -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");
|
||||
|
||||
Reference in New Issue
Block a user