* feat: add default search engines seeding * feat: set Homarr Docs as the default search Set the default search engine in server settings during seeding * refactor: use typed methods to define settings * feat: add insertServerSettingByKeyAsync * feat: update seeding logic for server settings * fix: format file using prettier * fix: disable eslint for `urlTemplate` * refactor: remove never happning else * feat: enhance createDocumentationLink - Updated createDocumentationLink to accept query parameters * test: add unit tests for createDocumentationLink * fix: update urlTemplate for Homarr documentation
48 lines
2.0 KiB
TypeScript
48 lines
2.0 KiB
TypeScript
/* eslint-disable no-restricted-syntax */
|
|
import { describe, expect, test } from "vitest";
|
|
|
|
import { createDocumentationLink } from "../docs";
|
|
import type { HomarrDocumentationPath } from "../docs/homarr-docs-sitemap";
|
|
|
|
describe("createDocumentationLink should generate correct URLs", () => {
|
|
test.each([
|
|
["/docs/getting-started", undefined, undefined, "https://homarr.dev/docs/getting-started"],
|
|
["/blog", undefined, undefined, "https://homarr.dev/blog"],
|
|
["/docs/widgets/weather", "#configuration", undefined, "https://homarr.dev/docs/widgets/weather#configuration"],
|
|
[
|
|
"/docs/advanced/environment-variables",
|
|
undefined,
|
|
{ lang: "en" },
|
|
"https://homarr.dev/docs/advanced/environment-variables?lang=en",
|
|
],
|
|
[
|
|
"/docs/widgets/bookmarks",
|
|
"#sorting",
|
|
{ lang: "fr", theme: "dark" },
|
|
"https://homarr.dev/docs/widgets/bookmarks?lang=fr&theme=dark#sorting",
|
|
],
|
|
] satisfies [HomarrDocumentationPath, `#${string}` | undefined, Record<string, string> | undefined, string][])(
|
|
"should create correct URL for path %s with hash %s and params %o",
|
|
(path, hashTag, queryParams, expected) => {
|
|
expect(createDocumentationLink(path, hashTag, queryParams)).toBe(expected);
|
|
},
|
|
);
|
|
});
|
|
|
|
describe("createDocumentationLink parameter validation", () => {
|
|
test("should work with only path parameter", () => {
|
|
const result = createDocumentationLink("/docs/getting-started");
|
|
expect(result).toBe("https://homarr.dev/docs/getting-started");
|
|
});
|
|
|
|
test("should work with path and hashtag", () => {
|
|
const result = createDocumentationLink("/docs/getting-started", "#installation");
|
|
expect(result).toBe("https://homarr.dev/docs/getting-started#installation");
|
|
});
|
|
|
|
test("should work with path and query params", () => {
|
|
const result = createDocumentationLink("/docs/getting-started", undefined, { version: "1.0" });
|
|
expect(result).toBe("https://homarr.dev/docs/getting-started?version=1.0");
|
|
});
|
|
});
|