import 'dart:io'; import 'package:cutdex_core/editor.dart'; import 'package:cutdex_core/project.dart'; import 'package:cutdex_core/timeline/model.dart'; import 'package:flutter_test/flutter_test.dart'; class SavedEditValidation { final _edits = >>{}; Future> capture( String projectPath, String timelineId, EditorSession session, SequenceId sequence, ) async { final edits = await _editingState(session, sequence); _edits.putIfAbsent(projectPath, () => {})[timelineId] = edits; return edits; } Future verify({ required Future Function(Duration) wait, required void Function( String projectPath, String timelineId, Map edits, ) onVerified, }) async { for (final project in _edits.entries) { ProjectFile? reopened; final deadline = DateTime.now().add(const Duration(seconds: 40)); while (reopened == null) { try { reopened = await ProjectFile.open(Directory(project.key)); } on ProjectFileException catch (error) { if (error.code != ProjectFileError.conflict || DateTime.now().isAfter(deadline)) { rethrow; } await wait(const Duration(milliseconds: 100)); } } try { for (final entry in project.value.entries) { final session = EditorSession( document: await reopened.loadTimeline(entry.key), persistence: await reopened.openTimelineSaveSession(entry.key), ); late Map actual; try { actual = await _editingState( session, SequenceId(entry.value['sequenceId'] as String), ); } finally { await session.close(); } expect( actual, entry.value, reason: 'Edited timeline changed after close/reopen', ); onVerified(project.key, entry.key, actual); } } finally { await reopened.close(); } } } Future> _editingState( EditorSession session, SequenceId sequence, ) async { final result = await session.executeCommand( sequence, const QueryTimeline(), ); // History availability and save status describe the current session. return Map.of(result.data) ..remove('canUndo') ..remove('canRedo') ..remove('saveState'); } }