Files
cutdex/test/picture_distortion_test.dart
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

124 lines
4.3 KiB
Dart

import 'package:cutdex/app/editor_theme.dart';
import 'package:cutdex/features/preview/preview_panel.dart';
import 'package:cutdex/features/properties/distortion_properties.dart';
import 'package:cutdex/l10n/app_localizations.dart';
import 'package:cutdex_core/editor.dart';
import 'package:cutdex_core/timeline/model.dart';
import 'package:cutdex_core/timeline/engine.dart';
import 'package:cutdex_ui/theme.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(
'four corner fields use paired keys; reset preserves animation; no px',
(tester) async {
final f = (await tester.runAsync(
() => createPreviewFixture(
Uri.file('/test/video.mov'),
clipDuration: RationalTime.seconds(5),
),
))!;
addTearDown(
() => tester.runAsync(() async {
await f.workspace.close();
await f.directory.delete(recursive: true);
}),
);
final sequence = SequenceId('one'),
clip = ElementId('clip'),
project = f.workspace.project!.info.id;
final view = f.timeline.view(sequence);
ElementRecord record() {
final q = view.version.kernelVersion.query();
return q.element(q.elementById(clip)!);
}
await tester.pumpWidget(
ProviderScope(
overrides: [
editorPreviewProvider(
project,
'project',
).overrideWith((ref) => null),
],
child: MaterialApp(
localizationsDelegates: AppLocalizations.localizationsDelegates,
supportedLocales: AppLocalizations.supportedLocales,
locale: const Locale('zh'),
theme: AppTheme.propertiesPanelTheme(
EditorTheme.desktop(EditorTheme.penDark),
),
home: Scaffold(
body: Align(
alignment: Alignment.topRight,
child: SizedBox(
width: 240,
child: SingleChildScrollView(
child: DistortionProperties(
projectId: project,
timelineId: 'project',
session: f.timeline,
sequence: sequence,
clip: clip,
),
),
),
),
),
),
),
);
Future<void> settle() async {
await tester.pump();
await tester.runAsync(f.timeline.flush);
await tester.pumpAndSettle();
expect(tester.takeException(), isNull);
}
await settle();
expect(find.text('变形'), findsOneWidget);
expect(find.text('px'), findsNothing);
expect(find.text('X'), findsNWidgets(4));
expect(find.text('Y'), findsNWidgets(4));
expect(find.byType(TextField), findsNWidgets(8));
final key = find.byKey(const ValueKey('distortion-topLeft-key'));
await tester.tap(key);
await settle();
for (final id in ClipDistortion.ids.take(2)) {
expect(record().parameters![id]!.length, 1);
}
view.seekTo(TimelineClock.ticksPerSecond);
await settle();
final input = find.descendant(
of: find.byKey(const ValueKey('distortion-topLeft-y')),
matching: find.byType(TextField),
);
await tester.enterText(input, '20');
await tester.testTextInput.receiveAction(TextInputAction.done);
await settle();
for (final id in ClipDistortion.ids.take(2)) {
expect(record().parameters![id]!.length, 2);
}
final y = record().parameters![ClipDistortion.ids[1]]!;
expect(y.valueAt(TimelineClock.ticksPerSecond), greaterThan(0));
for (final id in ClipDistortion.ids.skip(2)) {
expect(record().parameters?[id]?.length ?? 0, 0);
}
await tester.tap(find.byKey(const ValueKey('distortion-reset')));
await settle();
expect(record().parameters![ClipDistortion.ids[1]]!.length, 2);
expect(
record().parameters![ClipDistortion.ids[1]]!.valueAt(
TimelineClock.ticksPerSecond,
),
0,
);
await tester.pumpWidget(const SizedBox());
},
);
}