SystemHealthPanel.test.tsx 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. /**
  2. * Tests for SystemHealthPanel — the shared log-health result renderer used by
  3. * the System page and the bug reporter.
  4. *
  5. * Covers the three states (clean / log unavailable / findings) and that a
  6. * finding renders its localized name, cause, fix, category badge, and a wiki
  7. * deep-link built from the signature's anchor.
  8. */
  9. import { describe, it, expect } from 'vitest';
  10. import { render, screen } from '@testing-library/react';
  11. import { I18nextProvider } from 'react-i18next';
  12. import i18n from '../../i18n';
  13. import { SystemHealthPanel } from '../../components/SystemHealthPanel';
  14. import type { SystemHealthResult } from '../../api/client';
  15. function renderPanel(result: SystemHealthResult) {
  16. render(
  17. <I18nextProvider i18n={i18n}>
  18. <SystemHealthPanel result={result} />
  19. </I18nextProvider>,
  20. );
  21. }
  22. const BASE: SystemHealthResult = {
  23. findings: [],
  24. scanned_entries: 1200,
  25. log_available: true,
  26. summary: { total: 0, layer8: 0, environment: 0, bug: 0 },
  27. };
  28. describe('SystemHealthPanel', () => {
  29. it('shows a healthy message when there are no findings', () => {
  30. renderPanel(BASE);
  31. expect(screen.getByText(/No known issues found/i)).toBeInTheDocument();
  32. });
  33. it('shows a notice when file logging is unavailable', () => {
  34. renderPanel({ ...BASE, log_available: false });
  35. expect(screen.getByText(/File logging is disabled/i)).toBeInTheDocument();
  36. });
  37. it('renders a finding with localized name, cause, fix, badge, and wiki link', () => {
  38. renderPanel({
  39. ...BASE,
  40. log_available: true,
  41. findings: [
  42. {
  43. signature_id: 'ftp-auth-rejected',
  44. severity: 'error',
  45. category: 'layer8',
  46. wiki_anchor: 'wrong-access-code',
  47. count: 4,
  48. first_seen: '2026-05-22 09:00:00,000',
  49. last_seen: '2026-05-22 10:00:00,000',
  50. sample: 'FTP connection permission error to [IP]',
  51. },
  52. ],
  53. summary: { total: 1, layer8: 1, environment: 0, bug: 0 },
  54. });
  55. expect(screen.getByText('Printer rejected the access code')).toBeInTheDocument();
  56. expect(screen.getByText(/refused the file-transfer login/i)).toBeInTheDocument();
  57. expect(screen.getByText(/Re-copy the access code/i)).toBeInTheDocument();
  58. expect(screen.getByText('You can fix this')).toBeInTheDocument();
  59. expect(screen.getByText('FTP connection permission error to [IP]')).toBeInTheDocument();
  60. const link = screen.getByRole('link', { name: /How to fix/i });
  61. expect(link).toHaveAttribute(
  62. 'href',
  63. 'https://wiki.bambuddy.cool/reference/troubleshooting/#wrong-access-code',
  64. );
  65. });
  66. });