GitHubBackupSettings.scheduled.test.tsx 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  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. timezone: 'Europe/Berlin',
  23. };
  24. const mockLocalBackups = [
  25. {
  26. filename: 'bambuddy-backup-20260412-120000.zip',
  27. size: 52428800,
  28. created_at: '2026-04-12T12:00:00+00:00',
  29. },
  30. ];
  31. describe('GitHubBackupSettings - Scheduled Backups', () => {
  32. beforeEach(() => {
  33. vi.clearAllMocks();
  34. server.use(
  35. http.get('/api/v1/local-backup/status', () =>
  36. HttpResponse.json(mockLocalBackupStatus)
  37. ),
  38. http.get('/api/v1/local-backup/backups', () =>
  39. HttpResponse.json(mockLocalBackups)
  40. ),
  41. http.get('/api/v1/github-backup/config', () =>
  42. HttpResponse.json(null)
  43. ),
  44. http.get('/api/v1/github-backup/status', () =>
  45. HttpResponse.json({ configured: false, enabled: false, is_running: false, progress: null, last_backup_at: null, last_backup_status: null, next_scheduled_run: null })
  46. ),
  47. http.get('/api/v1/github-backup/logs', () =>
  48. HttpResponse.json([])
  49. ),
  50. http.get('/api/v1/cloud/status', () =>
  51. HttpResponse.json({ is_authenticated: false })
  52. ),
  53. http.get('/api/v1/printers', () =>
  54. HttpResponse.json([])
  55. ),
  56. http.put('/api/v1/settings/', () =>
  57. HttpResponse.json({})
  58. ),
  59. );
  60. });
  61. it('renders Scheduled Backups card title', async () => {
  62. render(<GitHubBackupSettings />);
  63. await waitFor(() => {
  64. expect(screen.getByText('Scheduled Backups')).toBeInTheDocument();
  65. });
  66. });
  67. it('shows frequency dropdown when enabled', async () => {
  68. render(<GitHubBackupSettings />);
  69. await waitFor(() => {
  70. expect(screen.getByText('Frequency')).toBeInTheDocument();
  71. });
  72. });
  73. it('shows retention input when enabled', async () => {
  74. render(<GitHubBackupSettings />);
  75. await waitFor(() => {
  76. expect(screen.getByText('Retention')).toBeInTheDocument();
  77. });
  78. });
  79. it('shows backup file list', async () => {
  80. render(<GitHubBackupSettings />);
  81. await waitFor(() => {
  82. expect(screen.getByText('bambuddy-backup-20260412-120000.zip')).toBeInTheDocument();
  83. });
  84. });
  85. it('shows file size in MB', async () => {
  86. render(<GitHubBackupSettings />);
  87. await waitFor(() => {
  88. expect(screen.getByText(/50\.0 MB/)).toBeInTheDocument();
  89. });
  90. });
  91. it('shows Run Now button', async () => {
  92. render(<GitHubBackupSettings />);
  93. await waitFor(() => {
  94. expect(screen.getByText('Run Now')).toBeInTheDocument();
  95. });
  96. });
  97. it('shows default path when path is empty', async () => {
  98. render(<GitHubBackupSettings />);
  99. await waitFor(() => {
  100. expect(screen.getByText('/data/backups')).toBeInTheDocument();
  101. });
  102. });
  103. it('hides schedule controls when disabled', async () => {
  104. server.use(
  105. http.get('/api/v1/local-backup/status', () =>
  106. HttpResponse.json({ ...mockLocalBackupStatus, enabled: false })
  107. ),
  108. );
  109. render(<GitHubBackupSettings />);
  110. await waitFor(() => {
  111. expect(screen.getByText('Scheduled Backups')).toBeInTheDocument();
  112. });
  113. expect(screen.queryByText('Frequency')).not.toBeInTheDocument();
  114. expect(screen.queryByText('Run Now')).not.toBeInTheDocument();
  115. });
  116. it('hides time picker when hourly is selected', async () => {
  117. server.use(
  118. http.get('/api/v1/local-backup/status', () =>
  119. HttpResponse.json({ ...mockLocalBackupStatus, schedule: 'hourly' })
  120. ),
  121. );
  122. render(<GitHubBackupSettings />);
  123. await waitFor(() => {
  124. expect(screen.getByText('Frequency')).toBeInTheDocument();
  125. });
  126. expect(screen.queryByText('Time')).not.toBeInTheDocument();
  127. });
  128. });