55 lines
1.8 KiB
TypeScript
55 lines
1.8 KiB
TypeScript
// @vitest-environment node
|
|
|
|
import { describe, expect, test } from "vitest";
|
|
|
|
import { iconRepositories, icons } from "@homarr/db/schema";
|
|
import { createDb } from "@homarr/db/test";
|
|
|
|
import { iconsRouter } from "../icons";
|
|
|
|
describe("findIcons", () => {
|
|
test("returns only repositories containing matches for a search", async () => {
|
|
const db = createDb();
|
|
await db.insert(iconRepositories).values([
|
|
{ id: "dashboard-icons", slug: "homarr-labs/dashboard-icons" },
|
|
{ id: "other-icons", slug: "example/other-icons" },
|
|
]);
|
|
await db.insert(icons).values([
|
|
{
|
|
id: "discord-svg",
|
|
name: "discord.svg",
|
|
url: "https://cdn.example.com/discord.svg",
|
|
checksum: "discord",
|
|
iconRepositoryId: "dashboard-icons",
|
|
},
|
|
{
|
|
id: "homarr-svg",
|
|
name: "homarr.svg",
|
|
url: "https://cdn.example.com/homarr.svg",
|
|
checksum: "homarr",
|
|
iconRepositoryId: "other-icons",
|
|
},
|
|
]);
|
|
const caller = iconsRouter.createCaller({ db, deviceType: undefined, session: null });
|
|
|
|
const result = await caller.findIcons({ searchText: "discord", limitPerGroup: 6 });
|
|
|
|
expect(result.countIcons).toBe(2);
|
|
expect(result.icons).toHaveLength(1);
|
|
expect(result.icons[0]).toMatchObject({
|
|
slug: "homarr-labs/dashboard-icons",
|
|
icons: [{ name: "discord.svg", url: "https://cdn.example.com/discord.svg" }],
|
|
});
|
|
});
|
|
|
|
test("keeps repositories when browsing without a search", async () => {
|
|
const db = createDb();
|
|
await db.insert(iconRepositories).values({ id: "empty", slug: "example/empty" });
|
|
const caller = iconsRouter.createCaller({ db, deviceType: undefined, session: null });
|
|
|
|
const result = await caller.findIcons({ limitPerGroup: 6 });
|
|
|
|
expect(result.icons).toMatchObject([{ slug: "example/empty", icons: [] }]);
|
|
});
|
|
});
|