mirror of
https://github.com/tauri-apps/tauri-search.git
synced 2026-02-04 02:41:20 +01:00
53 lines
1.4 KiB
TypeScript
53 lines
1.4 KiB
TypeScript
import { createModel } from "~/utils/createModel";
|
|
|
|
type Model = {
|
|
title: string;
|
|
section: string;
|
|
lastUpdated: number;
|
|
};
|
|
|
|
type AstModel = {
|
|
h1: string;
|
|
h2: string;
|
|
lastUpdated: string;
|
|
};
|
|
|
|
describe("createModel()", () => {
|
|
it("Configuring index properties on a model is seen in model's info section", async () => {
|
|
const m = createModel<Model>("foobar", (m) =>
|
|
m //
|
|
.sortable("section")
|
|
.displayed("title", "section")
|
|
.filterable("lastUpdated")
|
|
);
|
|
|
|
expect(m.meta.displayed).toContain("title");
|
|
expect(m.meta.displayed).toContain("section");
|
|
expect(m.meta.displayed).not.toContain("lastUpdated");
|
|
|
|
expect(m.meta.sortable).toContain("section");
|
|
expect(m.meta.filterable).toContain("lastUpdated");
|
|
});
|
|
|
|
it("toString() produces a clear and concise indication of what model it is", async () => {
|
|
const m = createModel<Model>("foobar");
|
|
expect(m.toString()).toContain("Model");
|
|
expect(m.toString()).toContain("foobar::");
|
|
expect(m.toString()).toContain(String(m.meta.hash));
|
|
});
|
|
|
|
it("adding mappers to a model, exposes this on the model API", () => {
|
|
// define a mapper on `m`
|
|
const m = createModel<Model>("foobar", (c) =>
|
|
c //
|
|
.addMapper("doc")
|
|
.mapDefn<AstModel>((i) => ({
|
|
title: i.h1,
|
|
section: i.h2,
|
|
lastUpdated: new Date(i.lastUpdated).getTime(),
|
|
}))
|
|
.searchable("title", "section")
|
|
);
|
|
});
|
|
});
|