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.4 KB
Raw Blame
import { cleanup, fireEvent, render, screen } from '@solidjs/testing-library';
import { afterEach, describe, expect, it, vi } from 'vitest';
import { createSignal } from 'solid-js';
import { RecoverySettingsPanel } from '../RecoverySettingsPanel';

function renderRecovery() {
  const [enabled, setEnabled] = createSignal(true);
  const [interval, setInterval] = createSignal(300);
  const [minutes, setMinutes] = createSignal(5);
  const [custom, setCustom] = createSignal(false);
  const [, setUnsaved] = createSignal(false);
  const setShowExportDialog = vi.fn();
  const setShowImportDialog = vi.fn();
  render(() => (
    <RecoverySettingsPanel
      backupPollingEnabled={enabled}
      setBackupPollingEnabled={setEnabled}
      backupPollingInterval={interval}
      setBackupPollingInterval={setInterval}
      backupPollingCustomMinutes={minutes}
      setBackupPollingCustomMinutes={setMinutes}
      backupPollingUseCustom={custom}
      setBackupPollingUseCustom={setCustom}
      backupPollingEnvLocked={() => false}
      backupIntervalSelectValue={() => String(interval())}
      backupIntervalSummary={() => 'Every 5 minutes'}
      setHasUnsavedChanges={setUnsaved}
      showExportDialog={() => false}
      setShowExportDialog={setShowExportDialog}
      showImportDialog={() => false}
      setShowImportDialog={setShowImportDialog}
    />
  ));
  return { setShowExportDialog, setShowImportDialog };
}

describe('RecoverySettingsPanel', () => {
  afterEach(cleanup);

  it('discloses the limited archive scope before either transfer is opened', () => {
    renderRecovery();
    const text = document.body.textContent;
    expect(text).toContain('selected workspace, not a full-server backup');
    expect(text).toContain('Proxmox connections & credentials');
    expect(text).toContain(
      'History, TrueNAS/vSphere connections, local login credentials and agent enrolment state are not included',
    );
    expect(text).not.toContain('All node connections');
    expect(screen.queryByRole('dialog')).not.toBeInTheDocument();
    const guide = screen.getByRole('link', { name: 'migration guide' });
    expect(guide).toHaveAttribute('href', '/docs/MIGRATION');
    expect(guide).toHaveAttribute('target', '_blank');
    expect(guide).toHaveAttribute('rel', 'noopener noreferrer');
  });

  it('warns that restoring replaces included settings rather than offering a merge', () => {
    renderRecovery();
    const text = document.body.textContent;
    expect(text).toContain('Back up the destination first');
    expect(text).toContain('Replaces included settings and API-token records');
    expect(text).not.toContain('Merge or replace');
    expect(screen.getByRole('button', { name: 'Restore Backup' })).toBeEnabled();
  });

  it('opens only the export dialog without selecting a login-credential mode', () => {
    const actions = renderRecovery();
    fireEvent.click(screen.getByRole('button', { name: 'Create Backup' }));
    expect(actions.setShowExportDialog).toHaveBeenCalledExactlyOnceWith(true);
    expect(actions.setShowImportDialog).not.toHaveBeenCalled();
  });

  it('opens only the existing import dialog from Restore Backup', () => {
    const actions = renderRecovery();
    fireEvent.click(screen.getByRole('button', { name: 'Restore Backup' }));
    expect(actions.setShowImportDialog).toHaveBeenCalledExactlyOnceWith(true);
    expect(actions.setShowExportDialog).not.toHaveBeenCalled();
  });
});