Skip to content

armgit / Pulse

Public Imported from GitHub
0

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.

5.7 KB
Raw Blame
import { describe, expect, it } from 'vitest';
import {
  BACKUP_INTERVAL_MAX_MINUTES,
  BACKUP_INTERVAL_OPTIONS,
  COMMON_DISCOVERY_SUBNETS,
  DOCKER_UPDATE_ACTIONS_ENV_VAR,
  DOCKER_UPDATE_ACTIONS_SECTION_DESCRIPTION,
  DOCKER_UPDATE_ACTIONS_SECTION_TITLE,
  DOCKER_UPDATE_ACTIONS_TOGGLE_DESCRIPTION,
  DOCKER_UPDATE_ACTIONS_TOGGLE_LABEL,
  formatPvePollingDuration,
  getBackupIntervalSelectValue,
  getBackupIntervalSummary,
  getCheckForUpdatesErrorMessage,
  getDockerUpdateActionsPresentation,
  getDockerUpdateActionsUpdateErrorMessage,
  getHideLocalLoginUpdateErrorMessage,
  getPvePollingCadenceSummary,
  getPvePollingCustomOption,
  getPvePollingPresetOptions,
  getStartUpdateErrorMessage,
  getSystemSettingsSaveErrorMessage,
  getTelemetryUpdateErrorMessage,
  getTemperatureMonitoringUpdateErrorMessage,
  PVE_POLLING_MAX_SECONDS,
  PVE_POLLING_MIN_SECONDS,
  PVE_POLLING_PRESETS,
} from '@/utils/systemSettingsPresentation';

describe('systemSettingsPresentation', () => {
  it('exports canonical PVE polling bounds and presets', () => {
    expect(PVE_POLLING_MIN_SECONDS).toBe(10);
    expect(PVE_POLLING_MAX_SECONDS).toBe(3600);
    expect(PVE_POLLING_PRESETS).toEqual([
      { label: 'Realtime (10s)', value: 10 },
      { label: 'Balanced (30s)', value: 30 },
      { label: 'Low (60s)', value: 60 },
      { label: 'Very low (5m)', value: 300 },
    ]);
  });

  it('exports canonical backup interval options and max custom minutes', () => {
    expect(BACKUP_INTERVAL_OPTIONS).toEqual([
      { value: 0, label: 'Default (~90s)' },
      { value: 300, label: '5 minutes' },
      { value: 900, label: '15 minutes' },
      { value: 1800, label: '30 minutes' },
      { value: 3600, label: '1 hour' },
      { value: 21600, label: '6 hours' },
      { value: 86400, label: '24 hours' },
    ]);
    expect(BACKUP_INTERVAL_MAX_MINUTES).toBe(7 * 24 * 60);
  });

  it('exports canonical common discovery subnet suggestions', () => {
    expect(COMMON_DISCOVERY_SUBNETS).toEqual([
      '192.168.1.0/24',
      '192.168.0.0/24',
      '10.0.0.0/24',
      '172.16.0.0/24',
      '192.168.10.0/24',
    ]);
  });

  it('exports canonical Docker and Podman update-action settings copy', () => {
    expect(DOCKER_UPDATE_ACTIONS_ENV_VAR).toBe('PULSE_DISABLE_DOCKER_UPDATE_ACTIONS');
    expect(DOCKER_UPDATE_ACTIONS_SECTION_TITLE).toBe('Docker / Podman updates');
    expect(DOCKER_UPDATE_ACTIONS_SECTION_DESCRIPTION).toBe(
      'Control how Docker / Podman update actions appear across Pulse.',
    );
    expect(DOCKER_UPDATE_ACTIONS_TOGGLE_LABEL).toBe('Hide update buttons');
    expect(DOCKER_UPDATE_ACTIONS_TOGGLE_DESCRIPTION).toBe(
      'When enabled, Docker / Podman "Update" actions are hidden across Pulse. Update detection still runs, so available updates remain visible.',
    );
  });

  it('localizes migrated general settings polling copy without changing machine units', () => {
    expect(getPvePollingPresetOptions('de')).toEqual([
      { label: 'Echtzeit (10s)', value: 10 },
      { label: 'Ausgewogen (30s)', value: 30 },
      { label: 'Niedrig (60s)', value: 60 },
      { label: 'Sehr niedrig (5m)', value: 300 },
    ]);
    expect(getPvePollingCustomOption('es')).toEqual({
      label: 'Personalizado',
      value: 'custom',
    });
    expect(formatPvePollingDuration(90, 'de')).toBe('1,5 Minuten');
    expect(getPvePollingCadenceSummary(30, 'es')).toBe(
      'Cadencia actual: 30 segundos (menos de un minuto)',
    );
  });

  it('localizes Docker update-action copy while preserving product and command tokens', () => {
    expect(getDockerUpdateActionsPresentation('de')).toMatchObject({
      sectionTitle: 'Docker / Podman-Updates',
      toggleLabel: 'Update-Schaltflaechen ausblenden',
    });
    expect(getDockerUpdateActionsPresentation('es').toggleDescription).toContain(
      'acciones "Update" de Docker / Podman',
    );
  });

  it('returns canonical backup interval select values', () => {
    expect(getBackupIntervalSelectValue(false, 0)).toBe('0');
    expect(getBackupIntervalSelectValue(false, 300)).toBe('300');
    expect(getBackupIntervalSelectValue(false, 123)).toBe('custom');
    expect(getBackupIntervalSelectValue(true, 300)).toBe('custom');
  });

  it('returns canonical backup interval summaries', () => {
    expect(getBackupIntervalSummary(false, 0)).toBe('Backup polling is disabled.');
    expect(getBackupIntervalSummary(true, 0)).toBe(
      'Pulse checks backups and snapshots at the default cadence (~every 90 seconds).',
    );
    expect(getBackupIntervalSummary(true, 3600)).toBe('Pulse checks backups every hour.');
    expect(getBackupIntervalSummary(true, 7200)).toBe('Pulse checks backups every 2 hours.');
    expect(getBackupIntervalSummary(true, 86400)).toBe('Pulse checks backups every day.');
    expect(getBackupIntervalSummary(true, 172800)).toBe('Pulse checks backups every 2 days.');
    expect(getBackupIntervalSummary(true, 900)).toBe('Pulse checks backups every 15 minutes.');
  });

  it('returns canonical system settings operational failure copy', () => {
    expect(getSystemSettingsSaveErrorMessage()).toBe('Unable to save settings.');
    expect(getSystemSettingsSaveErrorMessage('forbidden')).toBe('forbidden');
    expect(getHideLocalLoginUpdateErrorMessage()).toBe('Unable to update local login visibility.');
    expect(getDockerUpdateActionsUpdateErrorMessage()).toBe(
      'Unable to update Docker / Podman update actions.',
    );
    expect(getTelemetryUpdateErrorMessage()).toBe('Unable to update outbound usage telemetry.');
    expect(getTemperatureMonitoringUpdateErrorMessage()).toBe(
      'Unable to update temperature monitoring.',
    );
    expect(getCheckForUpdatesErrorMessage()).toBe('Unable to check for updates.');
    expect(getStartUpdateErrorMessage()).toBe('Unable to start the update. Please try again.');
  });
});