Files
cutdex/test/picture_keyframes_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

157 lines
5.8 KiB
Dart

import 'package:cutdex/app/editor_theme.dart';
import 'package:cutdex/l10n/app_localizations.dart';
import 'package:cutdex_sdk/editor.dart';
import 'package:cutdex/features/preview/preview_panel.dart';
import 'package:cutdex/features/properties/picture_properties.dart';
import 'package:cutdex_sdk/timeline/model.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(
'compact keyframe inspector authors, seeks, interpolates and clears',
(tester) async {
final f = (await tester.runAsync(
() => createPreviewFixture(
Uri.file('/test/video.mov'),
clipDuration: RationalTime.seconds(5),
),
))!;
final view = f.timeline.view(SequenceId('one'));
final project = f.workspace.project!.info.id;
ClipAnimation current() {
final q = view.version.kernelVersion.query();
return ClipAnimation.at(
q,
q.elementById(ElementId('clip'))!,
view.playheadTick,
TimelineClock.ticksPerSecond ~/ 30,
);
}
await tester.pumpWidget(
ProviderScope(
overrides: [
editorPreviewProvider(project, 'project').overrideWith(
(ref) async => throw StateError('No native preview'),
),
],
child: MaterialApp(
localizationsDelegates: AppLocalizations.localizationsDelegates,
supportedLocales: AppLocalizations.supportedLocales,
locale: const Locale('zh'),
theme: EditorTheme.penLight,
home: Scaffold(
body: Align(
alignment: Alignment.topLeft,
child: SizedBox(
width: 225,
child: SingleChildScrollView(
child: PictureProperties(
projectId: project,
timelineId: 'project',
session: f.timeline,
sequence: SequenceId('one'),
clip: current().record,
animationView: true,
),
),
),
),
),
),
),
);
await tester.pumpAndSettle();
Future<void> settleEdit() async {
await tester.pump();
await tester.runAsync(f.timeline.flush);
await tester.pumpAndSettle();
expect(tester.takeException(), isNull);
}
Future<void> tap(String key) async {
await tester.ensureVisible(find.byKey(ValueKey(key)));
await tester.tap(find.byKey(ValueKey(key)));
await settleEdit();
}
Finder input(String key) => find.descendant(
of: find.byKey(ValueKey(key)),
matching: find.byType(TextField),
);
await tap('picture-key-position');
expect(current().keyed(TransformChannel.position), isTrue);
view.seekTo(2 * TimelineClock.ticksPerSecond);
await tester.pump();
await tester.enterText(input('picture-x'), '216');
await tester.testTextInput.receiveAction(TextInputAction.done);
await settleEdit();
expect(current().value.x, .2);
expect(current().keyTimes(TransformChannel.position).length, 2);
view.seekTo(TimelineClock.ticksPerSecond);
await tester.pump();
expect(
tester.widget<TextField>(input('picture-x')).controller!.text,
'108',
);
await tap('picture-key-previous-position');
expect(view.playheadTick, 0);
await tap('picture-key-menu-position');
await tester.tap(find.widgetWithText(MenuItemButton, '保持'));
await settleEdit();
view.seekTo(TimelineClock.ticksPerSecond);
await tester.pump();
expect(current().value.x, 0);
await tap('picture-key-next-position');
expect(view.playheadTick, 2 * TimelineClock.ticksPerSecond);
await tap('picture-key-position');
expect(current().keyTimes(TransformChannel.position), [0]);
await tap('picture-key-marker-position-0');
expect(view.playheadTick, 0);
await tap('picture-key-position');
expect(current().animated(TransformChannel.position), isFalse);
await tap('picture-key-scale');
await tap('picture-lock');
view.seekTo(2 * TimelineClock.ticksPerSecond);
await tester.pump();
await tester.enterText(input('picture-scale-y'), '200');
await tester.testTextInput.receiveAction(TextInputAction.done);
await settleEdit();
expect(current().value.scale, 1);
expect(current().value.scaleY, 2);
view.seekTo(TimelineClock.ticksPerSecond);
await tester.pump();
expect(
tester.widget<TextField>(input('picture-scale-y')).controller!.text,
'150',
);
await tap('picture-key-menu-scale');
await tester.tap(find.text('移除全部关键帧'));
await settleEdit();
expect(current().animated(TransformChannel.scale), isFalse);
expect(current().value.scaleY, 1.5);
// Unsubmitted text cannot leak into a different playhead position.
await tester.enterText(input('picture-x'), '999');
view.seekTo(3 * TimelineClock.ticksPerSecond);
await tester.pump();
await tester.testTextInput.receiveAction(TextInputAction.done);
await settleEdit();
expect(current().value.x, 0);
await tester.enterText(input('picture-rotation'), '25');
await tap('picture-key-rotation');
expect(current().value.rotation, 25);
expect(current().keyed(TransformChannel.rotation), isTrue);
await tester.pumpWidget(const SizedBox());
await tester.runAsync(() async {
await f.workspace.close();
await f.directory.delete(recursive: true);
});
},
);
}