Files
cutdex/test/project_properties_test.dart
T
lingjhf 27e77fff39 feat: initial Cutdex application
Add the Flutter video editing application with project management, media
import, timeline editing, preview, AI assistance, diagnostics and settings.

Include shared UI and native host packages, platform runners, application
tests and release tooling.

Provide usage and contribution guides, the MIT license and third-party
notices. Exclude local credentials, build outputs and validation data.
2026-10-05 23:36:23 +08:00

201 lines
7.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 'package:cutdex/app/editor_theme.dart';
import 'dart:async';
import 'package:cutdex/l10n/app_localizations.dart';
import 'package:cutdex_sdk/editor.dart';
import 'package:cutdex/features/properties/properties_panel.dart';
import 'package:cutdex/workspace/timeline_provider.dart';
import 'package:cutdex/workspace/timeline_session.dart';
import 'package:cutdex_sdk/timeline/model.dart';
import 'package:cutdex_sdk/runtime/contracts.dart';
import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:flutter_test/flutter_test.dart';
import 'support/preview_fixture.dart';
void main() {
testWidgets('timeline switch does not expose the previous session', (
tester,
) async {
final f = (await tester.runAsync(
() =>
createPreviewFixture(Uri.file('/test/audio.wav'), mediaType: 'audio'),
))!;
addTearDown(() async {
await f.workspace.close();
await f.directory.delete(recursive: true);
});
final pending = Completer<EditorTimelineSession>();
final container = ProviderContainer(
overrides: [
editorTimelineProvider(
'project',
'first',
).overrideWith((ref) async => f.timeline),
editorTimelineProvider(
'project',
'second',
).overrideWith((ref) => pending.future),
],
);
addTearDown(container.dispose);
Widget panel(String timelineId) => UncontrolledProviderScope(
container: container,
child: MaterialApp(
localizationsDelegates: AppLocalizations.localizationsDelegates,
supportedLocales: AppLocalizations.supportedLocales,
locale: const Locale('zh'),
theme: EditorTheme.penDark,
home: Scaffold(
body: SizedBox(
width: 280,
child: EditorPropertiesPanel(
projectId: 'project',
timelineId: timelineId,
),
),
),
),
);
await tester.pumpWidget(panel('first'));
await tester.pumpAndSettle();
expect(find.text('项目属性'), findsOneWidget);
expect(
find.ancestor(
of: find.byType(SingleChildScrollView),
matching: find.byType(ShaderMask),
),
findsOneWidget,
);
expect(
find.descendant(
of: find.byType(EditorPropertiesPanel),
matching: find.byType(ClipRRect),
),
findsNothing,
);
await tester.pumpWidget(panel('second'));
await tester.pump();
expect(find.text('项目属性'), findsNothing);
expect(find.byKey(const Key('properties-pending')), findsOneWidget);
expect(find.byType(CircularProgressIndicator), findsNothing);
pending.complete(f.timeline);
await tester.pumpAndSettle();
expect(find.text('项目属性'), findsOneWidget);
expect(find.byType(CircularProgressIndicator), findsNothing);
});
testWidgets('project properties follow edits and return after deselection', (
tester,
) async {
final f = (await tester.runAsync(
() =>
createPreviewFixture(Uri.file('/test/audio.wav'), mediaType: 'audio'),
))!;
await tester.pumpWidget(
ProviderScope(
overrides: [
editorTimelineProvider(
'project',
'project',
).overrideWith((ref) async => f.timeline),
],
child: MaterialApp(
localizationsDelegates: AppLocalizations.localizationsDelegates,
supportedLocales: AppLocalizations.supportedLocales,
locale: const Locale('zh'),
theme: EditorTheme.penDark,
home: const Scaffold(
body: SizedBox(
width: 280,
child: EditorPropertiesPanel(
projectId: 'project',
timelineId: 'project',
),
),
),
),
),
);
await tester.pumpAndSettle();
expect(find.text('项目属性'), findsOneWidget);
expect(find.text('Preview test'), findsOneWidget);
expect(find.text('1080 × 1920 px'), findsOneWidget);
expect(find.text('30 fps'), findsOneWidget);
expect(find.text('2.00 秒'), findsOneWidget);
await tester.tap(find.byKey(const ValueKey('project-settings-edit')));
await tester.pumpAndSettle();
expect(find.text('项目设置'), findsOneWidget);
await tester.enterText(find.byKey(const ValueKey('project-width')), '0');
await tester.tap(find.byKey(const ValueKey('project-settings-save')));
await tester.pump();
expect(find.text('请输入 1–16384 的整数'), findsOneWidget);
expect(f.timeline.canvas, const ProjectCanvas(1080, 1920));
await tester.enterText(find.byKey(const ValueKey('project-width')), '3840');
await tester.enterText(
find.byKey(const ValueKey('project-height')),
'2160',
);
await tester.tap(find.byKey(const ValueKey('project-frame-rate')));
await tester.pumpAndSettle();
await tester.tap(find.text('29.97 fps').last);
await tester.pumpAndSettle();
await tester.tap(find.byKey(const ValueKey('project-color-space')));
await tester.pumpAndSettle();
await tester.tap(find.text('HDR · Rec.2020 PQ').last);
await tester.pumpAndSettle();
await tester.tap(find.byKey(const ValueKey('project-settings-save')));
await tester.runAsync(f.timeline.flush);
await tester.pumpAndSettle();
expect(find.text('项目设置'), findsNothing);
expect(find.text('3840 × 2160 px'), findsOneWidget);
expect(find.text('29.97 fps'), findsOneWidget);
expect(f.timeline.projectColorSpace, RenderColorSpace.rec2020PQ);
expect(
f.timeline.view(SequenceId('one')).format.frameDuration,
RationalTime(1001, 30000),
);
f.timeline.view(SequenceId('one')).undo();
await tester.runAsync(f.timeline.flush);
await tester.pumpAndSettle();
expect(find.text('1080 × 1920 px'), findsOneWidget);
expect(find.text('30 fps'), findsOneWidget);
expect(f.timeline.projectColorSpace, RenderColorSpace.rec709);
await tester.tap(find.byKey(const ValueKey('project-settings-edit')));
await tester.pumpAndSettle();
await tester.enterText(find.byKey(const ValueKey('project-width')), '1280');
await tester.tap(find.text('取消'));
await tester.pumpAndSettle();
expect(f.timeline.canvas, const ProjectCanvas(1080, 1920));
f.timeline.commands.setCanvas(ProjectCanvas.widescreen);
await tester.pump();
expect(find.text('1920 × 1080 px'), findsOneWidget);
final view = f.timeline.view(SequenceId('one'));
view.setSelection([
view.version.kernelVersion.query().elementById(ElementId('clip'))!,
]);
await tester.pump();
expect(find.text('项目属性'), findsNothing);
expect(find.text('Preview clip'), findsNothing);
view.clearSelection();
await tester.pump();
expect(find.text('项目属性'), findsOneWidget);
f.timeline.selectSequence(SequenceId('empty'));
await tester.pump();
expect(find.text('0.00 秒'), findsOneWidget);
expect(tester.takeException(), isNull);
await tester.pumpWidget(const SizedBox());
await tester.runAsync(() async {
await f.workspace.close();
await f.directory.delete(recursive: true);
});
});
}