feat: initialize Vue component library and aligned documentation
This commit is contained in:
@@ -0,0 +1,66 @@
|
||||
import { describe, it, expect } from "vitest";
|
||||
import {
|
||||
searchDocs,
|
||||
searchExcerpt,
|
||||
type SearchEntry,
|
||||
} from "../apps/docs/.vitepress/theme/search";
|
||||
const entries: SearchEntry[] = [
|
||||
{
|
||||
title: "Button 按钮",
|
||||
section: "API 参考",
|
||||
url: "/components/button#api-参考",
|
||||
text: "isPending boolean 加载期间保留焦点",
|
||||
},
|
||||
{
|
||||
title: "Switch 开关",
|
||||
section: "API 参考",
|
||||
url: "/components/switch#api-参考",
|
||||
text: "isReadOnly 只读 checked",
|
||||
},
|
||||
{
|
||||
title: "主题",
|
||||
section: "默认主题",
|
||||
url: "/themes#默认主题",
|
||||
text: "Button 采用相同颜色变量",
|
||||
},
|
||||
{
|
||||
title: "Input 输入框",
|
||||
section: "受控组件",
|
||||
url: "/components/input#受控组件",
|
||||
text: "使用 v-model 更新输入值",
|
||||
},
|
||||
];
|
||||
describe("documentation search", () => {
|
||||
it("finds parameters inside API content rather than only page titles", () => {
|
||||
expect(searchDocs(entries, "ispending").map((e) => e.url)).toEqual([
|
||||
"/components/button#api-参考",
|
||||
]);
|
||||
});
|
||||
it("ranks component-title matches before incidental content mentions", () => {
|
||||
expect(searchDocs(entries, "button")[0].title).toBe("Button 按钮");
|
||||
});
|
||||
it("requires all search terms and ignores surrounding whitespace and casing", () => {
|
||||
expect(searchDocs(entries, " SWITCH 只读 ").map((e) => e.title)).toEqual(
|
||||
["Switch 开关"],
|
||||
);
|
||||
});
|
||||
it("returns no results for blank or unmatched queries", () => {
|
||||
expect(searchDocs(entries, " ")).toEqual([]);
|
||||
expect(searchDocs(entries, "unknown-component")).toEqual([]);
|
||||
});
|
||||
});
|
||||
|
||||
it("shows the matched parameter in excerpts instead of table separator noise", () => {
|
||||
const entry = {
|
||||
title: "Button",
|
||||
section: "API",
|
||||
url: "/button",
|
||||
text:
|
||||
"Prop 类型 -------- " +
|
||||
"前文 ".repeat(60) +
|
||||
"isPending boolean 是否处于加载状态",
|
||||
};
|
||||
const excerpt = searchExcerpt(entry, "isPending");
|
||||
expect(excerpt).toContain("isPending");
|
||||
expect(excerpt).not.toContain("--------");
|
||||
});
|
||||
Reference in New Issue
Block a user