Files
cutdex/test/timeline_switch_presentation_test.dart
T
lingjhf 06f1c26681
Gitea CI / Assemble and validate CI artifacts (push) Successful in 1m47s
Gitea CI / Check code and tests (push) Successful in 7m15s
Gitea CI / Build Android APK (push) Successful in 4m6s
Gitea CI / Build Windows x64 app (push) Successful in 3m34s
Gitea CI / Audit and package Windows x64 (push) Successful in 1m29s
Gitea CI / Gitea CI passed (push) Successful in 1s
Gitea Release / Prepare draft Release (push) Failing after 8s
Gitea Release / Upload Android to draft Release (push) Skipped
Gitea Release / Upload Windows to draft Release (push) Skipped
Gitea Release / Verify and publish Release (push) Skipped
Move editor UI into the app and release verified Core dependencies (#14)
2026-10-11 19:59:40 +00:00

227 lines
8.2 KiB
Dart
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import 'package:cutdex/features/projects/projects_page.dart';
import 'dart:async';
import 'package:cutdex/app/app.dart';
import 'package:cutdex/features/editor/editor_panel_defaults.dart';
import 'package:cutdex/features/preview/preview_panel.dart';
import 'package:cutdex/features/properties/project_properties.dart';
import 'package:cutdex/integrations/agent/conversation_repository.dart';
import 'package:cutdex/integrations/platform/device_experience.dart';
import 'package:cutdex/persistence/app_database.dart';
import 'package:cutdex/persistence/app_settings_repositories.dart';
import 'package:cutdex/workspace/media_availability.dart';
import 'package:cutdex/workspace/project_state.dart';
import 'package:cutdex/workspace/projects.dart';
import 'package:cutdex/workspace/timeline_provider.dart';
import 'package:cutdex_core/project.dart';
import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:drift/native.dart';
import 'support/empty_conversation_repository.dart';
import 'support/memory_app_settings.dart';
import 'support/preview_fixture.dart';
void main() {
testWidgets(
'timeline navigation retains panels through preparation and failure',
(tester) async {
tester.view.physicalSize = const Size(1800, 900);
tester.view.devicePixelRatio = 1;
addTearDown(tester.view.resetPhysicalSize);
addTearDown(tester.view.resetDevicePixelRatio);
final first = (await tester.runAsync(
() => createPreviewFixture(
Uri.file('/test/first.png'),
mediaType: 'image',
),
))!;
final second = (await tester.runAsync(
() => createPreviewFixture(
Uri.file('/test/second.png'),
mediaType: 'image',
renderSize: {'width': 1920, 'height': 1080},
),
))!;
final projects = _DelayedTimelineProjects();
final database = AppDatabase(NativeDatabase.memory());
final container = ProviderContainer(
overrides: [
deviceExperienceProvider.overrideWithValue(DeviceExperience.desktop),
appDatabaseProvider.overrideWithValue(database),
appearanceSettingsRepositoryProvider.overrideWithValue(
MemoryAppearanceSettingsRepository(),
),
paletteSettingsRepositoryProvider.overrideWithValue(
MemoryPaletteSettingsRepository(),
),
projectsProvider.overrideWith(() => projects),
conversationRepositoryProvider.overrideWith(
(ref) async => EmptyConversationRepository(),
),
editorTimelineProvider(
'project',
'first',
).overrideWith((ref) => first.timeline),
editorTimelineProvider(
'project',
'second',
).overrideWith((ref) => second.timeline),
editorPreviewProvider.overrideWith((ref, ids) => null),
mediaAvailabilityProvider.overrideWith(
(ref, ids) async => MediaAvailability.missing,
),
],
);
addTearDown(() async {
await tester.pumpWidget(const SizedBox());
container.dispose();
await tester.runAsync(() async {
await first.workspace.close();
await second.workspace.close();
await first.directory.delete(recursive: true);
await second.directory.delete(recursive: true);
await database.close();
});
});
await tester.pumpWidget(
UncontrolledProviderScope(
container: container,
child: const CutdexApp(),
),
);
await tester.pumpAndSettle();
var windowBuilds = 0;
final previousBuild = debugOnRebuildDirtyWidget;
debugOnRebuildDirtyWidget = (element, built) {
previousBuild?.call(element, built);
if (element.widget is EditingPage || element.widget is MaterialApp) {
windowBuilds++;
}
};
projects.updateAssets([
AssetDocument(
id: 'new-media',
name: 'New media',
storage: AssetStorage.external,
location: 'file:///test/new.png',
metadata: const {'kind': 'image'},
),
]);
await tester.pumpAndSettle();
debugOnRebuildDirtyWidget = previousBuild;
expect(
windowBuilds,
0,
reason: 'Asset changes belong to content, not window/navigation',
);
await tester.tap(find.byKey(const Key('editor-properties-button')));
await tester.pumpAndSettle();
final properties = tester.element(find.byType(ProjectProperties));
final preview = tester.element(find.byType(EditorPreviewPanel));
final timeline = tester.element(
find.byKey(const Key('editor-timeline-surface')),
);
final propertyRect = tester.getRect(find.byType(ProjectProperties));
final canvasValue = tester.element(find.text('1080 × 1920 px'));
for (final success in [false, true]) {
await tester.tap(find.byKey(const ValueKey('timeline-tab-second')));
await tester.pump();
expect(
container.read(projectsProvider).requireValue.openingTimelineId,
'second',
);
expect(
tester.element(find.byType(ProjectProperties)),
same(properties),
);
expect(tester.element(find.byType(EditorPreviewPanel)), same(preview));
expect(
tester.element(find.byKey(const Key('editor-timeline-surface'))),
same(timeline),
);
expect(tester.getRect(find.byType(ProjectProperties)), propertyRect);
expect(find.byType(EditorEmptyPanel), findsNothing);
expect(find.byKey(const Key('properties-pending')), findsNothing);
expect(find.byKey(const Key('timeline-default-tracks')), findsNothing);
expect(find.text('1080 × 1920 px'), findsOneWidget);
await tester.tap(
find.byKey(const ValueKey('project-settings-edit')),
warnIfMissed: false,
);
await tester.pump();
expect(find.byKey(const ValueKey('project-width')), findsNothing);
projects.finish(success);
await tester.pumpAndSettle();
expect(
tester.element(find.byType(ProjectProperties)),
same(properties),
);
expect(tester.getRect(find.byType(ProjectProperties)), propertyRect);
expect(tester.element(find.byType(EditorPreviewPanel)), same(preview));
expect(
find.text(success ? '1920 × 1080 px' : '1080 × 1920 px'),
findsOneWidget,
);
expect(
tester.element(
find.text(success ? '1920 × 1080 px' : '1080 × 1920 px'),
),
same(canvasValue),
);
expect(tester.takeException(), isNull);
}
await tester.tap(find.byKey(const ValueKey('project-settings-edit')));
await tester.pumpAndSettle();
expect(find.byKey(const ValueKey('project-width')), findsOneWidget);
},
);
}
class _DelayedTimelineProjects extends Projects {
Completer<bool>? _pending;
void updateAssets(List<AssetDocument> assets) =>
state = AsyncData(state.requireValue.copyWith(assets: assets));
TimelineDocument _document(String id) =>
TimelineDocument(id: id, name: id, sequences: []);
@override
Future<ProjectState> build() async => ProjectState(
activeProject: const RecentProject(
id: 'project',
name: 'Project',
path: '/test/Project.cutdex',
),
recent: const [
RecentProject(
id: 'project',
name: 'Project',
path: '/test/Project.cutdex',
),
],
timelines: const [
TimelineSummary(id: 'first', name: 'First', revision: 1),
TimelineSummary(id: 'second', name: 'Second', revision: 1),
],
timeline: _document('first'),
);
@override
Future<bool> openTimeline(String projectId, String timelineId) async {
_pending = Completer<bool>();
state = AsyncData(
state.requireValue.copyWith(openingTimelineId: timelineId),
);
final success = await _pending!.future;
state = AsyncData(
state.requireValue.copyWith(
timeline: success ? _document(timelineId) : state.requireValue.timeline,
openingTimelineId: null,
),
);
return success;
}
void finish(bool success) => _pending!.complete(success);
}