import { screen } from '@testing-library/react'; import { describe, test, expect } from 'vitest'; import { installAppLifecycle, loadChapter, addChunk } from './appHarness.jsx'; import { loadProjectIndex } from '../utils/bibleUtils.jsx'; import { loadProjectById } from '../utils/projectStorage.js'; import { unsyncedStudies } from '../utils/syncQueue.js'; installAppLifecycle(); describe('Autosave', () => { test('leaving a study straight after an edit still saves it (no waiting for the 1-second timer)', async () => { const user = await loadChapter(); addChunk('Paul, a servant', 'In hope of eternal'); await screen.findByText('1 created'); await user.click(screen.getByRole('button', { name: /bible study home|back to home/i })); await screen.findByText('My Studies'); const [entry] = loadProjectIndex(); expect(entry).toBeTruthy(); expect(loadProjectById(entry.id).chapters[0].chunks).toHaveLength(1); }); test('a saved study is queued for the server until the server accepts it', async () => { const user = await loadChapter(); addChunk('Paul, a servant', 'In hope of eternal'); await screen.findByText('1 created'); await user.click(screen.getByRole('button', { name: /bible study home|back to home/i })); await screen.findByText('My Studies'); // the mocked server is unreachable in these tests, so the study stays on the "not yet synced" list expect(unsyncedStudies.list()).toContain(loadProjectIndex()[0].id); }); });