GitHubBackupSettings.scheduled.test.tsx 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. /**
  2. * Tests for the Scheduled Local Backup UI in GitHubBackupSettings.
  3. */
  4. import { describe, it, expect, vi, beforeEach } from 'vitest';
  5. import { screen, waitFor } from '@testing-library/react';
  6. import { render } from '../utils';
  7. import { GitHubBackupSettings } from '../../components/GitHubBackupSettings';
  8. import { http, HttpResponse } from 'msw';
  9. import { server } from '../mocks/server';
  10. const mockLocalBackupStatus = {
  11. enabled: true,
  12. schedule: 'daily',
  13. time: '03:00',
  14. retention: 5,
  15. path: '',
  16. default_path: '/data/backups',
  17. is_running: false,
  18. last_backup_at: null,
  19. last_status: null,
  20. last_message: null,
  21. next_run: '2026-04-13T03:00:00+00:00',
  22. };
  23. const mockLocalBackups = [
  24. {
  25. filename: 'bambuddy-backup-20260412-120000.zip',
  26. size: 52428800,
  27. created_at: '2026-04-12T12:00:00+00:00',
  28. },
  29. ];
  30. describe('GitHubBackupSettings - Scheduled Backups', () => {
  31. beforeEach(() => {
  32. vi.clearAllMocks();
  33. server.use(
  34. http.get('/api/v1/local-backup/status', () =>
  35. HttpResponse.json(mockLocalBackupStatus)
  36. ),
  37. http.get('/api/v1/local-backup/backups', () =>
  38. HttpResponse.json(mockLocalBackups)
  39. ),
  40. http.get('/api/v1/github-backup/config', () =>
  41. HttpResponse.json(null)
  42. ),
  43. http.get('/api/v1/github-backup/status', () =>
  44. HttpResponse.json({ configured: false, enabled: false, is_running: false, progress: null, last_backup_at: null, last_backup_status: null, next_scheduled_run: null })
  45. ),
  46. http.get('/api/v1/github-backup/logs', () =>
  47. HttpResponse.json([])
  48. ),
  49. http.get('/api/v1/cloud/status', () =>
  50. HttpResponse.json({ is_authenticated: false })
  51. ),
  52. http.get('/api/v1/printers', () =>
  53. HttpResponse.json([])
  54. ),
  55. http.put('/api/v1/settings/', () =>
  56. HttpResponse.json({})
  57. ),
  58. );
  59. });
  60. it('renders Scheduled Backups card title', async () => {
  61. render(<GitHubBackupSettings />);
  62. await waitFor(() => {
  63. expect(screen.getByText('Scheduled Backups')).toBeInTheDocument();
  64. });
  65. });
  66. it('shows frequency dropdown when enabled', async () => {
  67. render(<GitHubBackupSettings />);
  68. await waitFor(() => {
  69. expect(screen.getByText('Frequency')).toBeInTheDocument();
  70. });
  71. });
  72. it('shows retention input when enabled', async () => {
  73. render(<GitHubBackupSettings />);
  74. await waitFor(() => {
  75. expect(screen.getByText('Retention')).toBeInTheDocument();
  76. });
  77. });
  78. it('shows backup file list', async () => {
  79. render(<GitHubBackupSettings />);
  80. await waitFor(() => {
  81. expect(screen.getByText('bambuddy-backup-20260412-120000.zip')).toBeInTheDocument();
  82. });
  83. });
  84. it('shows file size in MB', async () => {
  85. render(<GitHubBackupSettings />);
  86. await waitFor(() => {
  87. expect(screen.getByText(/50\.0 MB/)).toBeInTheDocument();
  88. });
  89. });
  90. it('shows Run Now button', async () => {
  91. render(<GitHubBackupSettings />);
  92. await waitFor(() => {
  93. expect(screen.getByText('Run Now')).toBeInTheDocument();
  94. });
  95. });
  96. it('shows default path when path is empty', async () => {
  97. render(<GitHubBackupSettings />);
  98. await waitFor(() => {
  99. expect(screen.getByText('/data/backups')).toBeInTheDocument();
  100. });
  101. });
  102. it('hides schedule controls when disabled', async () => {
  103. server.use(
  104. http.get('/api/v1/local-backup/status', () =>
  105. HttpResponse.json({ ...mockLocalBackupStatus, enabled: false })
  106. ),
  107. );
  108. render(<GitHubBackupSettings />);
  109. await waitFor(() => {
  110. expect(screen.getByText('Scheduled Backups')).toBeInTheDocument();
  111. });
  112. expect(screen.queryByText('Frequency')).not.toBeInTheDocument();
  113. expect(screen.queryByText('Run Now')).not.toBeInTheDocument();
  114. });
  115. it('hides time picker when hourly is selected', async () => {
  116. server.use(
  117. http.get('/api/v1/local-backup/status', () =>
  118. HttpResponse.json({ ...mockLocalBackupStatus, schedule: 'hourly' })
  119. ),
  120. );
  121. render(<GitHubBackupSettings />);
  122. await waitFor(() => {
  123. expect(screen.getByText('Frequency')).toBeInTheDocument();
  124. });
  125. expect(screen.queryByText('Time')).not.toBeInTheDocument();
  126. });
  127. });