Files
study-bible-project/src/components/settings/DataSection.test.jsx
T
nmemmertandClaude Sonnet 5.5 5e80d307a7 Count "Download from my account" as a backup for the Home nudge
Only "Download backup" recorded the date, so downloading from the account left
Home saying "You haven't downloaded a backup yet". Both now record it.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-10-14 14:21:20 -04:00

38 lines
1.7 KiB
React

import { render, screen } from '@testing-library/react';
import userEvent from '@testing-library/user-event';
import { vi, test, expect, beforeEach } from 'vitest';
import { AppContext } from '../../context/AppContext.js';
import { ToastProvider } from '../Toasts.jsx';
import { lastBackupAt } from '../../utils/backup.js';
import DataSection from './DataSection.jsx';
const value = {
authUser: { email: 'a@b.test' }, readerBookmarks: {}, readerBookmarkNotes: {}, readerTextHighlights: [], readerColorLabels: {}, readerInkByPage: {},
readingPlansState: { progress: [], customPlans: [], activity: [] }, importReaderMarks: vi.fn(), importReadingPlans: vi.fn(), refreshProjectIndex: vi.fn(), prayers: [], importPrayers: vi.fn(),
};
const setup = () => {
render(<AppContext.Provider value={value}><ToastProvider><DataSection /></ToastProvider></AppContext.Provider>);
return userEvent.setup();
};
beforeEach(() => {
localStorage.clear();
URL.createObjectURL = vi.fn(() => 'blob:x');
URL.revokeObjectURL = vi.fn();
document.addEventListener('click', (e) => { if (e.target.closest?.('a[download]')) e.preventDefault(); }); // no real navigation in the test
});
test('downloading the backup file is remembered, so Home stops asking', async () => {
const user = setup();
expect(lastBackupAt()).toBeNull();
await user.click(screen.getByRole('button', { name: 'Download backup' }));
expect(lastBackupAt()).toBeGreaterThan(Date.now() - 5000);
});
test('downloading from the account is remembered too', async () => {
const user = setup();
expect(lastBackupAt()).toBeNull();
await user.click(screen.getByRole('link', { name: 'Download from my account' }));
expect(lastBackupAt()).toBeGreaterThan(Date.now() - 5000);
});