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.

3.9 KB
Raw Blame
import { describe, expect, it } from 'vitest';
import {
  getSystemLogBufferSummary,
  getSystemLogLineClass,
  getSystemLogStreamPresentation,
  SYSTEM_LOG_LEVEL_OPTIONS,
  SYSTEM_LOGS_PANEL_COPY,
} from '@/utils/systemLogsPresentation';

describe('systemLogsPresentation', () => {
  it('returns canonical system logs panel copy and level options', () => {
    expect(SYSTEM_LOGS_PANEL_COPY).toEqual({
      title: 'System Logs',
      description: 'Stream live system logs and download support bundles.',
      levelLabel: 'Server Log Level:',
      levelHelp:
        'Changes logging for the whole Pulse server. Debug can include private guest names and paths. Keep the current level unless needed.',
      displayHelp:
        'Pause and Clear affect this display only. Monitoring and server logging continue. This is not a backup safety pause. Messages received while paused are not added to the display.',
      bundleHelp:
        'Support bundles include server logs, configuration and environment details, not just the lines shown here. Pausing or clearing this display does not remove them. Keep the archive private. Share only manually reviewed, redacted excerpts.',
      clearTitle: 'Clear Log Output',
      downloadLabel: 'Support Bundle',
      emptyState: 'Waiting for log output.',
      unavailableState: 'No current log output.',
      connectionError:
        'Log access could not be confirmed. Buffered lines were cleared. Reconnect to try again.',
      readerChanged:
        'The reader or workspace changed. Buffered lines were cleared. Reconnect to read current logs.',
      reconnecting:
        'The log connection was interrupted. Buffered lines were cleared while the stream reconnects.',
      levelError:
        'The log level change could not be confirmed. Buffered lines were cleared. Reconnect to check the current level.',
      bufferHelp:
        'This view keeps only the latest 1,000 received lines. Paused lines are not collected. Clearing the view does not delete server logs.',
    });
    expect(SYSTEM_LOG_LEVEL_OPTIONS).toEqual([
      { value: 'debug', label: 'Debug' },
      { value: 'info', label: 'Info' },
      { value: 'warn', label: 'Warn' },
      { value: 'error', label: 'Error' },
    ]);
  });

  it('maps log severity text to canonical classes', () => {
    expect(getSystemLogLineClass('{"level":"error","msg":"boom"}')).toBe('text-red-400');
    expect(getSystemLogLineClass('[WARN] something odd')).toBe('text-amber-400');
    expect(getSystemLogLineClass('DBG refresh loop')).toBe('text-blue-400');
    expect(getSystemLogLineClass('plain info log')).toBe('text-slate-300');
  });

  it('maps live and paused stream state to canonical presentation', () => {
    expect(getSystemLogStreamPresentation(false)).toEqual({
      indicatorClass: 'bg-emerald-400 animate-pulse',
      label: 'Streaming',
      pauseButtonClass: 'hover:bg-surface-hover text-muted',
      toggleTitle: 'Pause Stream',
    });
    expect(getSystemLogStreamPresentation(true)).toEqual({
      indicatorClass: 'bg-amber-400',
      label: 'Paused',
      pauseButtonClass: 'bg-amber-100 text-amber-600 dark:bg-amber-900/25 dark:text-amber-400',
      toggleTitle: 'Resume Stream',
    });
  });

  it('gives connection loss precedence over display state without changing Pause/Resume controls', () => {
    for (const [connection, label] of [
      ['connecting', 'Connecting'],
      ['reconnecting', 'Reconnecting'],
      ['disconnected', 'Disconnected'],
    ] as const) {
      for (const paused of [false, true]) {
        const result = getSystemLogStreamPresentation(paused, connection);
        expect(result.label).toBe(label + (paused ? ' · paused' : ''));
        expect(result.indicatorClass).not.toContain('emerald');
        expect(result.toggleTitle).toBe(paused ? 'Resume Stream' : 'Pause Stream');
      }
    }
  });

  it('formats the canonical log buffer summary', () => {
    expect(getSystemLogBufferSummary(24, 500)).toBe('Buffer: 24 / 500 lines');
  });
});