Real-time monitoring dashboard for Proxmox VE, PBS, Docker, Kubernetes, TrueNAS and vSphere. Self-hosted, with alerts for failed backups, full disks, unhealthy containers and offline nodes.
Go aialertsdashboarddockerdocker-monitoringgohomelabinfrastructure-monitoringkubernetesmonitoringmspproxmoxproxmox-backup-serverproxmox-mail-gatewayproxmox-veself-hostedtruenastypescriptvspherewebhooks
import { describe, expect, it } from 'vitest';
import { temperatureStore } from '@/utils/temperature';
import type { PhysicalDiskPresentationData } from '@/features/storageBackups/diskPresentation';
import {
getDiskDetailAttributeCards,
getLinkedDiskTemperatureTextClass,
} from '@/features/storageBackups/diskDetailPresentation';
function makeDiskData(
overrides: Partial<PhysicalDiskPresentationData> = {},
): PhysicalDiskPresentationData {
return {
node: '',
instance: '',
devPath: '',
model: '',
serial: '',
wwn: '',
size: 0,
health: 'UNKNOWN',
riskReasons: [],
wearout: -1,
type: '',
temperature: 0,
rpm: 0,
used: '',
...overrides,
};
}
describe('diskDetailPresentation.branchcov0724pm', () => {
describe('getLinkedDiskTemperatureTextClass non-positive / non-finite guard (L20)', () => {
it('returns text-muted for NaN temperature', () => {
expect(getLinkedDiskTemperatureTextClass(NaN)).toBe('text-muted');
});
it('returns text-muted for zero temperature', () => {
expect(getLinkedDiskTemperatureTextClass(0)).toBe('text-muted');
});
it('short-circuits before consulting thresholds when the guard trips', () => {
// 0 would be flagged critical by these inverted thresholds, but the
// guard returns text-muted without ever calling getMetricSeverity.
expect(getLinkedDiskTemperatureTextClass(0, { warning: -10, critical: -5 })).toBe(
'text-muted',
);
});
});
describe('getDiskDetailAttributeCards empty-collection guard (L86)', () => {
it('returns an empty array when smartAttributes is absent', () => {
expect(getDiskDetailAttributeCards(makeDiskData({ type: 'hdd' }))).toEqual([]);
});
});
describe('independently reported temperature', () => {
it.each(['hdd', 'ssd', 'nvme'])('shows %s temperature without extended SMART data', (type) => {
expect(getDiskDetailAttributeCards(makeDiskData({ type, temperature: 42 }))).toEqual([
{ label: 'Temperature', value: '42°C', ok: true },
]);
});
it.each([0, -1, NaN, Infinity, -Infinity])('does not invent a card for %s', (temperature) => {
expect(getDiskDetailAttributeCards(makeDiskData({ temperature }))).toEqual([]);
});
it('keeps configured thresholds and display units independent of attribute presence', () => {
const disk = makeDiskData({ type: 'nvme', temperature: 65 });
expect(getDiskDetailAttributeCards(disk, { warning: 70, critical: 80 })).toEqual([
{ label: 'Temperature', value: '65°C', ok: true },
]);
temperatureStore.setUnit('fahrenheit');
try {
expect(getDiskDetailAttributeCards(disk, { warning: 50, critical: 60 })).toEqual([
{ label: 'Temperature', value: '149°F', ok: false },
]);
} finally {
temperatureStore.setUnit('celsius');
}
});
it('treats empty and missing SMART data alike without inventing counters', () => {
const disk = makeDiskData({ temperature: 42 });
expect(getDiskDetailAttributeCards({ ...disk, smartAttributes: {} })).toEqual(
getDiskDetailAttributeCards(disk),
);
});
});
describe('getDiskDetailAttributeCards SATA offlineUncorrectable arm (L129)', () => {
it('emits an Offline Uncorrectable card marked ok when the count is zero', () => {
const cards = getDiskDetailAttributeCards(
makeDiskData({ type: 'hdd', smartAttributes: { offlineUncorrectable: 0 } }),
);
expect(cards).toContainEqual({
label: 'Offline Uncorrectable',
value: '0',
ok: true,
});
});
it('emits an Offline Uncorrectable card marked not-ok when the count is non-zero', () => {
const cards = getDiskDetailAttributeCards(
makeDiskData({ type: 'hdd', smartAttributes: { offlineUncorrectable: 7 } }),
);
expect(cards).toContainEqual({
label: 'Offline Uncorrectable',
value: '7',
ok: false,
});
});
it('omits the Offline Uncorrectable card for an NVMe disk even when the field is set', () => {
const cards = getDiskDetailAttributeCards(
makeDiskData({ type: 'nvme', smartAttributes: { offlineUncorrectable: 7 } }),
);
expect(cards.find((c) => c.label === 'Offline Uncorrectable')).toBeUndefined();
});
});
describe('getDiskDetailAttributeCards SATA udmaCrcErrors arm (L136)', () => {
it('emits a CRC Errors card marked ok when the count is zero', () => {
const cards = getDiskDetailAttributeCards(
makeDiskData({ type: 'hdd', smartAttributes: { udmaCrcErrors: 0 } }),
);
expect(cards).toContainEqual({ label: 'CRC Errors', value: '0', ok: true });
});
it('emits a CRC Errors card marked not-ok when the count is non-zero', () => {
const cards = getDiskDetailAttributeCards(
makeDiskData({ type: 'hdd', smartAttributes: { udmaCrcErrors: 42 } }),
);
expect(cards).toContainEqual({ label: 'CRC Errors', value: '42', ok: false });
});
});
});