Files
cutdex/test/project_switch_presentation_test.dart
T
lingjhf 38ca180cf7
Gitea CI / Check code and tests (pull_request) Failing after 8s
Gitea CI / Build Android APK (pull_request) Skipped
Gitea CI / Build Windows x64 app (pull_request) Skipped
Gitea CI / Audit and package Windows x64 (pull_request) Skipped
Gitea CI / Assemble and validate CI artifacts (pull_request) Skipped
Gitea CI / Gitea CI passed (pull_request) Failing after 1s
refactor(core): own editor UI and pin verified native releases
2026-10-12 03:20:29 +08:00

250 lines
9.1 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 '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/workspace/view_settings.dart';
import 'package:cutdex/workspace/workspace_navigation.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(
'project navigation retains panels and rebinds only prepared values',
(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 = _DelayedProjects();
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(
'other',
'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();
await tester.runAsync(() async {
for (final id in ['project', 'other']) {
await container.read(projectViewSettingsProvider(id).future);
container
.read(projectViewSettingsProvider(id).notifier)
.setPropertiesOpen(true);
}
});
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 Key('project-tabs-projects')));
await tester.pumpAndSettle();
await tester.tap(find.byKey(const ValueKey('project-menu-other')));
await tester.pump();
await tester.pump();
expect(
container.read(workspaceNavigationProvider).selectedProjectId,
'other',
);
final tab = find.byKey(const ValueKey('project-tab-other'));
expect(tab, findsOneWidget);
expect(tester.widget<TextButton>(tab).onPressed, isNotNull);
expect(
tester
.widgetList<Semantics>(
find.ancestor(of: tab, matching: find.byType(Semantics)),
)
.any((widget) => widget.properties.selected == true),
isTrue,
);
expect(
find.descendant(
of: find.byKey(const Key('window-project-tabs')),
matching: find.byType(CircularProgressIndicator),
),
findsNothing,
);
await tester.pump(const Duration(seconds: 2));
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(
container.read(workspaceNavigationProvider).selectedProjectId,
isNull,
);
expect(
projects.state.requireValue.activeProject?.id,
success ? 'other' : 'project',
);
expect(
find.byKey(const ValueKey('project-tab-other')),
success ? findsOneWidget : findsNothing,
);
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 _DelayedProjects extends Projects {
Completer<bool>? _pending;
static const recent = [
RecentProject(
id: 'project',
name: 'First project',
path: '/test/First.cutdex',
),
RecentProject(
id: 'other',
name: 'Second project',
path: '/test/Second.cutdex',
),
];
TimelineDocument _document(String id) =>
TimelineDocument(id: id, name: id, sequences: []);
@override
Future<ProjectState> build() async => ProjectState(
activeProject: recent.first,
recent: recent,
timelines: const [TimelineSummary(id: 'first', name: 'First', revision: 1)],
timeline: _document('first'),
);
@override
Future<bool> open(
String directory, {
String? name,
String? expectedId,
String? timelineId,
String? initialTimelineName,
bool Function()? isCurrent,
}) async {
_pending = Completer<bool>();
state = AsyncData(state.requireValue.copyWith(projectBusy: true));
final success = await _pending!.future && (isCurrent?.call() ?? true);
state = AsyncData(
state.requireValue.copyWith(
projectBusy: false,
activeProject: success ? recent.last : state.requireValue.activeProject,
timelines: success
? const [TimelineSummary(id: 'second', name: 'Second', revision: 1)]
: state.requireValue.timelines,
timeline: success ? _document('second') : state.requireValue.timeline,
),
);
return success;
}
void finish(bool success) => _pending!.complete(success);
}