mirror of
https://github.com/gethomepage/homepage.git
synced 2026-02-08 00:40:52 +08:00
test: add widget config tests (batch 1)
This commit is contained in:
39
src/test-utils/widget-config.js
Normal file
39
src/test-utils/widget-config.js
Normal file
@@ -0,0 +1,39 @@
|
||||
import { expect } from "vitest";
|
||||
|
||||
export function expectWidgetConfigShape(widget) {
|
||||
expect(widget).toBeTruthy();
|
||||
expect(widget).toBeTypeOf("object");
|
||||
|
||||
if ("api" in widget) {
|
||||
expect(widget.api).toBeTypeOf("string");
|
||||
// Widget APIs are template strings that expand to a configured service URL.
|
||||
expect(widget.api).toContain("{url}");
|
||||
}
|
||||
|
||||
if ("proxyHandler" in widget) {
|
||||
expect(widget.proxyHandler).toBeTypeOf("function");
|
||||
}
|
||||
|
||||
if ("allowedEndpoints" in widget) {
|
||||
expect(widget.allowedEndpoints).toBeInstanceOf(RegExp);
|
||||
}
|
||||
|
||||
if ("mappings" in widget) {
|
||||
expect(widget.mappings).toBeTruthy();
|
||||
expect(widget.mappings).toBeTypeOf("object");
|
||||
|
||||
for (const [name, mapping] of Object.entries(widget.mappings)) {
|
||||
expect(name).toBeTruthy();
|
||||
expect(mapping).toBeTruthy();
|
||||
expect(mapping).toBeTypeOf("object");
|
||||
|
||||
if ("endpoint" in mapping) {
|
||||
expect(mapping.endpoint).toBeTypeOf("string");
|
||||
expect(mapping.endpoint.length).toBeGreaterThan(0);
|
||||
}
|
||||
if ("map" in mapping) {
|
||||
expect(mapping.map).toBeTypeOf("function");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
12
src/widgets/adguard/widget.test.js
Normal file
12
src/widgets/adguard/widget.test.js
Normal file
@@ -0,0 +1,12 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
|
||||
import { expectWidgetConfigShape } from "test-utils/widget-config";
|
||||
|
||||
import widget from "./widget";
|
||||
|
||||
describe("adguard widget config", () => {
|
||||
it("exports a valid widget config", () => {
|
||||
expectWidgetConfigShape(widget);
|
||||
expect(widget.mappings?.stats?.endpoint).toBe("stats");
|
||||
});
|
||||
});
|
||||
13
src/widgets/apcups/widget.test.js
Normal file
13
src/widgets/apcups/widget.test.js
Normal file
@@ -0,0 +1,13 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
|
||||
import { expectWidgetConfigShape } from "test-utils/widget-config";
|
||||
|
||||
import widget from "./widget";
|
||||
|
||||
describe("apcups widget config", () => {
|
||||
it("exports a valid widget config", () => {
|
||||
expectWidgetConfigShape(widget);
|
||||
// apcups talks TCP directly, so it does not use an `{url}/...` API template.
|
||||
expect(widget.api).toBeUndefined();
|
||||
});
|
||||
});
|
||||
12
src/widgets/audiobookshelf/widget.test.js
Normal file
12
src/widgets/audiobookshelf/widget.test.js
Normal file
@@ -0,0 +1,12 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
|
||||
import { expectWidgetConfigShape } from "test-utils/widget-config";
|
||||
|
||||
import widget from "./widget";
|
||||
|
||||
describe("audiobookshelf widget config", () => {
|
||||
it("exports a valid widget config", () => {
|
||||
expectWidgetConfigShape(widget);
|
||||
expect(widget.mappings?.libraries?.endpoint).toBe("libraries");
|
||||
});
|
||||
});
|
||||
13
src/widgets/authentik/widget.test.js
Normal file
13
src/widgets/authentik/widget.test.js
Normal file
@@ -0,0 +1,13 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
|
||||
import { expectWidgetConfigShape } from "test-utils/widget-config";
|
||||
|
||||
import widget from "./widget";
|
||||
|
||||
describe("authentik widget config", () => {
|
||||
it("exports a valid widget config", () => {
|
||||
expectWidgetConfigShape(widget);
|
||||
expect(widget.api).toContain("/api/v3/");
|
||||
expect(widget.mappings?.users?.endpoint).toContain("core/users");
|
||||
});
|
||||
});
|
||||
13
src/widgets/backrest/widget.test.js
Normal file
13
src/widgets/backrest/widget.test.js
Normal file
@@ -0,0 +1,13 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
|
||||
import { expectWidgetConfigShape } from "test-utils/widget-config";
|
||||
|
||||
import widget from "./widget";
|
||||
|
||||
describe("backrest widget config", () => {
|
||||
it("exports a valid widget config", () => {
|
||||
expectWidgetConfigShape(widget);
|
||||
expect(widget.api).toContain("/v1.Backrest/");
|
||||
expect(widget.mappings?.summary?.endpoint).toBe("GetSummaryDashboard");
|
||||
});
|
||||
});
|
||||
16
src/widgets/bazarr/widget.test.js
Normal file
16
src/widgets/bazarr/widget.test.js
Normal file
@@ -0,0 +1,16 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
|
||||
import { expectWidgetConfigShape } from "test-utils/widget-config";
|
||||
|
||||
import widget from "./widget";
|
||||
|
||||
describe("bazarr widget config", () => {
|
||||
it("exports a valid widget config", () => {
|
||||
expectWidgetConfigShape(widget);
|
||||
expect(widget.api).toContain("apikey={key}");
|
||||
|
||||
const moviesMapping = widget.mappings?.movies;
|
||||
expect(moviesMapping?.endpoint).toBe("movies");
|
||||
expect(moviesMapping?.map?.('{"total":123}')).toEqual({ total: 123 });
|
||||
});
|
||||
});
|
||||
12
src/widgets/calendar/widget.test.js
Normal file
12
src/widgets/calendar/widget.test.js
Normal file
@@ -0,0 +1,12 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
|
||||
import { expectWidgetConfigShape } from "test-utils/widget-config";
|
||||
|
||||
import widget from "./widget";
|
||||
|
||||
describe("calendar widget config", () => {
|
||||
it("exports a valid widget config", () => {
|
||||
expectWidgetConfigShape(widget);
|
||||
expect(widget.api).toBe("{url}");
|
||||
});
|
||||
});
|
||||
13
src/widgets/glances/widget.test.js
Normal file
13
src/widgets/glances/widget.test.js
Normal file
@@ -0,0 +1,13 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
|
||||
import { expectWidgetConfigShape } from "test-utils/widget-config";
|
||||
|
||||
import widget from "./widget";
|
||||
|
||||
describe("glances widget config", () => {
|
||||
it("exports a valid widget config", () => {
|
||||
expectWidgetConfigShape(widget);
|
||||
expect(widget.allowedEndpoints?.test("3/quicklook")).toBe(true);
|
||||
expect(widget.allowedEndpoints?.test("unknown")).toBe(false);
|
||||
});
|
||||
});
|
||||
13
src/widgets/immich/widget.test.js
Normal file
13
src/widgets/immich/widget.test.js
Normal file
@@ -0,0 +1,13 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
|
||||
import { expectWidgetConfigShape } from "test-utils/widget-config";
|
||||
|
||||
import widget from "./widget";
|
||||
|
||||
describe("immich widget config", () => {
|
||||
it("exports a valid widget config", () => {
|
||||
expectWidgetConfigShape(widget);
|
||||
expect(widget.api).toContain("/api/");
|
||||
expect(widget.mappings?.version?.endpoint).toBe("server-info/version");
|
||||
});
|
||||
});
|
||||
12
src/widgets/unraid/widget.test.js
Normal file
12
src/widgets/unraid/widget.test.js
Normal file
@@ -0,0 +1,12 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
|
||||
import { expectWidgetConfigShape } from "test-utils/widget-config";
|
||||
|
||||
import widget from "./widget";
|
||||
|
||||
describe("unraid widget config", () => {
|
||||
it("exports a valid widget config", () => {
|
||||
expectWidgetConfigShape(widget);
|
||||
expect(widget.api).toBeUndefined();
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user