fix: quick wins — calendar, about, glances, admin UX, releases, iframe, notes (#6116)
This commit is contained in:
1 parent
b83c8b6546
commit
f9da71a19b
16 files changed
+283
-67
No files matched your search
@@ -1,11 +1,11 @@
|
||||
// @vitest-environment node
|
||||
|
||||
import { describe, expect, test, vi } from "vitest";
|
||||
import { beforeEach, describe, expect, test, vi } from "vitest";
|
||||
|
||||
import { createDb } from "@homarr/db/test";
|
||||
import { fetchWithTrustedCertificatesAsync } from "@homarr/core/infrastructure/http";
|
||||
|
||||
import { GlancesIntegration } from "../src/glances/glances-integration";
|
||||
import { GlancesIntegration, parseGlancesCpuTempFromSensors } from "../src/glances/glances-integration";
|
||||
|
||||
// ─── module mocks ────────────────────────────────────────────────────────────
|
||||
|
||||
@@ -64,6 +64,19 @@ function makeResponse(body: unknown) {
|
||||
} as never;
|
||||
}
|
||||
|
||||
function mockGlancesFetch(statsBody: unknown, sensorsBody: unknown) {
|
||||
mockFetch.mockImplementation(((url: string | URL) => {
|
||||
const urlString = url.toString();
|
||||
if (urlString.endsWith("/api/4/all")) {
|
||||
return Promise.resolve(makeResponse(statsBody));
|
||||
}
|
||||
if (urlString.endsWith("/api/4/sensors")) {
|
||||
return Promise.resolve(makeResponse(sensorsBody));
|
||||
}
|
||||
return Promise.reject(new Error(`Unexpected fetch URL: ${urlString}`));
|
||||
}) as typeof fetchWithTrustedCertificatesAsync);
|
||||
}
|
||||
|
||||
const integrationInput = {
|
||||
id: "test-glances",
|
||||
name: "Glances",
|
||||
@@ -75,8 +88,12 @@ const integrationInput = {
|
||||
// ─── tests ───────────────────────────────────────────────────────────────────
|
||||
|
||||
describe("GlancesIntegration schema", () => {
|
||||
beforeEach(() => {
|
||||
mockFetch.mockReset();
|
||||
});
|
||||
|
||||
test("parses stats when quicklook is present", async () => {
|
||||
mockFetch.mockResolvedValueOnce(makeResponse({ ...baseStats, quicklook: { cpu_name: "Apple M1" } }));
|
||||
mockGlancesFetch({ ...baseStats, quicklook: { cpu_name: "Apple M1" } }, []);
|
||||
|
||||
const integration = new GlancesIntegration(integrationInput);
|
||||
const result = await integration.getSystemInfoAsync();
|
||||
@@ -86,7 +103,7 @@ describe("GlancesIntegration schema", () => {
|
||||
});
|
||||
|
||||
test("returns Unknown cpuModelName when quicklook is absent (macOS scenario)", async () => {
|
||||
mockFetch.mockResolvedValueOnce(makeResponse(baseStats));
|
||||
mockGlancesFetch(baseStats, []);
|
||||
|
||||
const integration = new GlancesIntegration(integrationInput);
|
||||
const result = await integration.getSystemInfoAsync();
|
||||
@@ -95,9 +112,41 @@ describe("GlancesIntegration schema", () => {
|
||||
});
|
||||
|
||||
test("does not throw a Zod parse error when quicklook is missing", async () => {
|
||||
mockFetch.mockResolvedValueOnce(makeResponse(baseStats));
|
||||
mockGlancesFetch(baseStats, []);
|
||||
|
||||
const integration = new GlancesIntegration(integrationInput);
|
||||
await expect(integration.getSystemInfoAsync()).resolves.not.toThrow();
|
||||
});
|
||||
|
||||
test("reads CPU temperature from sensors", async () => {
|
||||
mockGlancesFetch(baseStats, [
|
||||
{ label: "CPU", unit: "C", value: 58, type: "temperature_core" },
|
||||
{ label: "Core 0", unit: "C", value: 54, type: "temperature_core" },
|
||||
]);
|
||||
|
||||
const integration = new GlancesIntegration(integrationInput);
|
||||
const result = await integration.getSystemInfoAsync();
|
||||
|
||||
expect(result.cpuTemp).toBe(58);
|
||||
});
|
||||
});
|
||||
|
||||
describe("parseGlancesCpuTempFromSensors", () => {
|
||||
test("prefers CPU label over core sensors", () => {
|
||||
const result = parseGlancesCpuTempFromSensors([
|
||||
{ label: "Core 0", value: 54, type: "temperature_core" },
|
||||
{ label: "CPU", value: 58, type: "temperature_core" },
|
||||
]);
|
||||
|
||||
expect(result).toBe(58);
|
||||
});
|
||||
|
||||
test("falls back to Package id 0", () => {
|
||||
const result = parseGlancesCpuTempFromSensors([
|
||||
{ label: "Core 0", value: 54, type: "temperature_core" },
|
||||
{ label: "Package id 0", value: 62, type: "temperature_core" },
|
||||
]);
|
||||
|
||||
expect(result).toBe(62);
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,76 @@
|
||||
// @vitest-environment node
|
||||
|
||||
import { describe, expect, test, vi } from "vitest";
|
||||
|
||||
import { createDb } from "@homarr/db/test";
|
||||
import { fetchWithTrustedCertificatesAsync } from "@homarr/core/infrastructure/http";
|
||||
|
||||
import { LidarrIntegration } from "../src/media-organizer/lidarr/lidarr-integration";
|
||||
|
||||
vi.mock("@homarr/db", async (importActual) => {
|
||||
const actual = await importActual<typeof import("@homarr/db")>();
|
||||
return { ...actual, db: createDb() };
|
||||
});
|
||||
|
||||
vi.mock("@homarr/core/infrastructure/certificates", async (importActual) => {
|
||||
const actual = await importActual<typeof import("@homarr/core/infrastructure/certificates")>();
|
||||
return {
|
||||
...actual,
|
||||
getTrustedCertificateHostnamesAsync: vi.fn().mockResolvedValue([]),
|
||||
};
|
||||
});
|
||||
|
||||
vi.mock("@homarr/core/infrastructure/http", () => ({
|
||||
fetchWithTrustedCertificatesAsync: vi.fn(),
|
||||
}));
|
||||
|
||||
const mockFetch = vi.mocked(fetchWithTrustedCertificatesAsync);
|
||||
|
||||
const integrationInput = {
|
||||
id: "test-lidarr",
|
||||
name: "Lidarr",
|
||||
url: "http://localhost:8686",
|
||||
decryptedSecrets: [{ kind: "apiKey" as const, value: "test-key" }],
|
||||
externalUrl: null,
|
||||
};
|
||||
|
||||
describe("LidarrIntegration calendar", () => {
|
||||
test("includes Lidarr artist link in calendar events", async () => {
|
||||
mockFetch.mockResolvedValueOnce({
|
||||
ok: true,
|
||||
json: () =>
|
||||
Promise.resolve([
|
||||
{
|
||||
title: "Test Album",
|
||||
overview: "Overview",
|
||||
images: [],
|
||||
artist: {
|
||||
artistName: "Test Artist",
|
||||
titleSlug: "test-artist",
|
||||
links: [{ name: "last", url: "https://last.fm/music/Test+Artist" }],
|
||||
},
|
||||
releaseDate: "2026-01-01T00:00:00Z",
|
||||
},
|
||||
]),
|
||||
} as never);
|
||||
|
||||
const integration = new LidarrIntegration(integrationInput);
|
||||
const events = await integration.getCalendarEventsAsync(new Date("2026-01-01"), new Date("2026-01-31"));
|
||||
|
||||
expect(events[0]?.links[0]).toMatchObject({
|
||||
name: "Lidarr",
|
||||
href: "http://localhost:8686/artist/test-artist",
|
||||
logo: "/images/apps/lidarr.svg",
|
||||
});
|
||||
// The existing external artist link must survive the Lidarr-link prepend.
|
||||
expect(events[0]?.links).toEqual(
|
||||
expect.arrayContaining([
|
||||
expect.objectContaining({
|
||||
name: "LastFM",
|
||||
href: "https://last.fm/music/Test+Artist",
|
||||
logo: "/images/apps/lastfm.svg",
|
||||
}),
|
||||
]),
|
||||
);
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user