Files
cutdex/test/project_properties_test.dart
T
lingjhf 2e0033ce2d
Gitea CI / Build Android APK (pull_request) Canceled after 0s
Gitea CI / Build Windows x64 app (pull_request) Canceled after 0s
Gitea CI / Audit and package Windows x64 (pull_request) Canceled after 0s
Gitea CI / Assemble and validate CI artifacts (pull_request) Canceled after 0s
Gitea CI / Gitea CI passed (pull_request) Canceled after 0s
Gitea CI / Check code and tests (pull_request) Canceled after 6m29s
feat(workspace): refresh desktop editing experience and prepare 0.1.2
2026-10-09 01:56:01 +08:00

350 lines
12 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 'package:cutdex/features/properties/project_properties.dart';
import 'package:cutdex/features/properties/project_property_row.dart';
import 'package:cutdex_ui/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('desktop project values share a right edge across labels', (
tester,
) async {
final f = (await tester.runAsync(
() =>
createPreviewFixture(Uri.file('/test/photo.png'), mediaType: 'image'),
))!;
addTearDown(
() => tester.runAsync(() async {
await f.workspace.close();
await f.directory.delete(recursive: true);
}),
);
for (final locale in ['en', 'zh', 'de']) {
for (final width in [220.0, 260.0, 320.0]) {
await tester.pumpWidget(
MaterialApp(
localizationsDelegates: AppLocalizations.localizationsDelegates,
supportedLocales: AppLocalizations.supportedLocales,
locale: Locale(locale),
theme: EditorTheme.desktop(EditorTheme.penLight),
home: Scaffold(
body: Align(
alignment: Alignment.topLeft,
child: SizedBox(
width: width,
height: 600,
child: ProjectProperties(session: f.timeline),
),
),
),
),
);
await tester.pumpAndSettle();
final panelRight = tester.getRect(find.byType(ProjectProperties)).right;
expect(
tester
.getSize(find.byKey(const ValueKey('project-settings-edit')))
.height,
28,
);
final rows = find.byWidgetPredicate(
(widget) => widget.runtimeType.toString() == '_Info',
);
expect(rows, findsNWidgets(7));
for (var i = 0; i < 7; i++) {
final label = find
.descendant(of: rows.at(i), matching: find.byType(Text))
.first;
final value = find
.descendant(of: rows.at(i), matching: find.byType(Text))
.last;
expect(tester.widget<Text>(value).textAlign, TextAlign.right);
expect(
tester.getTopLeft(label).dy,
closeTo(tester.getTopLeft(value).dy, .01),
);
expect(tester.getRect(label).left, AppInspectorMetrics.padding);
expect(
find.descendant(
of: rows.at(i),
matching: find.byType(ProjectPropertyRow),
),
findsOneWidget,
);
expect(
tester.getRect(value).right,
panelRight - AppInspectorMetrics.padding,
reason: '$locale at $width: ${tester.widget<Text>(value).data}',
);
}
expect(tester.takeException(), isNull);
}
}
await tester.pumpWidget(const SizedBox());
});
testWidgets(
'long desktop project metadata fits narrow panels in every theme',
(tester) async {
const name = '海边日落与城市漫游 · 旅行短片的最终版本 / Very long sequence name';
for (final palette in AppPalette.values) {
for (final brightness in Brightness.values) {
for (final width in [220.0, 280.0, 320.0]) {
await tester.pumpWidget(
MaterialApp(
theme: AppTheme.desktopWorkspaceTheme(
AppTheme.forPalette(palette, brightness),
),
home: Scaffold(
body: Align(
alignment: Alignment.topLeft,
child: SizedBox(
width: width,
child: const MediaQuery(
data: MediaQueryData(
textScaler: TextScaler.linear(1.3),
),
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
ProjectPropertyRow(label: '时间线名称', value: name),
ProjectPropertyRow(
label: '项目色彩空间',
value: 'HDR · Rec.2020 HLG',
),
ProjectPropertyRow(
label: '画布大小',
value: '3840 × 2160 px',
),
],
),
),
),
),
),
),
);
await tester.pumpAndSettle();
expect(tester.takeException(), isNull);
for (final row in find.byType(ProjectPropertyRow).evaluate()) {
final texts = find.descendant(
of: find.byWidget(row.widget),
matching: find.byType(Text),
);
expect(tester.getRect(texts.first).left, 12);
expect(tester.getRect(texts.last).right, width - 12);
expect(
tester.getTopLeft(texts.first).dy,
closeTo(tester.getTopLeft(texts.last).dy, .01),
);
}
}
}
}
final tooltip = find.ancestor(
of: find.text(name),
matching: find.byType(Tooltip),
);
tester.state<TooltipState>(tooltip).ensureTooltipVisible();
await tester.pumpAndSettle();
expect(find.text(name), findsNWidgets(2));
await tester.pumpWidget(const SizedBox());
},
);
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);
});
});
}