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.

2.2 KB
Raw Blame
import { cleanup, fireEvent, render, screen } from '@solidjs/testing-library';
import { Route, Router } from '@solidjs/router';
import type { JSX } from 'solid-js';
import { afterEach, describe, expect, it, vi } from 'vitest';
import { AlertPushDestinationsSection } from './AlertPushDestinationsSection';
import {
  ALERT_DESTINATIONS_PUSH_MINIMUM_SEVERITY_HELP,
  ALERT_DESTINATIONS_PUSH_READY_MESSAGE,
  ALERT_DESTINATIONS_PUSH_SETUP_LINK_LABEL,
} from '@/utils/alertDestinationsPresentation';

function renderWithRouter(ui: () => JSX.Element) {
  return render(() => (
    <Router>
      <Route path="/" component={ui} />
    </Router>
  ));
}

describe('AlertPushDestinationsSection', () => {
  afterEach(() => {
    cleanup();
  });

  it('points licensed installs at Pulse Mobile settings', () => {
    const onMinimumSeverityChange = vi.fn();
    renderWithRouter(() => (
      <AlertPushDestinationsSection
        relayLicensed={true}
        minimumSeverity="critical"
        onMinimumSeverityChange={onMinimumSeverityChange}
      />
    ));

    expect(screen.getByText(ALERT_DESTINATIONS_PUSH_READY_MESSAGE)).toBeInTheDocument();
    const link = screen.getByRole('link', {
      name: `${ALERT_DESTINATIONS_PUSH_SETUP_LINK_LABEL} →`,
    });
    expect(link).toHaveAttribute('href', '/settings/system-relay');

    const severity = screen.getByRole('combobox', { name: 'Minimum alert severity' });
    expect(severity).toHaveValue('critical');
    expect(
      screen.queryByRole('option', { name: 'Warnings and critical alerts' }),
    ).not.toBeInTheDocument();
    fireEvent.change(severity, { target: { value: 'all' } });
    expect(onMinimumSeverityChange).toHaveBeenCalledWith('all');
    expect(screen.getByText(ALERT_DESTINATIONS_PUSH_MINIMUM_SEVERITY_HELP)).toBeInTheDocument();
  });

  it('renders nothing for installs without Pulse Mobile, since it is no longer sold', () => {
    renderWithRouter(() => <AlertPushDestinationsSection relayLicensed={false} />);

    expect(screen.queryByText(ALERT_DESTINATIONS_PUSH_READY_MESSAGE)).not.toBeInTheDocument();
    expect(screen.queryByText(/Relay/)).not.toBeInTheDocument();
    expect(screen.queryByRole('link')).not.toBeInTheDocument();
  });
});