mirror of
https://github.com/gethomepage/homepage.git
synced 2026-02-08 08:50: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");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user