feat(workspace): refresh desktop editing experience and prepare 0.1.2
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
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
This commit is contained in:
1 parent
aa5255d1e4
commit
2e0033ce2d
260 files changed
+43963
-5591
No files matched your search
+1008
-92
File diff suppressed because it is too large.
Load diff
@@ -10,6 +10,7 @@ import 'package:cutdex/features/assistant/composer_suggestion_surface.dart';
|
||||
import 'package:cutdex/features/media/media_asset_drag.dart';
|
||||
import 'package:cutdex/integrations/agent/agent_provider.dart';
|
||||
import 'package:cutdex/l10n/app_localizations.dart';
|
||||
import 'package:cutdex_ui/icons.dart';
|
||||
import 'package:cutdex_ui/theme.dart';
|
||||
import 'package:cutdex/shared/widgets/drop_to_add_overlay.dart';
|
||||
import 'package:cutdex/workspace/project_state.dart';
|
||||
@@ -327,7 +328,7 @@ void main() {
|
||||
final assetIcon =
|
||||
((assetSpan.children!.first as WidgetSpan).child as Padding).child
|
||||
as Icon;
|
||||
expect(assetIcon.icon, Icons.attach_file);
|
||||
expect(assetIcon.icon, AppIcons.attachment);
|
||||
expect(assetIcon.color, referenceColor);
|
||||
expect((assetSpan.children![1] as TextSpan).style?.color, referenceColor);
|
||||
expect(
|
||||
@@ -373,7 +374,7 @@ void main() {
|
||||
final timelineIcon =
|
||||
((timelineSpan.children!.first as WidgetSpan).child as Padding).child
|
||||
as Icon;
|
||||
expect(timelineIcon.icon, Icons.view_timeline_outlined);
|
||||
expect(timelineIcon.icon, AppIcons.timeline);
|
||||
expect(timelineIcon.color, referenceColor);
|
||||
final timelineLabel = timelineSpan.children![1] as TextSpan;
|
||||
expect(timelineLabel.text, '主时间线');
|
||||
|
||||
@@ -0,0 +1,43 @@
|
||||
import 'package:cutdex/features/assistant/agent_composer_controller.dart';
|
||||
import 'package:cutdex/features/assistant/agent_composer_store.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
|
||||
void main() {
|
||||
late AgentComposerStore store;
|
||||
setUp(() {
|
||||
store = AgentComposerStore(
|
||||
createComposer: (_) => AgentComposerController(
|
||||
canImport: () => false,
|
||||
pickFiles: () async => [],
|
||||
importMedia: (_) async => null,
|
||||
),
|
||||
);
|
||||
});
|
||||
tearDown(() => store.dispose());
|
||||
|
||||
test('the initial unassigned draft follows only the first project', () {
|
||||
final initial = store.input(null, null, projectScoped: true)
|
||||
..text = 'Create a travel film';
|
||||
expect(store.input('a', null, projectScoped: true), same(initial));
|
||||
expect(store.input('b', null, projectScoped: true).text, isEmpty);
|
||||
expect(
|
||||
store.input('a', null, projectScoped: true).text,
|
||||
'Create a travel film',
|
||||
);
|
||||
expect(store.draft.text, isEmpty);
|
||||
});
|
||||
|
||||
test('creating a conversation keeps follow-up input in its project', () {
|
||||
final first = store.input('a', null, projectScoped: true)
|
||||
..text = 'Follow-up while the first reply streams';
|
||||
final second = store.input('b', null, projectScoped: true)
|
||||
..text = 'Another project draft';
|
||||
final attachments = store.composer('a', 'draft-a');
|
||||
store.promoteDraft('a', 'draft-a', 'chat-a');
|
||||
expect(store.input('a', 'chat-a'), same(first));
|
||||
expect(store.composer('a', 'chat-a'), same(attachments));
|
||||
expect(store.input('a', null, projectScoped: true).text, isEmpty);
|
||||
expect(store.input('b', null, projectScoped: true), same(second));
|
||||
expect(second.text, 'Another project draft');
|
||||
});
|
||||
}
|
||||
@@ -16,6 +16,7 @@ import 'package:cutdex/integrations/editor_tools.dart';
|
||||
import 'package:cutdex/l10n/app_localizations.dart';
|
||||
import 'package:cutdex/persistence/app_settings_repositories.dart';
|
||||
import 'package:cutdex_agent/cutdex_agent.dart';
|
||||
import 'package:cutdex_ui/icons.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
@@ -215,7 +216,7 @@ void main() {
|
||||
expect(
|
||||
tester
|
||||
.widget<IconButton>(
|
||||
find.widgetWithIcon(IconButton, Icons.arrow_upward),
|
||||
find.widgetWithIcon(IconButton, AppIcons.arrowUp),
|
||||
)
|
||||
.onPressed,
|
||||
isNull,
|
||||
@@ -255,7 +256,7 @@ void main() {
|
||||
expect(
|
||||
tester
|
||||
.widget<IconButton>(
|
||||
find.widgetWithIcon(IconButton, Icons.arrow_upward),
|
||||
find.widgetWithIcon(IconButton, AppIcons.arrowUp),
|
||||
)
|
||||
.onPressed,
|
||||
isNull,
|
||||
|
||||
@@ -91,7 +91,7 @@ void main() {
|
||||
expect(
|
||||
(await database.customSelect('PRAGMA user_version').getSingle())
|
||||
.read<int>('user_version'),
|
||||
2,
|
||||
4,
|
||||
);
|
||||
|
||||
final appearance = DriftAppearanceSettingsRepository(database);
|
||||
|
||||
@@ -0,0 +1,141 @@
|
||||
import 'package:cutdex/app/editor_theme.dart';
|
||||
import 'package:cutdex/features/assistant/agent_chat_panel.dart';
|
||||
import 'package:cutdex/features/assistant/agent_reply_region.dart';
|
||||
import 'package:cutdex/features/assistant/chat_controller.dart';
|
||||
import 'package:cutdex/features/assistant/chat_state.dart';
|
||||
import 'package:cutdex/l10n/app_localizations.dart';
|
||||
import 'package:cutdex/workspace/project_state.dart';
|
||||
import 'package:cutdex/workspace/projects.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
|
||||
class _Chat extends ChatController {
|
||||
@override
|
||||
ChatState build(
|
||||
String projectId, {
|
||||
String? conversationId,
|
||||
String? draftKey,
|
||||
}) => const ChatState(
|
||||
busy: true,
|
||||
messages: [ChatMessage(text: 'Previous answer')],
|
||||
);
|
||||
void stream(String text) => state = state.copyWith(partialResponse: text);
|
||||
}
|
||||
|
||||
class _Projects extends Projects {
|
||||
@override
|
||||
Future<ProjectState> build() async => const ProjectState();
|
||||
}
|
||||
|
||||
void main() {
|
||||
testWidgets(
|
||||
'streaming updates reply without rebuilding history or composer',
|
||||
(tester) async {
|
||||
final chat = _Chat();
|
||||
final container = ProviderContainer(
|
||||
overrides: [
|
||||
projectsProvider.overrideWith(_Projects.new),
|
||||
chatControllerProvider('project').overrideWith(() => chat),
|
||||
],
|
||||
);
|
||||
addTearDown(container.dispose);
|
||||
var visible = true;
|
||||
late StateSetter visibility;
|
||||
await tester.pumpWidget(
|
||||
UncontrolledProviderScope(
|
||||
container: container,
|
||||
child: MaterialApp(
|
||||
localizationsDelegates: AppLocalizations.localizationsDelegates,
|
||||
supportedLocales: AppLocalizations.supportedLocales,
|
||||
locale: const Locale('zh'),
|
||||
theme: EditorTheme.penDark,
|
||||
home: StatefulBuilder(
|
||||
builder: (context, setState) {
|
||||
visibility = setState;
|
||||
return TickerMode(
|
||||
enabled: visible,
|
||||
child: const Scaffold(
|
||||
body: AgentChatPanel(
|
||||
projectId: 'project',
|
||||
timelineId: 'timeline',
|
||||
),
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
final input = tester.element(find.byType(TextField));
|
||||
final history = tester.element(find.text('Previous answer'));
|
||||
var panelBuilds = 0;
|
||||
var historyBuilds = 0;
|
||||
var replyBuilds = 0;
|
||||
final previous = debugOnRebuildDirtyWidget;
|
||||
debugOnRebuildDirtyWidget = (element, built) {
|
||||
previous?.call(element, built);
|
||||
if (element.widget is AgentChatPanel) panelBuilds++;
|
||||
if (element.widget is AgentReplyRegion) replyBuilds++;
|
||||
if (identical(element, history)) historyBuilds++;
|
||||
};
|
||||
addTearDown(() => debugOnRebuildDirtyWidget = previous);
|
||||
for (var chunk = 0; chunk < 120; chunk++) {
|
||||
chat.stream('Reply $chunk');
|
||||
await tester.pump();
|
||||
}
|
||||
expect(find.text('Reply 119'), findsOneWidget);
|
||||
expect(panelBuilds, 0);
|
||||
expect(historyBuilds, 0);
|
||||
expect(replyBuilds, 120);
|
||||
expect(tester.element(find.byType(TextField)), same(input));
|
||||
visibility(() => visible = false);
|
||||
await tester.pumpAndSettle();
|
||||
replyBuilds = 0;
|
||||
for (var chunk = 120; chunk < 240; chunk++) {
|
||||
chat.stream('Reply $chunk');
|
||||
await tester.pump();
|
||||
}
|
||||
expect(replyBuilds, 0);
|
||||
visibility(() => visible = true);
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.text('Reply 239'), findsOneWidget);
|
||||
expect(tester.element(find.byType(TextField)), same(input));
|
||||
expect(tester.takeException(), isNull);
|
||||
String? copied;
|
||||
tester.binding.defaultBinaryMessenger.setMockMethodCallHandler(
|
||||
SystemChannels.platform,
|
||||
(call) async {
|
||||
if (call.method == 'Clipboard.setData') {
|
||||
copied = (call.arguments as Map)['text'] as String;
|
||||
}
|
||||
return null;
|
||||
},
|
||||
);
|
||||
addTearDown(
|
||||
() => tester.binding.defaultBinaryMessenger.setMockMethodCallHandler(
|
||||
SystemChannels.platform,
|
||||
null,
|
||||
),
|
||||
);
|
||||
final selection = tester
|
||||
.state<SelectionAreaState>(
|
||||
find.descendant(
|
||||
of: find.byType(AgentReplyRegion),
|
||||
matching: find.byType(SelectionArea),
|
||||
),
|
||||
)
|
||||
.selectableRegion;
|
||||
selection.selectAll(SelectionChangedCause.keyboard);
|
||||
await tester.pump();
|
||||
selection.contextMenuButtonItems
|
||||
.singleWhere((item) => item.type == ContextMenuButtonType.copy)
|
||||
.onPressed!();
|
||||
await tester.pump();
|
||||
expect(copied, 'Reply 239');
|
||||
await tester.pumpWidget(const SizedBox());
|
||||
},
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,177 @@
|
||||
import 'package:cutdex/app/editor_theme.dart';
|
||||
import 'package:cutdex/features/properties/caption_properties.dart';
|
||||
import 'package:cutdex/l10n/app_localizations.dart';
|
||||
import 'package:cutdex/workspace/timeline_session.dart';
|
||||
import 'package:cutdex_sdk/editor.dart';
|
||||
import 'package:cutdex_sdk/timeline/model.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
|
||||
import 'support/preview_fixture.dart';
|
||||
|
||||
final _sequence = SequenceId('one');
|
||||
|
||||
void main() {
|
||||
for (final desktop in [false, true]) {
|
||||
for (final field in ['text', 'color', 'strokeColor']) {
|
||||
testWidgets(
|
||||
'$field draft cannot overwrite a newer caption edit desktop=$desktop',
|
||||
(tester) async {
|
||||
final (session, id, _) = await _fixture(tester);
|
||||
final host = _host(session, id, desktop: desktop);
|
||||
await tester.pumpWidget(host);
|
||||
await tester.pumpAndSettle();
|
||||
final input = _input(id, field);
|
||||
final element = tester.element(input);
|
||||
await tester.enterText(input, _local(field));
|
||||
|
||||
await tester.runAsync(() async {
|
||||
session.setCaption(_sequence, _edit(id, field, _external(field)));
|
||||
await session.flush();
|
||||
});
|
||||
await tester.pump();
|
||||
expect(tester.element(input), same(element));
|
||||
expect(
|
||||
tester.widget<TextField>(input).controller!.text,
|
||||
_external(field),
|
||||
);
|
||||
await tester.testTextInput.receiveAction(TextInputAction.done);
|
||||
await tester.pump();
|
||||
expect(_value(session, id, field), _external(field));
|
||||
|
||||
// A fresh draft in the new binding still commits normally.
|
||||
await tester.enterText(input, _local(field));
|
||||
await tester.testTextInput.receiveAction(TextInputAction.done);
|
||||
await tester.pump();
|
||||
expect(_value(session, id, field), _local(field));
|
||||
expect(tester.takeException(), isNull);
|
||||
await tester.runAsync(session.flush);
|
||||
await tester.pumpWidget(const SizedBox());
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
testWidgets('ordinary rebuilds retain a valid unsubmitted caption draft', (
|
||||
tester,
|
||||
) async {
|
||||
final (session, id, _) = await _fixture(tester);
|
||||
await tester.pumpWidget(_host(session, id));
|
||||
await tester.pumpAndSettle();
|
||||
final input = _input(id, 'text');
|
||||
await tester.enterText(input, 'Unsubmitted draft');
|
||||
await tester.pumpWidget(_host(session, id));
|
||||
await tester.pump();
|
||||
expect(
|
||||
tester.widget<TextField>(input).controller!.text,
|
||||
'Unsubmitted draft',
|
||||
);
|
||||
await tester.testTextInput.receiveAction(TextInputAction.done);
|
||||
await tester.pump();
|
||||
expect(session.caption(_sequence, id).text, 'Unsubmitted draft');
|
||||
await tester.runAsync(session.flush);
|
||||
await tester.pumpWidget(const SizedBox());
|
||||
});
|
||||
|
||||
testWidgets('selection changes do not carry a draft into another caption', (
|
||||
tester,
|
||||
) async {
|
||||
final (session, first, second) = await _fixture(tester);
|
||||
await tester.pumpWidget(_host(session, first));
|
||||
await tester.pumpAndSettle();
|
||||
await tester.enterText(_input(first, 'text'), 'First cue draft');
|
||||
await tester.pumpWidget(_host(session, second));
|
||||
await tester.pumpAndSettle();
|
||||
expect(
|
||||
tester.widget<TextField>(_input(second, 'text')).controller!.text,
|
||||
'Second caption',
|
||||
);
|
||||
expect(session.caption(_sequence, second).text, 'Second caption');
|
||||
expect(session.caption(_sequence, first).text, 'Original');
|
||||
expect(tester.takeException(), isNull);
|
||||
await tester.pumpWidget(const SizedBox());
|
||||
});
|
||||
}
|
||||
|
||||
Future<(EditorTimelineSession, String, String)> _fixture(
|
||||
WidgetTester tester,
|
||||
) async {
|
||||
final fixture = (await tester.runAsync(
|
||||
() => createPreviewFixture(Uri.file('/fixture.mov')),
|
||||
))!;
|
||||
addTearDown(
|
||||
() => tester.runAsync(() async {
|
||||
await fixture.workspace.close();
|
||||
await fixture.directory.delete(recursive: true);
|
||||
}),
|
||||
);
|
||||
final session = fixture.timeline;
|
||||
final ids = (await tester.runAsync(() async {
|
||||
final role =
|
||||
session.createCaptionTrack(
|
||||
_sequence,
|
||||
const CreateCaptionTrack(name: 'Captions', language: 'en'),
|
||||
)['roleId']
|
||||
as String;
|
||||
final result = session.addCaptions(
|
||||
_sequence,
|
||||
AddCaptions(
|
||||
roleId: role,
|
||||
cues: [
|
||||
CaptionCueInput(
|
||||
text: 'Original',
|
||||
start: CommandTime(0, 1),
|
||||
duration: CommandTime(1, 1),
|
||||
),
|
||||
CaptionCueInput(
|
||||
text: 'Second caption',
|
||||
start: CommandTime(1, 1),
|
||||
duration: CommandTime(1, 1),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
await session.flush();
|
||||
return (result['captionIds'] as List).cast<String>();
|
||||
}))!;
|
||||
return (session, ids[0], ids[1]);
|
||||
}
|
||||
|
||||
Widget _host(
|
||||
EditorTimelineSession session,
|
||||
String id, {
|
||||
bool desktop = false,
|
||||
}) => MaterialApp(
|
||||
localizationsDelegates: AppLocalizations.localizationsDelegates,
|
||||
supportedLocales: AppLocalizations.supportedLocales,
|
||||
theme: desktop
|
||||
? EditorTheme.desktop(EditorTheme.penDark)
|
||||
: EditorTheme.penDark,
|
||||
home: Scaffold(
|
||||
body: CaptionProperties(session: session, sequence: _sequence, clipId: id),
|
||||
),
|
||||
);
|
||||
|
||||
Finder _input(String id, String field) => find.descendant(
|
||||
of: find.byKey(ValueKey(('caption-$field', id))),
|
||||
matching: find.byType(TextField),
|
||||
);
|
||||
|
||||
String _local(String field) => field == 'text' ? 'Local draft' : '#123456';
|
||||
String _external(String field) =>
|
||||
field == 'text' ? 'New external edit' : '#ABCDEF';
|
||||
|
||||
SetCaption _edit(String id, String field, String value) => switch (field) {
|
||||
'text' => SetCaption(captionId: id, text: value),
|
||||
'color' => SetCaption(captionId: id, color: value),
|
||||
_ => SetCaption(captionId: id, strokeColor: value),
|
||||
};
|
||||
|
||||
String _value(EditorTimelineSession session, String id, String field) {
|
||||
final caption = session.caption(_sequence, id);
|
||||
return switch (field) {
|
||||
'text' => caption.text,
|
||||
'color' => caption.color,
|
||||
_ => caption.strokeColor,
|
||||
};
|
||||
}
|
||||
@@ -8,6 +8,7 @@ import 'package:cutdex/features/assistant/chat_controller.dart';
|
||||
import 'package:cutdex/features/assistant/agent_conversation_service.dart';
|
||||
import 'package:cutdex/features/assistant/agent_chat_panel.dart';
|
||||
import 'package:cutdex/features/assistant/chat_state.dart';
|
||||
import 'package:cutdex_ui/icons.dart';
|
||||
import 'package:cutdex_ui/widgets.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
@@ -313,7 +314,7 @@ void main() {
|
||||
await tester.pump();
|
||||
expect(find.text('尚未发送的消息'), findsOneWidget);
|
||||
final send = tester.widget<IconButton>(
|
||||
find.widgetWithIcon(IconButton, Icons.arrow_upward),
|
||||
find.widgetWithIcon(IconButton, AppIcons.arrowUp),
|
||||
);
|
||||
expect(send.onPressed, isNull);
|
||||
final conversation = find.byKey(const Key('agent-conversation'));
|
||||
@@ -374,7 +375,7 @@ void main() {
|
||||
expect(composerInput.style?.fontSize, 13);
|
||||
expect(composerInput.decoration?.hintStyle?.fontSize, 13);
|
||||
final sendButton = tester.widget<IconButton>(
|
||||
find.widgetWithIcon(IconButton, Icons.arrow_upward),
|
||||
find.widgetWithIcon(IconButton, AppIcons.arrowUp),
|
||||
);
|
||||
expect(
|
||||
sendButton.style?.shape?.resolve(<WidgetState>{}),
|
||||
@@ -557,7 +558,7 @@ void main() {
|
||||
expect(
|
||||
tester
|
||||
.widget<IconButton>(
|
||||
find.widgetWithIcon(IconButton, Icons.arrow_upward),
|
||||
find.widgetWithIcon(IconButton, AppIcons.arrowUp),
|
||||
)
|
||||
.onPressed,
|
||||
isNull,
|
||||
|
||||
@@ -0,0 +1,289 @@
|
||||
import 'package:cutdex/features/projects/chat_header.dart';
|
||||
import 'package:cutdex/l10n/app_localizations.dart';
|
||||
import 'package:cutdex_ui/theme.dart';
|
||||
import 'package:cutdex_ui/widgets.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
|
||||
void main() {
|
||||
const entries = [
|
||||
(id: 'rough', title: '旅行短片粗剪'),
|
||||
(id: 'opening', title: '调整片头节奏与镜头衔接,让画面更自然'),
|
||||
(id: 'captions', title: '字幕与配乐'),
|
||||
];
|
||||
|
||||
Widget host(Widget child, {double width = 240, ThemeData? theme}) =>
|
||||
MaterialApp(
|
||||
theme: theme ?? AppTheme.desktopWorkspaceTheme(AppTheme.penDark),
|
||||
locale: const Locale('zh'),
|
||||
localizationsDelegates: AppLocalizations.localizationsDelegates,
|
||||
supportedLocales: AppLocalizations.supportedLocales,
|
||||
home: Scaffold(
|
||||
body: Align(
|
||||
alignment: Alignment.topLeft,
|
||||
child: SizedBox(width: width, child: child),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
testWidgets('title, new and more controls fit palettes and narrow widths', (
|
||||
tester,
|
||||
) async {
|
||||
for (final palette in AppPalette.values) {
|
||||
for (final brightness in Brightness.values) {
|
||||
for (final width in [120.0, 240.0, 400.0]) {
|
||||
await tester.pumpWidget(
|
||||
host(
|
||||
ChatHeader(
|
||||
title: entries[1].title,
|
||||
onNew: () {},
|
||||
actions: [AppMenuItem(label: '重命名', onPressed: () {})],
|
||||
historyBuilder: (_, close) =>
|
||||
ChatHistoryMenu(entries: entries, onSelect: (_) => close()),
|
||||
),
|
||||
width: width,
|
||||
theme: AppTheme.desktopWorkspaceTheme(
|
||||
AppTheme.forPalette(palette, brightness),
|
||||
),
|
||||
),
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
final header = tester.getRect(
|
||||
find.byKey(const Key('project-chat-header')),
|
||||
);
|
||||
final history = tester.getRect(
|
||||
find.byKey(const Key('project-chat-history')),
|
||||
);
|
||||
final create = tester.getRect(
|
||||
find.byKey(const Key('project-chat-new')),
|
||||
);
|
||||
final more = tester.getRect(
|
||||
find.byKey(const Key('project-chat-more')),
|
||||
);
|
||||
expect(header.height, 36);
|
||||
expect(create.size, const Size.square(26));
|
||||
expect(more.size, const Size.square(26));
|
||||
expect(create.center.dy, header.center.dy);
|
||||
expect(more.center.dy, header.center.dy);
|
||||
expect(history.left - header.left, 10);
|
||||
expect(header.right - more.right, 10);
|
||||
expect(create.left - history.right, 4);
|
||||
expect(more.left - create.right, 4);
|
||||
final title = tester.widget<Text>(
|
||||
find.byKey(const Key('project-chat-title')),
|
||||
);
|
||||
expect(title.maxLines, 1);
|
||||
expect(title.overflow, TextOverflow.ellipsis);
|
||||
expect(
|
||||
tester.takeException(),
|
||||
isNull,
|
||||
reason: '$palette $brightness $width',
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
testWidgets('history search, selection, new chat and actions work', (
|
||||
tester,
|
||||
) async {
|
||||
String? selected = 'rough';
|
||||
var actionCount = 0;
|
||||
await tester.pumpWidget(
|
||||
host(
|
||||
StatefulBuilder(
|
||||
builder: (context, setState) => ChatHeader(
|
||||
title:
|
||||
entries
|
||||
.where((entry) => entry.id == selected)
|
||||
.firstOrNull
|
||||
?.title ??
|
||||
'新聊天',
|
||||
onNew: () => setState(() => selected = null),
|
||||
actions: selected == null
|
||||
? const []
|
||||
: [AppMenuItem(label: '重命名', onPressed: () => actionCount++)],
|
||||
historyBuilder: (_, close) => ChatHistoryMenu(
|
||||
entries: entries,
|
||||
selectedId: selected,
|
||||
onSelect: (id) {
|
||||
close();
|
||||
setState(() => selected = id);
|
||||
},
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
await tester.tap(find.byKey(const Key('project-chat-history')));
|
||||
await tester.pumpAndSettle();
|
||||
expect(
|
||||
find.text(lookupAppLocalizations(const Locale('zh')).agentConversations),
|
||||
findsOneWidget,
|
||||
);
|
||||
await tester.enterText(find.byKey(const Key('project-chat-search')), '字幕');
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.byKey(const ValueKey('chat-history-rough')), findsNothing);
|
||||
await tester.tap(find.byKey(const ValueKey('chat-history-captions')));
|
||||
await tester.pumpAndSettle();
|
||||
expect(selected, 'captions');
|
||||
expect(find.byKey(const Key('project-chat-history-menu')), findsNothing);
|
||||
expect(find.text('字幕与配乐'), findsOneWidget);
|
||||
|
||||
await tester.tap(find.byKey(const Key('project-chat-more')));
|
||||
await tester.pumpAndSettle();
|
||||
await tester.tap(find.text('重命名'));
|
||||
await tester.pumpAndSettle();
|
||||
expect(actionCount, 1);
|
||||
await tester.tap(find.byKey(const Key('project-chat-new')));
|
||||
await tester.pumpAndSettle();
|
||||
expect(selected, isNull);
|
||||
expect(find.text('新聊天'), findsOneWidget);
|
||||
expect(
|
||||
tester
|
||||
.widget<IconButton>(find.byKey(const Key('project-chat-more')))
|
||||
.onPressed,
|
||||
isNull,
|
||||
);
|
||||
|
||||
await tester.tap(find.byKey(const Key('project-chat-history')));
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.byKey(const ValueKey('chat-history-rough')), findsOneWidget);
|
||||
await tester.enterText(
|
||||
find.byKey(const Key('project-chat-search')),
|
||||
'missing',
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
expect(
|
||||
find.text(lookupAppLocalizations(const Locale('zh')).noMatchingOptions),
|
||||
findsOneWidget,
|
||||
);
|
||||
await tester.sendKeyEvent(LogicalKeyboardKey.escape);
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.byKey(const Key('project-chat-history-menu')), findsNothing);
|
||||
expect(tester.takeException(), isNull);
|
||||
});
|
||||
|
||||
testWidgets(
|
||||
'empty history hides search and retains trash without stale filters',
|
||||
(tester) async {
|
||||
var history = <ChatHistoryEntry>[];
|
||||
var showTrash = false;
|
||||
late StateSetter updateHistory;
|
||||
await tester.pumpWidget(
|
||||
host(
|
||||
StatefulBuilder(
|
||||
builder: (_, setState) {
|
||||
updateHistory = setState;
|
||||
return ChatHeader(
|
||||
title: '新聊天',
|
||||
onNew: () {},
|
||||
actions: const [],
|
||||
historyBuilder: (_, _) => ChatHistoryMenu(
|
||||
entries: history,
|
||||
onSelect: (_) {},
|
||||
footer: showTrash ? const Text('Trash item') : null,
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
),
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
await tester.tap(find.byKey(const Key('project-chat-history')));
|
||||
await tester.pumpAndSettle();
|
||||
final l10n = lookupAppLocalizations(const Locale('zh'));
|
||||
expect(find.byKey(const Key('project-chat-search')), findsNothing);
|
||||
expect(find.text(l10n.agentNoConversations), findsOneWidget);
|
||||
expect(find.text('Trash item'), findsNothing);
|
||||
expect(
|
||||
tester.getSize(find.byType(ChatHistoryMenu)).height,
|
||||
lessThan(200),
|
||||
);
|
||||
updateHistory(() => showTrash = true);
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.text('Trash item'), findsOneWidget);
|
||||
expect(find.byKey(const Key('project-chat-search')), findsNothing);
|
||||
|
||||
updateHistory(() => history = entries.toList());
|
||||
await tester.pumpAndSettle();
|
||||
final search = find.byKey(const Key('project-chat-search'));
|
||||
expect(search, findsOneWidget);
|
||||
await tester.enterText(search, 'unmatched');
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.text(l10n.noMatchingOptions), findsOneWidget);
|
||||
expect(search, findsOneWidget);
|
||||
|
||||
updateHistory(() => history = []);
|
||||
await tester.pumpAndSettle();
|
||||
expect(search, findsNothing);
|
||||
expect(find.text(l10n.agentNoConversations), findsOneWidget);
|
||||
updateHistory(() => history = entries.toList());
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.byKey(const ValueKey('chat-history-rough')), findsOneWidget);
|
||||
expect(tester.widget<TextField>(search).controller?.text ?? '', isEmpty);
|
||||
expect(tester.takeException(), isNull);
|
||||
},
|
||||
);
|
||||
|
||||
testWidgets('panel commands stay available while a conversation is busy', (
|
||||
tester,
|
||||
) async {
|
||||
var collapsed = false;
|
||||
await tester.pumpWidget(
|
||||
host(
|
||||
ChatHeader(
|
||||
title: 'Working',
|
||||
busy: true,
|
||||
onNew: () {},
|
||||
actions: [AppMenuItem(label: '重命名', onPressed: () {})],
|
||||
panelActions: [
|
||||
AppMenuItem(label: '折叠对话', onPressed: () => collapsed = true),
|
||||
],
|
||||
historyBuilder: (_, close) =>
|
||||
ChatHistoryMenu(entries: entries, onSelect: (_) => close()),
|
||||
),
|
||||
),
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
expect(
|
||||
tester
|
||||
.widget<IconButton>(find.byKey(const Key('project-chat-new')))
|
||||
.onPressed,
|
||||
isNull,
|
||||
);
|
||||
await tester.tap(find.byKey(const Key('project-chat-more')));
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.text('重命名'), findsNothing);
|
||||
await tester.tap(find.text('折叠对话'));
|
||||
await tester.pumpAndSettle();
|
||||
expect(collapsed, isTrue);
|
||||
expect(tester.takeException(), isNull);
|
||||
});
|
||||
|
||||
testWidgets('busy header disables navigation', (tester) async {
|
||||
await tester.pumpWidget(
|
||||
host(
|
||||
ChatHeader(
|
||||
title: 'Chat',
|
||||
busy: true,
|
||||
onNew: () {},
|
||||
actions: [AppMenuItem(label: 'Rename', onPressed: () {})],
|
||||
historyBuilder: (_, _) => const Text('History'),
|
||||
),
|
||||
),
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
expect(
|
||||
tester
|
||||
.widget<TextButton>(find.byKey(const Key('project-chat-history')))
|
||||
.onPressed,
|
||||
isNull,
|
||||
);
|
||||
for (final key in ['project-chat-new', 'project-chat-more']) {
|
||||
expect(tester.widget<IconButton>(find.byKey(Key(key))).onPressed, isNull);
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,232 @@
|
||||
import 'package:cutdex/app/editor_theme.dart';
|
||||
import 'package:cutdex/features/preview/preview_panel.dart';
|
||||
import 'package:cutdex/features/properties/picture_properties.dart';
|
||||
import 'package:cutdex/features/properties/audio_properties.dart';
|
||||
import 'package:cutdex/features/properties/speed_properties.dart';
|
||||
import 'package:cutdex_ui/widgets.dart';
|
||||
import 'package:cutdex_ui/icons.dart';
|
||||
import 'package:cutdex/l10n/app_localizations.dart';
|
||||
import 'package:cutdex_sdk/timeline/model.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(
|
||||
'audio and speed controls fit desktop group headers at narrow widths',
|
||||
(tester) async {
|
||||
final f = (await tester.runAsync(
|
||||
() => createPreviewFixture(Uri.file('/test/video.mov'), hasAudio: true),
|
||||
))!;
|
||||
addTearDown(
|
||||
() => tester.runAsync(() async {
|
||||
await f.workspace.close();
|
||||
await f.directory.delete(recursive: true);
|
||||
}),
|
||||
);
|
||||
final query = f.timeline
|
||||
.view(SequenceId('one'))
|
||||
.version
|
||||
.kernelVersion
|
||||
.query();
|
||||
final clip = query.element(query.elementById(ElementId('clip'))!);
|
||||
for (final width in [220.0, 280.0, 360.0]) {
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(
|
||||
localizationsDelegates: AppLocalizations.localizationsDelegates,
|
||||
supportedLocales: AppLocalizations.supportedLocales,
|
||||
locale: const Locale('zh'),
|
||||
theme: AppTheme.propertiesPanelTheme(
|
||||
EditorTheme.desktop(EditorTheme.penDark),
|
||||
),
|
||||
home: Scaffold(
|
||||
body: Align(
|
||||
alignment: Alignment.topLeft,
|
||||
child: SizedBox(
|
||||
width: width,
|
||||
child: SingleChildScrollView(
|
||||
child: Column(
|
||||
children: [
|
||||
AudioProperties(
|
||||
session: f.timeline,
|
||||
sequence: SequenceId('one'),
|
||||
clip: clip,
|
||||
hasAudio: true,
|
||||
),
|
||||
SpeedProperties(
|
||||
session: f.timeline,
|
||||
sequence: SequenceId('one'),
|
||||
clip: clip.id,
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
final field = find.descendant(
|
||||
of: find.byKey(const Key('audio-db')),
|
||||
matching: find.byType(TextField),
|
||||
);
|
||||
expect(tester.getSize(field).height, 28);
|
||||
expect(
|
||||
tester.getRect(find.byKey(const Key('audio-key'))).bottom,
|
||||
tester.getRect(field).top - 4,
|
||||
);
|
||||
expect(find.byType(AppPropertyGroup), findsNWidgets(2));
|
||||
expect(tester.takeException(), isNull);
|
||||
}
|
||||
await tester.pumpWidget(const SizedBox());
|
||||
},
|
||||
);
|
||||
|
||||
testWidgets('desktop transform grid fits narrow panels in all six themes', (
|
||||
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);
|
||||
}),
|
||||
);
|
||||
final project = f.workspace.project!.info.id;
|
||||
final query = f.timeline
|
||||
.view(SequenceId('one'))
|
||||
.version
|
||||
.kernelVersion
|
||||
.query();
|
||||
final clip = query.element(query.elementById(ElementId('clip'))!);
|
||||
final container = ProviderContainer(
|
||||
overrides: [
|
||||
editorPreviewProvider(project, 'project').overrideWith((ref) => null),
|
||||
],
|
||||
);
|
||||
addTearDown(container.dispose);
|
||||
Finder input(String name) => find.descendant(
|
||||
of: find.byKey(ValueKey('picture-$name')),
|
||||
matching: find.byType(TextField),
|
||||
);
|
||||
for (final palette in AppPalette.values) {
|
||||
for (final brightness in Brightness.values) {
|
||||
for (final (width, locale) in [
|
||||
(220.0, 'de'),
|
||||
(280.0, 'zh'),
|
||||
(360.0, 'en'),
|
||||
]) {
|
||||
await tester.pumpWidget(
|
||||
UncontrolledProviderScope(
|
||||
container: container,
|
||||
child: MaterialApp(
|
||||
localizationsDelegates: AppLocalizations.localizationsDelegates,
|
||||
supportedLocales: AppLocalizations.supportedLocales,
|
||||
locale: Locale(locale),
|
||||
theme: AppTheme.propertiesPanelTheme(
|
||||
EditorTheme.desktop(
|
||||
EditorTheme.forPalette(palette, brightness),
|
||||
),
|
||||
),
|
||||
home: Scaffold(
|
||||
body: Align(
|
||||
alignment: Alignment.topLeft,
|
||||
child: SizedBox(
|
||||
width: width,
|
||||
child: SingleChildScrollView(
|
||||
child: PictureProperties(
|
||||
projectId: project,
|
||||
timelineId: 'project',
|
||||
session: f.timeline,
|
||||
sequence: SequenceId('one'),
|
||||
clip: clip,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
for (final name in ['x', 'y', 'scale-x', 'scale-y', 'rotation']) {
|
||||
expect(tester.getSize(input(name)).height, 28);
|
||||
}
|
||||
expect(tester.getRect(input('x')).left, 12);
|
||||
expect(tester.getRect(input('x')).width, (width - 28) / 2);
|
||||
for (final name in ['x', 'y', 'scale-x', 'scale-y', 'rotation']) {
|
||||
final field = tester.widget<TextField>(input(name));
|
||||
expect(field.decoration!.prefixIcon, isNotNull);
|
||||
}
|
||||
expect(
|
||||
find.descendant(
|
||||
of: find.byKey(const ValueKey('picture-rotation')),
|
||||
matching: find.byIcon(AppIcons.angle),
|
||||
),
|
||||
findsOneWidget,
|
||||
);
|
||||
final xLabel = find.descendant(
|
||||
of: find.byKey(const ValueKey('picture-x')),
|
||||
matching: find.text('X'),
|
||||
);
|
||||
expect(
|
||||
tester.getRect(xLabel).center.dy,
|
||||
tester.getRect(input('x')).center.dy,
|
||||
);
|
||||
final right = tester
|
||||
.getRect(find.byKey(const ValueKey('picture-key-position')))
|
||||
.right;
|
||||
for (final channel in ['position', 'scale', 'rotation']) {
|
||||
final action = find.byKey(ValueKey('picture-key-$channel'));
|
||||
expect(tester.getSize(action), const Size.square(24));
|
||||
expect(tester.getRect(action).right, right);
|
||||
final field = input(
|
||||
channel == 'position'
|
||||
? 'x'
|
||||
: channel == 'scale'
|
||||
? 'scale-x'
|
||||
: 'rotation',
|
||||
);
|
||||
expect(
|
||||
tester.getRect(action).bottom,
|
||||
tester.getRect(field).top - 4,
|
||||
);
|
||||
}
|
||||
expect(right, width - 12);
|
||||
expect(
|
||||
tester.getRect(input('x')).left,
|
||||
tester.getRect(input('rotation')).left,
|
||||
);
|
||||
if (width >= 220) {
|
||||
expect(
|
||||
tester.getCenter(input('x')).dy,
|
||||
tester.getCenter(input('y')).dy,
|
||||
);
|
||||
expect(
|
||||
tester.getCenter(input('scale-x')).dy,
|
||||
tester.getCenter(input('scale-y')).dy,
|
||||
);
|
||||
expect(
|
||||
tester.getRect(input('rotation')).top -
|
||||
tester.getRect(input('scale-x')).bottom,
|
||||
40,
|
||||
);
|
||||
}
|
||||
expect(
|
||||
tester.takeException(),
|
||||
isNull,
|
||||
reason: '$palette $brightness $locale $width',
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
await tester.pumpWidget(const SizedBox());
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
import 'package:cutdex/app/adaptive/desktop_content_controller.dart';
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
|
||||
void main() {
|
||||
for (final surface in DesktopContent.values.where(
|
||||
(surface) => surface != DesktopContent.settings,
|
||||
)) {
|
||||
test('settings returns to ${surface.name} after repeated navigation', () {
|
||||
final container = ProviderContainer();
|
||||
addTearDown(container.dispose);
|
||||
final navigation = container.read(desktopContentProvider.notifier);
|
||||
navigation.select(surface);
|
||||
final before = container.read(desktopContentProvider);
|
||||
navigation.showSettings(tab: 3, workspace: ('project', 'timeline'));
|
||||
navigation.showSettings(tab: 1);
|
||||
navigation.closeSettings();
|
||||
final after = container.read(desktopContentProvider);
|
||||
expect(after.surface, surface);
|
||||
expect(after.resourcesSelected, before.resourcesSelected);
|
||||
expect(after.librarySelected, before.librarySelected);
|
||||
expect(after.settingsTab, 1);
|
||||
expect(after.settingsVisited, isTrue);
|
||||
expect(after.workspace, ('project', 'timeline'));
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,125 @@
|
||||
import 'package:cutdex/app/shells/desktop_window_frame.dart';
|
||||
import 'package:cutdex/features/projects/project_tabs_bar.dart';
|
||||
import 'package:cutdex/integrations/platform/editor_window_chrome.dart';
|
||||
import 'package:cutdex/l10n/app_localizations.dart';
|
||||
import 'package:cutdex/workspace/project_state.dart';
|
||||
import 'package:cutdex_native/cutdex_native.dart';
|
||||
import 'package:cutdex_ui/theme.dart';
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
|
||||
void main() {
|
||||
testWidgets(
|
||||
'header separates native buttons from project entry and uses equal margins',
|
||||
(tester) async {
|
||||
const width = 720.0;
|
||||
const captionWidth = 132.0;
|
||||
for (final platform in [TargetPlatform.macOS, TargetPlatform.windows]) {
|
||||
for (final integrated in [false, true]) {
|
||||
debugDefaultTargetPlatformOverride = platform;
|
||||
final caption = integrated && platform == TargetPlatform.windows;
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(
|
||||
theme: AppTheme.desktopWorkspaceTheme(AppTheme.penDark),
|
||||
localizationsDelegates: AppLocalizations.localizationsDelegates,
|
||||
supportedLocales: AppLocalizations.supportedLocales,
|
||||
home: Scaffold(
|
||||
body: Align(
|
||||
alignment: Alignment.topLeft,
|
||||
child: SizedBox(
|
||||
width: width,
|
||||
height: 120,
|
||||
child: WindowHeaderLayout(
|
||||
captionBounds: caption
|
||||
? const Rect.fromLTWH(
|
||||
width - captionWidth,
|
||||
0,
|
||||
captionWidth,
|
||||
44,
|
||||
)
|
||||
: Rect.zero,
|
||||
child: DesktopWindowFrame(
|
||||
integratedTitlebar: integrated,
|
||||
headerControls: const SizedBox.shrink(),
|
||||
projectTabs: ProjectTabsBar(
|
||||
projects: const [
|
||||
RecentProject(id: 'one', name: 'One', path: '/one'),
|
||||
],
|
||||
recent: const [],
|
||||
selectedId: 'one',
|
||||
leadingActions: [
|
||||
IconButton(
|
||||
key: const Key('header-sidebar-action'),
|
||||
onPressed: () {},
|
||||
icon: const Icon(Icons.menu, size: 16),
|
||||
),
|
||||
],
|
||||
trailingActions: [
|
||||
IconButton(
|
||||
key: const Key('header-task-action'),
|
||||
onPressed: () {},
|
||||
icon: const Icon(Icons.task_alt, size: 16),
|
||||
),
|
||||
],
|
||||
onSelect: (_) {},
|
||||
onClose: (_) {},
|
||||
onCreate: () {},
|
||||
onOpen: () {},
|
||||
onRename: (_) {},
|
||||
),
|
||||
onHomePressed: () {},
|
||||
onSettingsPressed: () {},
|
||||
child: const SizedBox.shrink(),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
final entry = tester.getRect(
|
||||
find.byKey(const Key('project-tabs-projects')),
|
||||
);
|
||||
final sidebar = tester.getRect(
|
||||
find.byKey(const Key('header-sidebar-action')),
|
||||
);
|
||||
final list = tester.getRect(
|
||||
find.byKey(const Key('project-tabs-list')),
|
||||
);
|
||||
final task = tester.getRect(
|
||||
find.byKey(const Key('header-task-action')),
|
||||
);
|
||||
final start = integrated ? EditorWindowChrome.leadingWidth : 0.0;
|
||||
final end = caption ? width - captionWidth : width;
|
||||
final macButtons = integrated && platform == TargetPlatform.macOS;
|
||||
expect(
|
||||
sidebar.left - start,
|
||||
12,
|
||||
reason: '$platform integrated=$integrated left',
|
||||
);
|
||||
expect(
|
||||
end - task.right,
|
||||
12,
|
||||
reason: '$platform integrated=$integrated right',
|
||||
);
|
||||
if (macButtons) {
|
||||
expect(sidebar.left, 80);
|
||||
// The last native button is centered at 59 with a 14px frame.
|
||||
expect(sidebar.left - (59 + 14 / 2), 14);
|
||||
}
|
||||
expect(entry.center.dy, 22);
|
||||
expect(sidebar.center.dy, 22);
|
||||
expect(entry.left - sidebar.right, AppProjectTabMetrics.gap);
|
||||
expect(list.center.dy, 22);
|
||||
expect(task.center.dy, 22);
|
||||
expect(task.left - list.right, AppProjectTabMetrics.gap);
|
||||
expect(task.size, const Size.square(AppProjectTabMetrics.height));
|
||||
expect(tester.takeException(), isNull);
|
||||
}
|
||||
}
|
||||
debugDefaultTargetPlatformOverride = null;
|
||||
},
|
||||
);
|
||||
}
|
||||
@@ -1,4 +1,5 @@
|
||||
import 'package:cutdex/app/adaptive/desktop_workspace_controller.dart';
|
||||
import 'package:cutdex/shared/layout/workspace_layout_metrics.dart';
|
||||
import 'package:cutdex/app/shells/desktop_workspace_shell.dart';
|
||||
import 'package:cutdex/workspace/workspace_mode.dart';
|
||||
import 'package:cutdex/features/editor/layouts/expanded_editor_layout.dart';
|
||||
@@ -6,66 +7,65 @@ import 'package:flutter/material.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
|
||||
void main() {
|
||||
testWidgets(
|
||||
'properties divider spans the preview card including its header',
|
||||
(tester) async {
|
||||
tester.view.physicalSize = const Size(1000, 800);
|
||||
tester.view.devicePixelRatio = 1;
|
||||
addTearDown(tester.view.resetPhysicalSize);
|
||||
addTearDown(tester.view.resetDevicePixelRatio);
|
||||
var showProperties = true;
|
||||
late StateSetter update;
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(
|
||||
home: StatefulBuilder(
|
||||
builder: (context, setState) {
|
||||
update = setState;
|
||||
return ExpandedEditorLayout(
|
||||
preview: const SizedBox.expand(key: Key('test-preview')),
|
||||
header: const SizedBox(height: 40, key: Key('test-header')),
|
||||
properties: const SizedBox.expand(),
|
||||
media: const SizedBox(),
|
||||
showMedia: false,
|
||||
showProperties: showProperties,
|
||||
timelineHeight: 200,
|
||||
onTimelineHeightChanged: (_) {},
|
||||
onTimelineHeightChangeEnd: () {},
|
||||
timeline: const SizedBox(),
|
||||
);
|
||||
},
|
||||
),
|
||||
testWidgets('inspector has an independent frame aligned with the preview', (
|
||||
tester,
|
||||
) async {
|
||||
tester.view.physicalSize = const Size(1000, 800);
|
||||
tester.view.devicePixelRatio = 1;
|
||||
addTearDown(tester.view.resetPhysicalSize);
|
||||
addTearDown(tester.view.resetDevicePixelRatio);
|
||||
var showProperties = true;
|
||||
late StateSetter update;
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(
|
||||
home: StatefulBuilder(
|
||||
builder: (context, setState) {
|
||||
update = setState;
|
||||
return ExpandedEditorLayout(
|
||||
preview: const SizedBox.expand(key: Key('test-preview')),
|
||||
header: const SizedBox(height: 40, key: Key('test-header')),
|
||||
properties: const SizedBox.expand(),
|
||||
media: const SizedBox(),
|
||||
showMedia: false,
|
||||
showProperties: showProperties,
|
||||
timelineHeight: 200,
|
||||
onTimelineHeightChanged: (_) {},
|
||||
onTimelineHeightChangeEnd: () {},
|
||||
timeline: const SizedBox(),
|
||||
);
|
||||
},
|
||||
),
|
||||
);
|
||||
final card = tester.getRect(find.byKey(const Key('editor-preview-card')));
|
||||
final divider = tester.getRect(
|
||||
find.byKey(const Key('editor-properties-divider')),
|
||||
);
|
||||
final properties = tester.getRect(
|
||||
find.byKey(const Key('editor-properties-region')),
|
||||
);
|
||||
final header = tester.getRect(find.byKey(const Key('test-header')));
|
||||
expect(divider.top, card.top + 1);
|
||||
expect(divider.bottom, card.bottom - 1);
|
||||
expect(properties.top, divider.top);
|
||||
expect(properties.bottom, divider.bottom);
|
||||
expect(header.right, divider.left);
|
||||
expect(properties.left, divider.right);
|
||||
final preview = tester.element(find.byKey(const Key('test-preview')));
|
||||
update(() => showProperties = false);
|
||||
await tester.pump();
|
||||
expect(find.byKey(const Key('editor-properties-divider')), findsNothing);
|
||||
expect(
|
||||
tester.getRect(find.byKey(const Key('test-header'))).right,
|
||||
card.right - 1,
|
||||
);
|
||||
expect(
|
||||
tester.element(find.byKey(const Key('test-preview'))),
|
||||
same(preview),
|
||||
);
|
||||
expect(tester.takeException(), isNull);
|
||||
},
|
||||
);
|
||||
testWidgets('preview and timeline cards resize through their 1 dp gap', (
|
||||
),
|
||||
);
|
||||
final card = tester.getRect(find.byKey(const Key('editor-preview-card')));
|
||||
final divider = tester.getRect(
|
||||
find.byKey(const Key('editor-properties-divider')),
|
||||
);
|
||||
final properties = tester.getRect(
|
||||
find.byKey(const Key('editor-properties-region')),
|
||||
);
|
||||
final header = tester.getRect(find.byKey(const Key('test-header')));
|
||||
expect(divider.top, card.top);
|
||||
expect(divider.bottom, card.bottom);
|
||||
expect(properties.top, divider.top);
|
||||
expect(properties.bottom, divider.bottom);
|
||||
expect(header.right, divider.left - 1);
|
||||
expect(properties.left, divider.right);
|
||||
final preview = tester.element(find.byKey(const Key('test-preview')));
|
||||
update(() => showProperties = false);
|
||||
await tester.pump();
|
||||
expect(find.byKey(const Key('editor-properties-divider')), findsNothing);
|
||||
expect(
|
||||
tester.getRect(find.byKey(const Key('test-header'))).right,
|
||||
tester.getRect(find.byKey(const Key('editor-preview-card'))).right - 1,
|
||||
);
|
||||
expect(
|
||||
tester.element(find.byKey(const Key('test-preview'))),
|
||||
same(preview),
|
||||
);
|
||||
expect(tester.takeException(), isNull);
|
||||
});
|
||||
testWidgets('preview and timeline cards resize through their 6 dp gap', (
|
||||
tester,
|
||||
) async {
|
||||
tester.view.physicalSize = const Size(700, 800);
|
||||
@@ -101,9 +101,15 @@ void main() {
|
||||
Rect card(String name) =>
|
||||
tester.getRect(find.byKey(Key('editor-$name-card')));
|
||||
final timelineBefore = card('timeline');
|
||||
expect(timelineBefore.top - card('preview').bottom, 1);
|
||||
expect(
|
||||
timelineBefore.top - card('preview').bottom,
|
||||
WorkspaceLayoutMetrics.desktopSpacing,
|
||||
);
|
||||
final resize = find.byKey(const Key('editor-timeline-resize'));
|
||||
expect(tester.getSize(resize).height, 5);
|
||||
expect(
|
||||
tester.getSize(resize).height,
|
||||
WorkspaceLayoutMetrics.desktopResizeHitExtent,
|
||||
);
|
||||
expect(
|
||||
find.descendant(
|
||||
of: find.byKey(const Key('editor-timeline-card')),
|
||||
@@ -117,7 +123,10 @@ void main() {
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
expect(card('timeline').height, timelineBefore.height + 80);
|
||||
expect(card('timeline').top - card('preview').bottom, 1);
|
||||
expect(
|
||||
card('timeline').top - card('preview').bottom,
|
||||
WorkspaceLayoutMetrics.desktopSpacing,
|
||||
);
|
||||
expect(saves, 1);
|
||||
await tester.dragFrom(
|
||||
tester.getCenter(resize) + const Offset(0, 2),
|
||||
@@ -127,7 +136,7 @@ void main() {
|
||||
expect(card('timeline').height, timelineBefore.height + 60);
|
||||
expect(saves, 2);
|
||||
await tester.dragFrom(
|
||||
tester.getCenter(resize) + const Offset(0, 3),
|
||||
tester.getCenter(resize) + const Offset(0, 6),
|
||||
const Offset(0, -30),
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
@@ -175,15 +184,24 @@ void main() {
|
||||
final project = card('project');
|
||||
final editor = card('editor');
|
||||
final agent = card('agent');
|
||||
expect(editor.left - project.right, 1);
|
||||
expect(agent.left - editor.right, 1);
|
||||
expect(
|
||||
editor.left - project.right,
|
||||
WorkspaceLayoutMetrics.desktopSpacing,
|
||||
);
|
||||
expect(agent.left - editor.right, WorkspaceLayoutMetrics.desktopSpacing);
|
||||
expect(project.top, editor.top);
|
||||
expect(editor.bottom, agent.bottom);
|
||||
|
||||
final projectResize = find.byKey(const Key('project-sidebar-resize'));
|
||||
final agentResize = find.byKey(const Key('agent-panel-resize'));
|
||||
expect(tester.getSize(projectResize).width, 5);
|
||||
expect(tester.getSize(agentResize).width, 5);
|
||||
expect(
|
||||
tester.getSize(projectResize).width,
|
||||
WorkspaceLayoutMetrics.desktopResizeHitExtent,
|
||||
);
|
||||
expect(
|
||||
tester.getSize(agentResize).width,
|
||||
WorkspaceLayoutMetrics.desktopResizeHitExtent,
|
||||
);
|
||||
await tester.dragFrom(
|
||||
tester.getCenter(projectResize) + const Offset(-2, 0),
|
||||
const Offset(60, 0),
|
||||
@@ -199,7 +217,10 @@ void main() {
|
||||
await tester.pumpAndSettle();
|
||||
expect(card('agent').width, agent.width + 80);
|
||||
expect(card('project').width, project.width + 60);
|
||||
expect(card('agent').left - card('editor').right, 1);
|
||||
expect(
|
||||
card('agent').left - card('editor').right,
|
||||
WorkspaceLayoutMetrics.desktopSpacing,
|
||||
);
|
||||
await tester.dragFrom(
|
||||
tester.getCenter(projectResize) + const Offset(2, 0),
|
||||
const Offset(-20, 0),
|
||||
@@ -213,13 +234,17 @@ void main() {
|
||||
await tester.pumpAndSettle();
|
||||
expect(card('agent').width, agent.width + 60);
|
||||
await tester.dragFrom(
|
||||
tester.getCenter(projectResize) + const Offset(-3, 0),
|
||||
tester.getCenter(projectResize) + const Offset(-6, 0),
|
||||
const Offset(30, 0),
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
expect(card('project').width, project.width + 40);
|
||||
expect(card('editor').left - card('project').right, 1);
|
||||
expect(
|
||||
card('editor').left - card('project').right,
|
||||
WorkspaceLayoutMetrics.desktopSpacing,
|
||||
);
|
||||
|
||||
controller.setAgentVisible(true);
|
||||
update(() => mode = WorkspaceMode.cut);
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.byKey(const Key('desktop-agent-card')), findsOneWidget);
|
||||
|
||||
@@ -3,6 +3,7 @@ import 'package:cutdex/features/editor/editor_panel_defaults.dart';
|
||||
import 'package:cutdex/features/preview/preview_panel.dart';
|
||||
import 'package:cutdex/l10n/app_localizations.dart';
|
||||
import 'package:cutdex_sdk/editor.dart';
|
||||
import 'package:cutdex_ui/icons.dart';
|
||||
import 'package:cutdex_ui/widgets.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
@@ -42,7 +43,7 @@ void main() {
|
||||
expect(ratio.value, ProjectCanvas.widescreen);
|
||||
expect(ratio.onChanged, isNull);
|
||||
final play = tester.widget<IconButton>(
|
||||
find.widgetWithIcon(IconButton, Icons.play_arrow),
|
||||
find.widgetWithIcon(IconButton, AppIcons.play),
|
||||
);
|
||||
expect(play.onPressed, isNull);
|
||||
expect(find.byType(CircularProgressIndicator), findsNothing);
|
||||
@@ -55,12 +56,18 @@ void main() {
|
||||
) async {
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(
|
||||
theme: EditorTheme.penLight,
|
||||
theme: EditorTheme.desktop(EditorTheme.penLight),
|
||||
localizationsDelegates: AppLocalizations.localizationsDelegates,
|
||||
supportedLocales: AppLocalizations.supportedLocales,
|
||||
home: const Scaffold(body: EditorTimelineDefaults()),
|
||||
),
|
||||
);
|
||||
expect(find.byKey(const Key('timeline-default-tracks')), findsOneWidget);
|
||||
expect(find.byKey(const Key('timeline-toolbar')), findsOneWidget);
|
||||
expect(
|
||||
tester.getSize(find.byKey(const Key('timeline-add-button'))),
|
||||
const Size.square(26),
|
||||
);
|
||||
for (final button in tester.widgetList<IconButton>(
|
||||
find.byType(IconButton),
|
||||
)) {
|
||||
|
||||
@@ -7,6 +7,28 @@ import 'package:flutter/material.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
|
||||
void main() {
|
||||
test('desktop timecode ruler has room for labels and downward marks', () {
|
||||
for (final palette in AppPalette.values) {
|
||||
for (final brightness in Brightness.values) {
|
||||
final mobile = EditorTheme.forPalette(palette, brightness);
|
||||
final desktop = EditorTheme.desktop(mobile);
|
||||
final ruler = desktop.extension<TimelineThemeData>()!;
|
||||
expect(ruler.rulerHeight, 28);
|
||||
expect(ruler.rulerTextStyle.fontSize, 12);
|
||||
expect(
|
||||
ruler.rulerTextStyle.fontFeatures,
|
||||
contains(const FontFeature.tabularFigures()),
|
||||
);
|
||||
expect(ruler.playheadColor, desktop.colorScheme.primary);
|
||||
expect(mobile.extension<TimelineThemeData>()!.rulerHeight, 20);
|
||||
expect(
|
||||
mobile.extension<TimelineThemeData>()!.playheadColor,
|
||||
mobile.colorScheme.onSurface,
|
||||
);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
test(
|
||||
'Pen presets give timeline the same Codex surface and ink hierarchy',
|
||||
() {
|
||||
|
||||
@@ -4,6 +4,7 @@ import 'package:cutdex/l10n/app_localizations.dart';
|
||||
import 'dart:async';
|
||||
|
||||
import 'package:cutdex/integrations/platform/editor_window_chrome.dart';
|
||||
import 'package:cutdex_ui/icons.dart';
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
@@ -99,7 +100,7 @@ void main() {
|
||||
});
|
||||
await tester.pump();
|
||||
expect(find.byTooltip('还原'), findsOneWidget);
|
||||
expect(find.byIcon(Icons.filter_none), findsOneWidget);
|
||||
expect(find.byIcon(AppIcons.windowRestore), findsOneWidget);
|
||||
await tester.pumpWidget(const SizedBox());
|
||||
await tester.pump();
|
||||
expect(calls.last.arguments, {'enabled': false});
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import 'package:cutdex/errors/app_failure.dart';
|
||||
import 'package:cutdex/l10n/app_localizations.dart';
|
||||
import 'package:cutdex/shared/widgets/error_notification_host.dart';
|
||||
import 'package:cutdex_ui/icons.dart';
|
||||
import 'package:flutter/gestures.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
@@ -57,7 +58,7 @@ void main() {
|
||||
expect(copied, contains('code: resourceDownloadHttpFailed'));
|
||||
expect(copied, contains('HTTP: 503'));
|
||||
expect(copied, contains('service unavailable'));
|
||||
expect(find.byIcon(Icons.check), findsOneWidget);
|
||||
expect(find.byIcon(AppIcons.check), findsOneWidget);
|
||||
await tester.tap(find.byKey(const Key('close-error-button')));
|
||||
await tester.pump();
|
||||
expect(notice, findsNothing);
|
||||
@@ -101,4 +102,50 @@ void main() {
|
||||
expect(find.text('Dialog error'), findsNothing);
|
||||
expect(find.text('Dialog'), findsOneWidget);
|
||||
});
|
||||
|
||||
testWidgets('top message keeps undo available above dialogs', (tester) async {
|
||||
final host = await mount(tester);
|
||||
showDialog<void>(
|
||||
context: tester.element(find.text('Workspace')),
|
||||
builder: (_) => const AlertDialog(content: Text('Dialog')),
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
var restored = false;
|
||||
host.showMessage(
|
||||
content: const Text('Project removed'),
|
||||
actionLabel: 'Undo',
|
||||
onAction: () => restored = true,
|
||||
);
|
||||
await tester.pump();
|
||||
final notice = find.byKey(const Key('global-message-notification'));
|
||||
expect(tester.getRect(notice).top, 48);
|
||||
expect(find.byType(SnackBar), findsNothing);
|
||||
expect(find.byKey(const Key('copy-error-button')), findsNothing);
|
||||
await tester.tap(find.text('Undo'));
|
||||
await tester.pump();
|
||||
expect(restored, isTrue);
|
||||
expect(notice, findsNothing);
|
||||
expect(find.text('Dialog'), findsOneWidget);
|
||||
});
|
||||
|
||||
testWidgets('messages and errors share a queue and dismiss automatically', (
|
||||
tester,
|
||||
) async {
|
||||
final host = await mount(tester);
|
||||
host.showMessage(content: const Text('Task started'));
|
||||
host.show(const ErrorNotification(content: Text('Task failed')));
|
||||
host.showMessage(content: const Text('Token copied'));
|
||||
await tester.pump();
|
||||
expect(find.text('Task started'), findsOneWidget);
|
||||
expect(find.text('Task failed'), findsNothing);
|
||||
await tester.pump(const Duration(seconds: 4));
|
||||
expect(find.text('Task started'), findsNothing);
|
||||
expect(find.text('Task failed'), findsOneWidget);
|
||||
await tester.pump(const Duration(seconds: 8));
|
||||
expect(find.text('Task failed'), findsNothing);
|
||||
expect(find.text('Token copied'), findsOneWidget);
|
||||
await tester.tap(find.byKey(const Key('close-message-button')));
|
||||
await tester.pump();
|
||||
expect(find.text('Token copied'), findsNothing);
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,256 @@
|
||||
import 'package:cutdex/app/editor_theme.dart';
|
||||
import 'package:cutdex/features/projects/conversation_sidebar.dart';
|
||||
import 'package:cutdex/features/projects/project_sidebar.dart';
|
||||
import 'package:cutdex/integrations/agent/conversation_repository.dart';
|
||||
import 'package:cutdex/l10n/app_localizations.dart';
|
||||
import 'package:cutdex/workspace/project_state.dart';
|
||||
import 'package:cutdex/workspace/projects.dart';
|
||||
import 'package:cutdex/workspace/workspace_mode.dart';
|
||||
import 'package:cutdex_ui/icons.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
|
||||
import '../../support/empty_conversation_repository.dart';
|
||||
|
||||
void main() {
|
||||
testWidgets(
|
||||
'desktop header follows selection, rename, trash and project scope',
|
||||
(tester) async {
|
||||
const projects = [
|
||||
RecentProject(id: 'a', name: 'Project A', path: '/a'),
|
||||
RecentProject(id: 'b', name: 'Project B', path: '/b'),
|
||||
];
|
||||
final repository = _Conversations([
|
||||
_item('first', 'a', 'First chat'),
|
||||
_item('second', 'a', 'Second chat'),
|
||||
_item('other', 'b', 'Other project chat'),
|
||||
]);
|
||||
final workspace = _Projects(
|
||||
ProjectState(activeProject: projects.first, recent: projects),
|
||||
);
|
||||
final container = ProviderContainer(
|
||||
overrides: [
|
||||
projectsProvider.overrideWith(() => workspace),
|
||||
conversationRepositoryProvider.overrideWith((_) => repository),
|
||||
],
|
||||
);
|
||||
addTearDown(container.dispose);
|
||||
await container.read(projectsProvider.future);
|
||||
await container.read(conversationSidebarProvider.future);
|
||||
await tester.pumpWidget(
|
||||
UncontrolledProviderScope(
|
||||
container: container,
|
||||
child: MaterialApp(
|
||||
theme: EditorTheme.desktop(EditorTheme.penDark),
|
||||
locale: const Locale('zh'),
|
||||
localizationsDelegates: AppLocalizations.localizationsDelegates,
|
||||
supportedLocales: AppLocalizations.supportedLocales,
|
||||
home: Scaffold(
|
||||
body: SizedBox(
|
||||
width: 240,
|
||||
child: Consumer(
|
||||
builder: (context, ref, _) {
|
||||
final state = ref.watch(projectsProvider).requireValue;
|
||||
return ProjectSidebar(
|
||||
chatOnly: true,
|
||||
agent: const Text('Conversation content'),
|
||||
mode: WorkspaceMode.agent,
|
||||
onModeChanged: (_) {},
|
||||
navigationWidth: 240,
|
||||
navigationCollapsed: false,
|
||||
agentHeaderLeading: const SizedBox(),
|
||||
editorHidden: false,
|
||||
onExpandEditor: null,
|
||||
state: state,
|
||||
selectedProjectId: state.activeProject?.id,
|
||||
integratedTitlebar: false,
|
||||
onCreateProject: null,
|
||||
onSelectProject: null,
|
||||
onRenameProject: (_) async => false,
|
||||
headerControls: const SizedBox(),
|
||||
);
|
||||
},
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.text('First chat'), findsOneWidget);
|
||||
await tester.tap(find.byKey(const Key('project-chat-history')));
|
||||
await tester.pumpAndSettle();
|
||||
final menu = find.byKey(const Key('project-chat-history-menu'));
|
||||
Finder menuText(String text) =>
|
||||
find.descendant(of: menu, matching: find.text(text));
|
||||
final group = tester.getRect(find.byKey(const Key('project-chat-group')));
|
||||
expect(tester.getRect(menuText('First chat')).left, group.left);
|
||||
expect(tester.getRect(menuText('Second chat')).left, group.left);
|
||||
final searchIcon = find.descendant(
|
||||
of: find.byKey(const Key('project-chat-search')),
|
||||
matching: find.byIcon(AppIcons.search),
|
||||
);
|
||||
expect(tester.getCenter(searchIcon).dx, group.left + 7);
|
||||
final search = find.byKey(const Key('project-chat-search'));
|
||||
expect(tester.getSize(search).height, 28);
|
||||
expect(tester.widget<TextField>(search).style?.fontSize, 13);
|
||||
expect(tester.widget<TextField>(search).cursorHeight, 13);
|
||||
expect(
|
||||
find.byKey(const ValueKey('sidebar-conversation-other')),
|
||||
findsNothing,
|
||||
);
|
||||
await tester.enterText(
|
||||
find.byKey(const Key('project-chat-search')),
|
||||
'Second',
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
await tester.tap(
|
||||
find.byKey(const ValueKey('sidebar-conversation-second')),
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.byKey(const Key('project-chat-history-menu')), findsNothing);
|
||||
expect(find.text('Second chat'), findsOneWidget);
|
||||
expect(repository.selection['a'], 'second');
|
||||
|
||||
await tester.tap(find.byKey(const Key('project-chat-more')));
|
||||
await tester.pumpAndSettle();
|
||||
await tester.tap(
|
||||
find.text(lookupAppLocalizations(const Locale('zh')).rename),
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
await tester.enterText(find.byType(TextFormField), 'Renamed second');
|
||||
await tester.tap(
|
||||
find.text(lookupAppLocalizations(const Locale('zh')).save),
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.text('Renamed second'), findsOneWidget);
|
||||
expect(
|
||||
repository.items.firstWhere((item) => item.id == 'second').title,
|
||||
'Renamed second',
|
||||
);
|
||||
|
||||
await tester.tap(find.byKey(const Key('project-chat-more')));
|
||||
await tester.pumpAndSettle();
|
||||
await tester.tap(
|
||||
find.text(lookupAppLocalizations(const Locale('zh')).agentMoveToTrash),
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.text('新聊天'), findsOneWidget);
|
||||
expect(
|
||||
container.read(conversationSelectionProvider('a')).selectedId,
|
||||
isNull,
|
||||
);
|
||||
await tester.tap(find.byKey(const Key('project-chat-history')));
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.text('Renamed second'), findsOneWidget);
|
||||
final trashTitle = tester.getRect(
|
||||
find.byKey(const Key('project-chat-trash-title')),
|
||||
);
|
||||
expect(
|
||||
trashTitle.left,
|
||||
tester.getRect(find.byKey(const Key('project-chat-group'))).left,
|
||||
);
|
||||
expect(tester.getRect(menuText('Renamed second')).left, trashTitle.left);
|
||||
expect(
|
||||
find.byKey(const ValueKey('sidebar-conversation-second')),
|
||||
findsNothing,
|
||||
);
|
||||
await tester.tap(
|
||||
find.byTooltip(lookupAppLocalizations(const Locale('zh')).agentRestore),
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
expect(
|
||||
find.byKey(const ValueKey('sidebar-conversation-second')),
|
||||
findsOneWidget,
|
||||
);
|
||||
|
||||
workspace.switchTo(projects.last);
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.byKey(const Key('project-chat-history-menu')), findsNothing);
|
||||
expect(find.text('Other project chat'), findsOneWidget);
|
||||
await tester.tap(find.byKey(const Key('project-chat-history')));
|
||||
await tester.pumpAndSettle();
|
||||
expect(
|
||||
find.byKey(const ValueKey('sidebar-conversation-other')),
|
||||
findsOneWidget,
|
||||
);
|
||||
expect(
|
||||
find.byKey(const ValueKey('sidebar-conversation-first')),
|
||||
findsNothing,
|
||||
);
|
||||
expect(
|
||||
find.byKey(const ValueKey('sidebar-conversation-second')),
|
||||
findsNothing,
|
||||
);
|
||||
expect(tester.takeException(), isNull);
|
||||
await tester.pumpWidget(const SizedBox());
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
ConversationMetadata _item(String id, String projectId, String title) =>
|
||||
ConversationMetadata(
|
||||
id: id,
|
||||
projectId: projectId,
|
||||
title: title,
|
||||
createdAt: DateTime.utc(2026),
|
||||
updatedAt: DateTime.utc(2026),
|
||||
providerId: 'provider',
|
||||
modelId: 'model',
|
||||
timelineId: 'timeline',
|
||||
pending: false,
|
||||
responseDurationsMs: const [],
|
||||
);
|
||||
|
||||
class _Projects extends Projects {
|
||||
_Projects(this.initial);
|
||||
final ProjectState initial;
|
||||
@override
|
||||
Future<ProjectState> build() async => initial;
|
||||
void switchTo(RecentProject project) =>
|
||||
state = AsyncData(state.requireValue.copyWith(activeProject: project));
|
||||
}
|
||||
|
||||
class _Conversations extends EmptyConversationRepository {
|
||||
_Conversations(this.items);
|
||||
final List<ConversationMetadata> items;
|
||||
final trashed = <ConversationMetadata>[];
|
||||
final selection = <String, String?>{'a': 'first', 'b': 'other'};
|
||||
@override
|
||||
Future<List<ConversationMetadata>> list(
|
||||
String projectId, {
|
||||
bool trash = false,
|
||||
}) async => (trash ? trashed : items)
|
||||
.where((item) => item.projectId == projectId)
|
||||
.toList();
|
||||
@override
|
||||
Future<String?> selected(String projectId) async => selection[projectId];
|
||||
@override
|
||||
Future<void> select(String projectId, String? conversationId) async =>
|
||||
selection[projectId] = conversationId;
|
||||
@override
|
||||
Future<ConversationMetadata> update(ConversationMetadata item) async {
|
||||
items[items.indexWhere((entry) => entry.id == item.id)] = item;
|
||||
return item;
|
||||
}
|
||||
|
||||
@override
|
||||
Future<void> trash(String projectId, String id) async {
|
||||
final item = items.firstWhere(
|
||||
(entry) => entry.projectId == projectId && entry.id == id,
|
||||
);
|
||||
items.remove(item);
|
||||
trashed.add(item);
|
||||
if (selection[projectId] == id) selection[projectId] = null;
|
||||
}
|
||||
|
||||
@override
|
||||
Future<void> restore(String projectId, String id) async {
|
||||
final item = trashed.firstWhere(
|
||||
(entry) => entry.projectId == projectId && entry.id == id,
|
||||
);
|
||||
trashed.remove(item);
|
||||
items.add(item);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,334 @@
|
||||
import 'dart:async';
|
||||
|
||||
import 'package:cutdex/app/editor_theme.dart';
|
||||
import 'package:cutdex/features/projects/conversation_sidebar.dart';
|
||||
import 'package:cutdex/features/projects/project_sidebar.dart';
|
||||
import 'package:cutdex/integrations/agent/conversation_repository.dart';
|
||||
import 'package:cutdex/l10n/app_localizations.dart';
|
||||
import 'package:cutdex/workspace/project_state.dart';
|
||||
import 'package:cutdex/workspace/projects.dart';
|
||||
import 'package:cutdex/workspace/workspace_mode.dart';
|
||||
import 'package:cutdex_sdk/project.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
|
||||
void main() {
|
||||
testWidgets(
|
||||
'missing conversation timeline still allows the project default',
|
||||
(tester) async {
|
||||
final sidebar = _Sidebar();
|
||||
await sidebar.mount(tester);
|
||||
final operation = sidebar.select(tester);
|
||||
sidebar.conversations.remembered.complete();
|
||||
await tester.pump();
|
||||
sidebar.projects.opened.complete(false);
|
||||
await tester.pump();
|
||||
expect(sidebar.projects._openCalls, 2);
|
||||
sidebar.projects._publish(_recent[1], timelineId: 'default');
|
||||
expect(sidebar.projects._openGuards.last!(), isTrue);
|
||||
sidebar.projects._fallbackOpened.complete(true);
|
||||
await expectLater(operation, completes);
|
||||
expect(sidebar.conversations.activated, ['chat']);
|
||||
await tester.pumpWidget(const SizedBox());
|
||||
},
|
||||
);
|
||||
|
||||
testWidgets('project change invalidates a still mounted sidebar request', (
|
||||
tester,
|
||||
) async {
|
||||
final sidebar = _Sidebar();
|
||||
await sidebar.mount(tester);
|
||||
final operation = sidebar.select(tester);
|
||||
sidebar.projects._publish(_recent[2]);
|
||||
await tester.pump();
|
||||
sidebar.conversations.remembered.complete();
|
||||
await expectLater(operation, completes);
|
||||
expect(sidebar.projects._openCalls, 0);
|
||||
expect(sidebar.conversations.activated, isEmpty);
|
||||
expect(sidebar.modes, isEmpty);
|
||||
await tester.pumpWidget(const SizedBox());
|
||||
});
|
||||
|
||||
testWidgets(
|
||||
'returning to the source project does not revive old navigation',
|
||||
(tester) async {
|
||||
final sidebar = _Sidebar();
|
||||
await sidebar.mount(tester);
|
||||
final operation = sidebar.select(tester);
|
||||
sidebar.projects._publish(_recent[2]);
|
||||
sidebar.projects._publish(_recent[0]);
|
||||
await tester.pump();
|
||||
sidebar.conversations.remembered.complete();
|
||||
await expectLater(operation, completes);
|
||||
expect(sidebar.projects._openCalls, 0);
|
||||
expect(sidebar.conversations.activated, isEmpty);
|
||||
await tester.pumpWidget(const SizedBox());
|
||||
},
|
||||
);
|
||||
|
||||
testWidgets('timeline change invalidates a pending conversation selection', (
|
||||
tester,
|
||||
) async {
|
||||
final sidebar = _Sidebar(activeProject: _recent[1]);
|
||||
await sidebar.mount(tester);
|
||||
final operation = sidebar.select(tester);
|
||||
sidebar.projects._publish(_recent[1], timelineId: 'other');
|
||||
await tester.pump();
|
||||
sidebar.conversations.remembered.complete();
|
||||
await expectLater(operation, completes);
|
||||
expect(sidebar.conversations.activated, isEmpty);
|
||||
expect(sidebar.modes, isEmpty);
|
||||
await tester.pumpWidget(const SizedBox());
|
||||
});
|
||||
|
||||
testWidgets(
|
||||
'latest conversation wins when selection saves finish in reverse',
|
||||
(tester) async {
|
||||
final sidebar = _Sidebar(activeProject: _recent[1]);
|
||||
await sidebar.mount(tester);
|
||||
final first = sidebar.select(tester);
|
||||
final second = sidebar.select(tester, id: 'next');
|
||||
sidebar.conversations.nextRemembered.complete();
|
||||
await expectLater(second, completes);
|
||||
sidebar.conversations.remembered.complete();
|
||||
await expectLater(first, completes);
|
||||
expect(sidebar.conversations.activated, ['next']);
|
||||
expect(sidebar.navigationCompletions, 1);
|
||||
await tester.pumpWidget(const SizedBox());
|
||||
},
|
||||
);
|
||||
|
||||
testWidgets('navigation allows the project transition it requested', (
|
||||
tester,
|
||||
) async {
|
||||
final sidebar = _Sidebar();
|
||||
await sidebar.mount(tester);
|
||||
final operation = sidebar.select(tester);
|
||||
sidebar.conversations.remembered.complete();
|
||||
await tester.pump();
|
||||
expect(sidebar.projects._openCalls, 1);
|
||||
expect(sidebar.projects._openGuards.single!(), isTrue);
|
||||
sidebar.projects._publish(_recent[1], timelineId: 'timeline');
|
||||
sidebar.projects.opened.complete(true);
|
||||
await expectLater(operation, completes);
|
||||
expect(sidebar.conversations.activated, ['chat']);
|
||||
expect(sidebar.modes, [WorkspaceMode.agent]);
|
||||
await tester.pumpWidget(const SizedBox());
|
||||
});
|
||||
|
||||
testWidgets('removed sidebar stops navigation after remembering selection', (
|
||||
tester,
|
||||
) async {
|
||||
final sidebar = _Sidebar();
|
||||
await sidebar.mount(tester);
|
||||
final operation = sidebar.select(tester);
|
||||
await tester.pump();
|
||||
await tester.pumpWidget(sidebar.host(const SizedBox()));
|
||||
sidebar.conversations.remembered.complete();
|
||||
await expectLater(operation, completes);
|
||||
expect(sidebar.projects._openCalls, 0);
|
||||
expect(sidebar.conversations.activated, isEmpty);
|
||||
expect(sidebar.modes, isEmpty);
|
||||
expect(tester.takeException(), isNull);
|
||||
await tester.pumpWidget(const SizedBox());
|
||||
});
|
||||
|
||||
testWidgets('removed sidebar does not retry a failed project open', (
|
||||
tester,
|
||||
) async {
|
||||
final sidebar = _Sidebar();
|
||||
await sidebar.mount(tester);
|
||||
final operation = sidebar.select(tester);
|
||||
sidebar.conversations.remembered.complete();
|
||||
await tester.pump();
|
||||
expect(sidebar.projects._openCalls, 1);
|
||||
await tester.pumpWidget(sidebar.host(const SizedBox()));
|
||||
expect(sidebar.projects._openGuards.single!(), isFalse);
|
||||
sidebar.projects.opened.complete(false);
|
||||
await expectLater(operation, completes);
|
||||
expect(sidebar.projects._openCalls, 1);
|
||||
expect(sidebar.conversations.activated, isEmpty);
|
||||
expect(sidebar.modes, isEmpty);
|
||||
expect(tester.takeException(), isNull);
|
||||
await tester.pumpWidget(const SizedBox());
|
||||
});
|
||||
|
||||
testWidgets('mounted sidebar still activates the selected conversation', (
|
||||
tester,
|
||||
) async {
|
||||
final sidebar = _Sidebar(activeProject: _recent[1]);
|
||||
await sidebar.mount(tester);
|
||||
final operation = sidebar.select(tester);
|
||||
sidebar.conversations.remembered.complete();
|
||||
await expectLater(operation, completes);
|
||||
await tester.pump();
|
||||
expect(sidebar.projects._openCalls, 0);
|
||||
expect(sidebar.conversations.activated, ['chat']);
|
||||
expect(sidebar.modes, [WorkspaceMode.agent]);
|
||||
expect(sidebar.navigationCompletions, 1);
|
||||
expect(tester.takeException(), isNull);
|
||||
await tester.pumpWidget(const SizedBox());
|
||||
});
|
||||
}
|
||||
|
||||
const _recent = [
|
||||
RecentProject(id: 'a', name: 'A', path: '/a'),
|
||||
RecentProject(id: 'b', name: 'B', path: '/b'),
|
||||
RecentProject(id: 'c', name: 'C', path: '/c'),
|
||||
];
|
||||
|
||||
class _Sidebar {
|
||||
_Sidebar({
|
||||
RecentProject activeProject = const RecentProject(
|
||||
id: 'a',
|
||||
name: 'A',
|
||||
path: '/a',
|
||||
),
|
||||
}) {
|
||||
initial = ProjectState(activeProject: activeProject, recent: _recent);
|
||||
projects = _Projects(initial);
|
||||
conversations = _Conversations(item);
|
||||
container = ProviderContainer(
|
||||
overrides: [
|
||||
projectsProvider.overrideWith(() => projects),
|
||||
conversationSidebarProvider.overrideWith(() => conversations),
|
||||
conversationSelectionProvider.overrideWith2((_) => _Selected()),
|
||||
],
|
||||
);
|
||||
addTearDown(container.dispose);
|
||||
}
|
||||
|
||||
late final ProjectState initial;
|
||||
late final _Projects projects;
|
||||
late final _Conversations conversations;
|
||||
late final ProviderContainer container;
|
||||
final modes = <WorkspaceMode>[];
|
||||
int navigationCompletions = 0;
|
||||
final item = ConversationMetadata(
|
||||
id: 'chat',
|
||||
projectId: 'b',
|
||||
title: 'Chat',
|
||||
createdAt: DateTime.utc(2026),
|
||||
updatedAt: DateTime.utc(2026),
|
||||
providerId: 'provider',
|
||||
modelId: 'model',
|
||||
timelineId: 'timeline',
|
||||
pending: false,
|
||||
responseDurationsMs: const [],
|
||||
);
|
||||
|
||||
Future<void> select(WidgetTester tester, {String id = 'chat'}) {
|
||||
final row = tester.widget<InkWell>(
|
||||
find.byKey(ValueKey('sidebar-conversation-$id')),
|
||||
);
|
||||
// InkWell declares a void callback, but navigation returns a future.
|
||||
// Await that operation so async lifecycle exceptions fail this test.
|
||||
return Function.apply(row.onTap!, []) as Future<void>;
|
||||
}
|
||||
|
||||
Widget host(Widget child) => UncontrolledProviderScope(
|
||||
container: container,
|
||||
child: MaterialApp(
|
||||
theme: EditorTheme.desktop(EditorTheme.penLight),
|
||||
localizationsDelegates: AppLocalizations.localizationsDelegates,
|
||||
supportedLocales: AppLocalizations.supportedLocales,
|
||||
locale: const Locale('zh'),
|
||||
home: Scaffold(body: SizedBox(width: 350, child: child)),
|
||||
),
|
||||
);
|
||||
|
||||
Future<void> mount(WidgetTester tester) async {
|
||||
await container.read(projectsProvider.future);
|
||||
await container.read(conversationSidebarProvider.future);
|
||||
await tester.pumpWidget(
|
||||
host(
|
||||
ProjectSidebar(
|
||||
agent: const SizedBox(),
|
||||
navigationOnly: true,
|
||||
mode: WorkspaceMode.agent,
|
||||
onModeChanged: modes.add,
|
||||
onNavigationComplete: () => navigationCompletions++,
|
||||
navigationWidth: 350,
|
||||
navigationCollapsed: false,
|
||||
agentHeaderLeading: const SizedBox(),
|
||||
editorHidden: false,
|
||||
onExpandEditor: null,
|
||||
state: initial,
|
||||
selectedProjectId: initial.activeProject!.id,
|
||||
integratedTitlebar: false,
|
||||
onCreateProject: null,
|
||||
onSelectProject: null,
|
||||
onRenameProject: (_) async => false,
|
||||
headerControls: const SizedBox(),
|
||||
),
|
||||
),
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
}
|
||||
}
|
||||
|
||||
class _Projects extends Projects {
|
||||
_Projects(this.initial);
|
||||
final ProjectState initial;
|
||||
final opened = Completer<bool>();
|
||||
final _fallbackOpened = Completer<bool>();
|
||||
int _openCalls = 0;
|
||||
final _openGuards = <bool Function()?>[];
|
||||
|
||||
void _publish(RecentProject project, {String? timelineId}) {
|
||||
state = AsyncData(
|
||||
state.requireValue.copyWith(
|
||||
activeProject: project,
|
||||
timeline: timelineId == null
|
||||
? null
|
||||
: TimelineDocument(id: timelineId, name: timelineId, sequences: []),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
Future<ProjectState> build() async => initial;
|
||||
|
||||
@override
|
||||
Future<bool> open(
|
||||
String path, {
|
||||
String? name,
|
||||
String? expectedId,
|
||||
String? timelineId,
|
||||
String? initialTimelineName,
|
||||
bool Function()? isCurrent,
|
||||
}) {
|
||||
_openCalls++;
|
||||
_openGuards.add(isCurrent);
|
||||
return _openCalls == 1 ? opened.future : _fallbackOpened.future;
|
||||
}
|
||||
}
|
||||
|
||||
class _Selected extends ConversationSelection {
|
||||
@override
|
||||
ConversationSelectionState build(String? projectId) =>
|
||||
const ConversationSelectionState(draftKey: 'draft', initialized: true);
|
||||
}
|
||||
|
||||
class _Conversations extends ConversationSidebar {
|
||||
_Conversations(this.item);
|
||||
final ConversationMetadata item;
|
||||
final remembered = Completer<void>();
|
||||
final nextRemembered = Completer<void>();
|
||||
final activated = <String>[];
|
||||
|
||||
@override
|
||||
Future<ConversationSnapshot> build() async => ConversationSnapshot(
|
||||
groups: {
|
||||
'b': [item, item.copyWith(id: 'next')],
|
||||
},
|
||||
);
|
||||
|
||||
@override
|
||||
Future<void> rememberSelection(ConversationMetadata item) =>
|
||||
item.id == 'next' ? nextRemembered.future : remembered.future;
|
||||
|
||||
@override
|
||||
void activate(ConversationMetadata item) => activated.add(item.id);
|
||||
}
|
||||
@@ -0,0 +1,117 @@
|
||||
import 'package:cutdex/features/projects/project_tabs_controller.dart';
|
||||
import 'package:cutdex/workspace/project_state.dart';
|
||||
import 'package:cutdex/workspace/projects.dart';
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
|
||||
void main() {
|
||||
TestWidgetsFlutterBinding.ensureInitialized();
|
||||
const first = RecentProject(id: 'a', name: 'First', path: '/first');
|
||||
const second = RecentProject(id: 'b', name: 'Second', path: '/second');
|
||||
const third = RecentProject(id: 'c', name: 'Recent only', path: '/third');
|
||||
late _Projects projects;
|
||||
late ProviderContainer container;
|
||||
late ProjectTabsController tabs;
|
||||
|
||||
setUp(() async {
|
||||
projects = _Projects(
|
||||
const ProjectState(activeProject: first, recent: [first, second, third]),
|
||||
);
|
||||
container = ProviderContainer(
|
||||
overrides: [projectsProvider.overrideWith(() => projects)],
|
||||
);
|
||||
await container.read(projectsProvider.future);
|
||||
tabs = container.read(projectTabsProvider.notifier);
|
||||
});
|
||||
tearDown(() => container.dispose());
|
||||
List<RecentProject> opened() => container.read(projectTabsProvider);
|
||||
|
||||
test(
|
||||
'tabs follow successful opens, keep order and exclude recent-only files',
|
||||
() {
|
||||
expect(opened(), [first]);
|
||||
projects.publish(projects._current.copyWith(activeProject: second));
|
||||
expect(opened(), [first, second]);
|
||||
projects.publish(projects._current.copyWith(activeProject: first));
|
||||
expect(opened(), [first, second]);
|
||||
projects.publish(projects._current.copyWith(projectBusy: true));
|
||||
expect(opened(), [first, second]);
|
||||
},
|
||||
);
|
||||
|
||||
test(
|
||||
'history removal and truncation do not discard opened project metadata',
|
||||
() {
|
||||
projects.publish(projects._current.copyWith(activeProject: second));
|
||||
projects.publish(projects._current.copyWith(recent: const [third]));
|
||||
expect(opened(), [first, second]);
|
||||
projects.publish(projects._current.copyWith(activeProject: null));
|
||||
expect(opened(), [first, second]);
|
||||
tabs.remove(second.id);
|
||||
expect(opened(), [first]);
|
||||
projects.publish(projects._current.copyWith(activeProject: second));
|
||||
expect(opened(), [first, second]);
|
||||
},
|
||||
);
|
||||
|
||||
test('metadata changes update tabs without changing their order', () {
|
||||
projects.publish(projects._current.copyWith(activeProject: second));
|
||||
final renamed = first.copyWith(name: 'Renamed');
|
||||
final relocated = second.copyWith(path: '/new-second');
|
||||
projects.publish(
|
||||
projects._current.copyWith(
|
||||
recent: [renamed, relocated, third],
|
||||
activeProject: relocated,
|
||||
),
|
||||
);
|
||||
expect(opened(), [renamed, relocated]);
|
||||
projects.publish(projects._current.copyWith(recent: const []));
|
||||
final renamedAgain = renamed.copyWith(name: 'Renamed outside history');
|
||||
tabs.updateProject(renamedAgain);
|
||||
expect(opened(), [renamedAgain, relocated]);
|
||||
});
|
||||
|
||||
test('history updates do not reopen a closed inactive tab', () {
|
||||
projects.publish(projects._current.copyWith(activeProject: second));
|
||||
tabs.remove(first.id);
|
||||
projects.publish(
|
||||
projects._current.copyWith(
|
||||
recent: [
|
||||
first.copyWith(name: 'Updated'),
|
||||
second,
|
||||
],
|
||||
),
|
||||
);
|
||||
expect(opened(), [second]);
|
||||
expect(() => opened().clear(), throwsUnsupportedError);
|
||||
});
|
||||
|
||||
test('all opened projects remain available beyond the twenty-entry history limit', () {
|
||||
for (var index = 0; index < 25; index++) {
|
||||
final project = RecentProject(
|
||||
id: 'extra-$index',
|
||||
name: 'Project $index',
|
||||
path: '/extra-$index',
|
||||
);
|
||||
projects.publish(
|
||||
projects._current.copyWith(
|
||||
activeProject: project,
|
||||
recent: [project, ...projects._current.recent].take(20).toList(),
|
||||
),
|
||||
);
|
||||
}
|
||||
expect(projects._current.recent, hasLength(20));
|
||||
expect(opened(), hasLength(26));
|
||||
expect(opened().first, first);
|
||||
expect(opened().last.id, 'extra-24');
|
||||
});
|
||||
}
|
||||
|
||||
class _Projects extends Projects {
|
||||
_Projects(this.initial);
|
||||
final ProjectState initial;
|
||||
@override
|
||||
Future<ProjectState> build() async => initial;
|
||||
ProjectState get _current => state.requireValue;
|
||||
void publish(ProjectState value) => state = AsyncData(value);
|
||||
}
|
||||
@@ -1,5 +1,6 @@
|
||||
import 'package:cutdex/integrations/platform/file_picker.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:cutdex/workspace/media_import.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
|
||||
@@ -7,6 +8,7 @@ void main() {
|
||||
TestWidgetsFlutterBinding.ensureInitialized();
|
||||
const picker = AppFilePicker();
|
||||
const channel = MethodChannel('filegate');
|
||||
const nativeChannel = MethodChannel('cutdex_native/file_picker');
|
||||
Object? response;
|
||||
MethodCall? lastCall;
|
||||
|
||||
@@ -22,6 +24,60 @@ void main() {
|
||||
tearDown(() {
|
||||
TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger
|
||||
.setMockMethodCallHandler(channel, null);
|
||||
TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger
|
||||
.setMockMethodCallHandler(nativeChannel, null);
|
||||
debugDefaultTargetPlatformOverride = null;
|
||||
});
|
||||
|
||||
test(
|
||||
'macOS uses the window-owned picker and preserves local paths',
|
||||
() async {
|
||||
debugDefaultTargetPlatformOverride = TargetPlatform.macOS;
|
||||
MethodCall? nativeCall;
|
||||
TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger
|
||||
.setMockMethodCallHandler(nativeChannel, (call) async {
|
||||
nativeCall = call;
|
||||
return ['/tmp/a b.mp4', '/tmp/中文.wav'];
|
||||
});
|
||||
expect(
|
||||
await picker.pickFiles(allowedExtensions: ['.MP4', 'wav', 'mp4']),
|
||||
[
|
||||
const ExternalMediaFile(path: '/tmp/a b.mp4'),
|
||||
const ExternalMediaFile(path: '/tmp/中文.wav'),
|
||||
],
|
||||
);
|
||||
expect(nativeCall!.method, 'pickFiles');
|
||||
expect(nativeCall!.arguments, {
|
||||
'allowedExtensions': ['mp4', 'wav'],
|
||||
});
|
||||
expect(lastCall, isNull);
|
||||
},
|
||||
);
|
||||
|
||||
test('macOS cancellation produces no selection', () async {
|
||||
debugDefaultTargetPlatformOverride = TargetPlatform.macOS;
|
||||
TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger
|
||||
.setMockMethodCallHandler(nativeChannel, (_) async => null);
|
||||
expect(await picker.pickFiles(allowedExtensions: ['mp4']), isEmpty);
|
||||
expect(lastCall, isNull);
|
||||
});
|
||||
|
||||
test('macOS reports a busy or unavailable host window', () async {
|
||||
debugDefaultTargetPlatformOverride = TargetPlatform.macOS;
|
||||
for (final code in ['picker_active', 'window_unavailable']) {
|
||||
TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger
|
||||
.setMockMethodCallHandler(
|
||||
nativeChannel,
|
||||
(_) async => throw PlatformException(code: code),
|
||||
);
|
||||
await expectLater(
|
||||
picker.pickFiles(allowedExtensions: ['mp4']),
|
||||
throwsA(
|
||||
isA<PlatformException>().having((error) => error.code, 'code', code),
|
||||
),
|
||||
);
|
||||
}
|
||||
expect(lastCall, isNull);
|
||||
});
|
||||
|
||||
test(
|
||||
|
||||
@@ -3,6 +3,142 @@ import 'package:flutter/widgets.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
|
||||
void main() {
|
||||
testWidgets('selector activation must use the new owner callback', (
|
||||
tester,
|
||||
) async {
|
||||
final source = ValueNotifier(0);
|
||||
addTearDown(source.dispose);
|
||||
final key = GlobalKey();
|
||||
var moved = false;
|
||||
late StateSetter update;
|
||||
Widget region() => Builder(
|
||||
builder: (owner) => ListenableSelector<int>(
|
||||
key: key,
|
||||
listenable: source,
|
||||
select: () {
|
||||
Directionality.of(owner);
|
||||
return source.value;
|
||||
},
|
||||
builder: (_, value) => Text('$value'),
|
||||
),
|
||||
);
|
||||
await tester.pumpWidget(
|
||||
Directionality(
|
||||
textDirection: TextDirection.ltr,
|
||||
child: StatefulBuilder(
|
||||
builder: (_, setState) {
|
||||
update = setState;
|
||||
return Row(
|
||||
children: [
|
||||
Expanded(child: moved ? const SizedBox() : region()),
|
||||
Expanded(child: moved ? region() : const SizedBox()),
|
||||
],
|
||||
);
|
||||
},
|
||||
),
|
||||
),
|
||||
);
|
||||
update(() => moved = true);
|
||||
await tester.pump();
|
||||
expect(tester.takeException(), isNull);
|
||||
source.value = 1;
|
||||
await tester.pump();
|
||||
expect(find.text('1'), findsOneWidget);
|
||||
await tester.pumpWidget(const SizedBox());
|
||||
});
|
||||
|
||||
testWidgets('deactivated selection ignores replacement notifications', (
|
||||
tester,
|
||||
) async {
|
||||
final source = _Source((time: 0, playing: false));
|
||||
addTearDown(source.dispose);
|
||||
var selections = 0;
|
||||
var listeningAtReplacement = true;
|
||||
Widget host(Widget child) =>
|
||||
Directionality(textDirection: TextDirection.ltr, child: child);
|
||||
await tester.pumpWidget(
|
||||
host(
|
||||
Builder(
|
||||
builder: (ownerContext) => ListenableSelector<int>(
|
||||
listenable: source,
|
||||
select: () {
|
||||
selections++;
|
||||
Directionality.of(ownerContext);
|
||||
return source.value.time;
|
||||
},
|
||||
builder: (_, value) => Text('$value'),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
final initial = selections;
|
||||
await tester.pumpWidget(
|
||||
host(
|
||||
_NotifyOnMount(() {
|
||||
listeningAtReplacement = source.subscribed;
|
||||
source.value = (time: 1, playing: false);
|
||||
}),
|
||||
),
|
||||
);
|
||||
expect(tester.takeException(), isNull);
|
||||
expect(listeningAtReplacement, isFalse);
|
||||
expect(selections, initial);
|
||||
expect(source.subscribed, isFalse);
|
||||
});
|
||||
|
||||
testWidgets('reparented selection resumes and catches up before rendering', (
|
||||
tester,
|
||||
) async {
|
||||
final source = _Source((time: 0, playing: false));
|
||||
addTearDown(source.dispose);
|
||||
final key = GlobalKey();
|
||||
var moved = false;
|
||||
var listeningDuringMove = true;
|
||||
late StateSetter move;
|
||||
await tester.pumpWidget(
|
||||
Directionality(
|
||||
textDirection: TextDirection.ltr,
|
||||
child: StatefulBuilder(
|
||||
builder: (context, setState) {
|
||||
move = setState;
|
||||
final selection = ListenableSelector<int>(
|
||||
key: key,
|
||||
listenable: source,
|
||||
select: () => source.value.time,
|
||||
builder: (_, value) => Text('$value'),
|
||||
);
|
||||
return Row(
|
||||
children: [
|
||||
SizedBox(
|
||||
child: moved
|
||||
? _NotifyOnMount(() {
|
||||
listeningDuringMove = source.subscribed;
|
||||
source.value = (time: 7, playing: false);
|
||||
})
|
||||
: selection,
|
||||
),
|
||||
SizedBox(child: moved ? selection : const SizedBox()),
|
||||
],
|
||||
);
|
||||
},
|
||||
),
|
||||
),
|
||||
);
|
||||
final element = tester.element(find.byKey(key));
|
||||
move(() => moved = true);
|
||||
await tester.pump();
|
||||
expect(listeningDuringMove, isFalse);
|
||||
expect(tester.element(find.byKey(key)), same(element));
|
||||
expect(find.text('7'), findsOneWidget);
|
||||
expect(source.subscribed, isTrue);
|
||||
source.value = (time: 8, playing: false);
|
||||
await tester.pump();
|
||||
expect(find.text('8'), findsOneWidget);
|
||||
expect(tester.takeException(), isNull);
|
||||
await tester.pumpWidget(const SizedBox());
|
||||
expect(source.subscribed, isFalse);
|
||||
});
|
||||
|
||||
testWidgets('selection ignores unrelated events and detaches old sources', (
|
||||
tester,
|
||||
) async {
|
||||
@@ -40,6 +176,73 @@ void main() {
|
||||
await tester.pumpWidget(const SizedBox());
|
||||
expect(second.subscribed, isFalse);
|
||||
});
|
||||
testWidgets('hidden selection pauses observation and catches up on reveal', (
|
||||
tester,
|
||||
) async {
|
||||
final source = _Source((time: 0, playing: false));
|
||||
addTearDown(source.dispose);
|
||||
var visible = true;
|
||||
var selections = 0;
|
||||
late StateSetter changeVisibility;
|
||||
await tester.pumpWidget(
|
||||
Directionality(
|
||||
textDirection: TextDirection.ltr,
|
||||
child: StatefulBuilder(
|
||||
builder: (context, setState) {
|
||||
changeVisibility = setState;
|
||||
return TickerMode(
|
||||
enabled: visible,
|
||||
child: ListenableSelector<int>(
|
||||
listenable: source,
|
||||
select: () {
|
||||
selections++;
|
||||
return source.value.time;
|
||||
},
|
||||
builder: (context, time) => Text('$time'),
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
),
|
||||
);
|
||||
final element = tester.element(find.byType(Text));
|
||||
changeVisibility(() => visible = false);
|
||||
await tester.pump();
|
||||
expect(source.subscribed, isFalse);
|
||||
final hiddenSelections = selections;
|
||||
for (var tick = 1; tick <= 120; tick++) {
|
||||
source.value = (time: tick, playing: false);
|
||||
await tester.pump();
|
||||
}
|
||||
expect(selections, hiddenSelections);
|
||||
expect(find.text('0'), findsOneWidget);
|
||||
changeVisibility(() => visible = true);
|
||||
await tester.pump();
|
||||
expect(source.subscribed, isTrue);
|
||||
expect(find.text('120'), findsOneWidget);
|
||||
expect(tester.element(find.byType(Text)), same(element));
|
||||
await tester.pumpWidget(const SizedBox());
|
||||
expect(source.subscribed, isFalse);
|
||||
});
|
||||
}
|
||||
|
||||
class _NotifyOnMount extends StatefulWidget {
|
||||
const _NotifyOnMount(this.notify);
|
||||
final VoidCallback notify;
|
||||
|
||||
@override
|
||||
State<_NotifyOnMount> createState() => _NotifyOnMountState();
|
||||
}
|
||||
|
||||
class _NotifyOnMountState extends State<_NotifyOnMount> {
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
widget.notify();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) => const SizedBox();
|
||||
}
|
||||
|
||||
class _Source extends ValueNotifier<({int time, bool playing})> {
|
||||
|
||||
@@ -84,17 +84,31 @@ void main() {
|
||||
expect(tester.getRect(sidebar).right, tester.getRect(divider).left);
|
||||
expect(tester.getRect(sidebar).height, frameSize.height);
|
||||
expect(
|
||||
tester.getRect(find.text('外观')).left,
|
||||
tester.getRect(find.text('语言')).left,
|
||||
greaterThan(tester.getRect(divider).right),
|
||||
);
|
||||
expect(
|
||||
tester.widget<Text>(find.text('外观')).style?.fontSize,
|
||||
tester.widget<Text>(find.text('语言')).style?.fontSize,
|
||||
AppTheme.settingsContentTheme(EditorTheme.penDark)
|
||||
.textTheme
|
||||
.labelLarge
|
||||
?.fontSize,
|
||||
);
|
||||
expect(find.text('语言'), findsOneWidget);
|
||||
await tester.tap(find.byKey(const ValueKey('settings-navigation-3')));
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.byKey(const Key('settings-color-palette')), findsOneWidget);
|
||||
expect(
|
||||
tester.getRect(find.text('主题')).left,
|
||||
greaterThan(tester.getRect(divider).right),
|
||||
);
|
||||
expect(
|
||||
tester.widget<Text>(find.text('主题')).style?.fontSize,
|
||||
AppTheme.settingsContentTheme(EditorTheme.penDark)
|
||||
.textTheme
|
||||
.labelLarge
|
||||
?.fontSize,
|
||||
);
|
||||
expect(find.text('外观'), findsOneWidget);
|
||||
await tester.tap(find.text('MCP').first);
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.text('监听端口'), findsOneWidget);
|
||||
|
||||
@@ -0,0 +1,110 @@
|
||||
import 'package:cutdex/features/media/media_browser_body.dart';
|
||||
import 'package:cutdex/features/media/media_browser_controller.dart';
|
||||
import 'package:cutdex/l10n/app_localizations.dart';
|
||||
import 'package:cutdex/workspace/project_state.dart';
|
||||
import 'package:cutdex/workspace/projects.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
|
||||
void main() {
|
||||
testWidgets('local browsing updates keep provider subscriptions bounded', (
|
||||
tester,
|
||||
) async {
|
||||
final container = ProviderContainer(
|
||||
overrides: [projectsProvider.overrideWith(_Projects.new)],
|
||||
);
|
||||
addTearDown(container.dispose);
|
||||
await container.read(projectsProvider.future);
|
||||
await tester.pumpWidget(
|
||||
UncontrolledProviderScope(
|
||||
container: container,
|
||||
child: const MaterialApp(
|
||||
localizationsDelegates: AppLocalizations.localizationsDelegates,
|
||||
supportedLocales: AppLocalizations.supportedLocales,
|
||||
home: Scaffold(
|
||||
body: MediaBrowserBody(
|
||||
projectId: 'project',
|
||||
grid: true,
|
||||
desktop: true,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
final projects = container.read(projectsProvider.notifier) as _Projects;
|
||||
Future<int> subscriptionWork() async {
|
||||
projects._project.idReads = 0;
|
||||
projects.publishUnselectedChange();
|
||||
await tester.pumpAndSettle();
|
||||
return projects._project.idReads;
|
||||
}
|
||||
|
||||
final before = await subscriptionWork();
|
||||
expect(before, greaterThan(0));
|
||||
final browser = container.read(mediaBrowserProvider('project'));
|
||||
for (var i = 0; i < 20; i++) {
|
||||
browser.query = 'query $i';
|
||||
browser.filter = MediaFilter.values[i % MediaFilter.values.length];
|
||||
browser.sort = MediaSort.values[i % MediaSort.values.length];
|
||||
browser.gridSize = MediaGridSize.values[i % MediaGridSize.values.length];
|
||||
await tester.pump();
|
||||
expect(await subscriptionWork(), before);
|
||||
}
|
||||
expect(tester.takeException(), isNull);
|
||||
await tester.pumpWidget(const SizedBox());
|
||||
});
|
||||
}
|
||||
|
||||
class _Projects extends Projects {
|
||||
final _project = _CountingProject();
|
||||
var _revision = 0;
|
||||
|
||||
@override
|
||||
Future<ProjectState> build() async => ProjectState(activeProject: _project);
|
||||
|
||||
void publishUnselectedChange() {
|
||||
state = AsyncData(
|
||||
state.requireValue.copyWith(
|
||||
recent: [
|
||||
RecentProject(
|
||||
id: 'recent-${_revision++}',
|
||||
name: 'Recent',
|
||||
path: '/Recent.cutdex',
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
// Count selector evaluations through the public state model. Extra provider
|
||||
// subscriptions increase this work even when the selected values stay equal.
|
||||
class _CountingProject implements RecentProject {
|
||||
final _value = const RecentProject(
|
||||
id: 'project',
|
||||
name: 'Project',
|
||||
path: '/Project.cutdex',
|
||||
);
|
||||
int idReads = 0;
|
||||
|
||||
@override
|
||||
String get id {
|
||||
idReads++;
|
||||
return _value.id;
|
||||
}
|
||||
|
||||
@override
|
||||
String get name => _value.name;
|
||||
|
||||
@override
|
||||
String get path => _value.path;
|
||||
|
||||
@override
|
||||
ProjectAvailability get availability => _value.availability;
|
||||
|
||||
@override
|
||||
$RecentProjectCopyWith<RecentProject> get copyWith => _value.copyWith;
|
||||
}
|
||||
@@ -7,6 +7,7 @@ import 'package:cutdex/workspace/media_color_interpretation.dart';
|
||||
import 'package:cutdex/workspace/timeline_session.dart';
|
||||
import 'package:cutdex_sdk/runtime.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:cutdex_ui/theme.dart';
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
|
||||
@@ -55,85 +56,103 @@ void main() {
|
||||
});
|
||||
|
||||
for (final width in [240.0, 400.0]) {
|
||||
testWidgets(
|
||||
'color inspector at $width saves source interpretation and restores automatic',
|
||||
(tester) async {
|
||||
await tester.runAsync(() async {
|
||||
final f = await createPreviewFixture(Uri.file('/test/video.mov'));
|
||||
final preview = _ColorPreview(f.timeline);
|
||||
addTearDown(
|
||||
() => tester.runAsync(() async {
|
||||
await preview.close();
|
||||
await f.workspace.close();
|
||||
await f.directory.delete(recursive: true);
|
||||
}),
|
||||
);
|
||||
await tester.pumpWidget(
|
||||
ProviderScope(
|
||||
overrides: [
|
||||
editorPreviewProvider(
|
||||
'project',
|
||||
'project',
|
||||
).overrideWith((_) async => preview),
|
||||
],
|
||||
child: MaterialApp(
|
||||
localizationsDelegates: AppLocalizations.localizationsDelegates,
|
||||
supportedLocales: AppLocalizations.supportedLocales,
|
||||
locale: const Locale('zh'),
|
||||
for (final desktop in [false, true]) {
|
||||
testWidgets(
|
||||
'color inspector desktop=$desktop at $width saves source interpretation and restores automatic',
|
||||
(tester) async {
|
||||
await tester.runAsync(() async {
|
||||
final f = await createPreviewFixture(Uri.file('/test/video.mov'));
|
||||
final preview = _ColorPreview(f.timeline);
|
||||
addTearDown(
|
||||
() => tester.runAsync(() async {
|
||||
await preview.close();
|
||||
await f.workspace.close();
|
||||
await f.directory.delete(recursive: true);
|
||||
}),
|
||||
);
|
||||
await tester.pumpWidget(
|
||||
ProviderScope(
|
||||
overrides: [
|
||||
editorPreviewProvider(
|
||||
'project',
|
||||
'project',
|
||||
).overrideWith((_) async => preview),
|
||||
],
|
||||
child: MaterialApp(
|
||||
localizationsDelegates:
|
||||
AppLocalizations.localizationsDelegates,
|
||||
supportedLocales: AppLocalizations.supportedLocales,
|
||||
locale: const Locale('zh'),
|
||||
|
||||
theme: EditorTheme.penDark,
|
||||
home: Scaffold(
|
||||
body: Center(
|
||||
child: SizedBox(
|
||||
width: width,
|
||||
child: ColorInterpretationProperties(
|
||||
projectId: 'project',
|
||||
timelineId: 'project',
|
||||
session: f.timeline,
|
||||
assetId: 'media',
|
||||
trackIndex: 0,
|
||||
theme: desktop
|
||||
? AppTheme.propertiesPanelTheme(
|
||||
EditorTheme.desktop(EditorTheme.penDark),
|
||||
)
|
||||
: EditorTheme.penDark,
|
||||
home: Scaffold(
|
||||
body: Center(
|
||||
child: SizedBox(
|
||||
width: width,
|
||||
child: ColorInterpretationProperties(
|
||||
projectId: 'project',
|
||||
timelineId: 'project',
|
||||
session: f.timeline,
|
||||
assetId: 'media',
|
||||
trackIndex: 0,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.text('色彩空间未知,暂按 Rec.709 显示'), findsOneWidget);
|
||||
expect(
|
||||
f.timeline.settings.containsKey('mediaColorInterpretations'),
|
||||
isFalse,
|
||||
);
|
||||
await tester.tap(find.byKey(const Key('media-color-menu')));
|
||||
await tester.pumpAndSettle();
|
||||
await tester.tap(find.text('线性 Rec.2020'));
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.text('手动指定:线性 Rec.2020'), findsOneWidget);
|
||||
expect(tester.takeException(), isNull);
|
||||
{
|
||||
await f.timeline.flush();
|
||||
final saved = await f.workspace.project!.loadTimeline('project');
|
||||
final reopened = EditorTimelineSession(
|
||||
document: saved,
|
||||
persistence: f.timeline.persistence,
|
||||
assetUris: f.timeline.assetUris,
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
if (desktop) {
|
||||
expect(find.byKey(const Key('media-color-menu')), findsNothing);
|
||||
await tester.tap(find.byType(ExpansionTile));
|
||||
await tester.pumpAndSettle();
|
||||
}
|
||||
expect(find.text('色彩空间未知,暂按 Rec.709 显示'), findsOneWidget);
|
||||
expect(
|
||||
reopened.mediaColorInterpretation('media', 0),
|
||||
RenderColorSpace.linearRec2020,
|
||||
f.timeline.settings.containsKey('mediaColorInterpretations'),
|
||||
isFalse,
|
||||
);
|
||||
expect(reopened.mediaColorInterpretation('media', 1), isNull);
|
||||
}
|
||||
await tester.tap(find.byKey(const Key('media-color-menu')));
|
||||
await tester.pumpAndSettle();
|
||||
await tester.tap(find.text('自动'));
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.text('色彩空间未知,暂按 Rec.709 显示'), findsOneWidget);
|
||||
expect(f.timeline.mediaColorInterpretation('media', 0), isNull);
|
||||
expect(tester.takeException(), isNull);
|
||||
});
|
||||
},
|
||||
);
|
||||
await tester.tap(find.byKey(const Key('media-color-menu')));
|
||||
await tester.pumpAndSettle();
|
||||
await tester.tap(find.text('线性 Rec.2020'));
|
||||
await tester.pumpAndSettle();
|
||||
if (desktop) {
|
||||
await tester.tap(find.byType(ExpansionTile));
|
||||
await tester.pumpAndSettle();
|
||||
await tester.tap(find.byType(ExpansionTile));
|
||||
await tester.pumpAndSettle();
|
||||
}
|
||||
expect(find.text('手动指定:线性 Rec.2020'), findsOneWidget);
|
||||
expect(tester.takeException(), isNull);
|
||||
{
|
||||
await f.timeline.flush();
|
||||
final saved = await f.workspace.project!.loadTimeline('project');
|
||||
final reopened = EditorTimelineSession(
|
||||
document: saved,
|
||||
persistence: f.timeline.persistence,
|
||||
assetUris: f.timeline.assetUris,
|
||||
);
|
||||
expect(
|
||||
reopened.mediaColorInterpretation('media', 0),
|
||||
RenderColorSpace.linearRec2020,
|
||||
);
|
||||
expect(reopened.mediaColorInterpretation('media', 1), isNull);
|
||||
}
|
||||
await tester.tap(find.byKey(const Key('media-color-menu')));
|
||||
await tester.pumpAndSettle();
|
||||
await tester.tap(find.text('自动'));
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.text('色彩空间未知,暂按 Rec.709 显示'), findsOneWidget);
|
||||
expect(f.timeline.mediaColorInterpretation('media', 0), isNull);
|
||||
expect(tester.takeException(), isNull);
|
||||
});
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
+598
-133
@@ -8,7 +8,7 @@ import 'dart:async';
|
||||
import 'dart:ui' as ui;
|
||||
|
||||
import 'package:cutdex/features/media/media_panel.dart';
|
||||
import 'package:cutdex/features/media/media_asset_strip.dart';
|
||||
import 'package:cutdex_ui/icons.dart';
|
||||
import 'package:cutdex_ui/theme.dart';
|
||||
import 'package:cutdex/shared/widgets/drop_to_add_overlay.dart';
|
||||
import 'package:cutdex/workspace/projects.dart';
|
||||
@@ -130,7 +130,7 @@ void main() {
|
||||
locale: locale,
|
||||
localizationsDelegates: AppLocalizations.localizationsDelegates,
|
||||
supportedLocales: AppLocalizations.supportedLocales,
|
||||
theme: EditorTheme.penLight,
|
||||
theme: EditorTheme.desktop(EditorTheme.penLight),
|
||||
home: Scaffold(
|
||||
body: MediaQuery(
|
||||
data: const MediaQueryData(
|
||||
@@ -269,7 +269,10 @@ void main() {
|
||||
await tester.tap(find.text('重命名'));
|
||||
await tester.pumpAndSettle();
|
||||
expect(
|
||||
tester.widget<TextField>(find.byType(TextField)).controller!.text,
|
||||
tester
|
||||
.widget<TextField>(find.byType(TextField).last)
|
||||
.controller!
|
||||
.text,
|
||||
'second.txt',
|
||||
);
|
||||
await tester.tap(find.text('取消'));
|
||||
@@ -333,7 +336,9 @@ void main() {
|
||||
supportedLocales: AppLocalizations.supportedLocales,
|
||||
locale: const Locale('zh'),
|
||||
|
||||
theme: EditorTheme.penLight,
|
||||
theme: touch
|
||||
? EditorTheme.penLight
|
||||
: EditorTheme.desktop(EditorTheme.penLight),
|
||||
home: Scaffold(
|
||||
body: touch
|
||||
? const MediaBrowserPage(projectId: 'project')
|
||||
@@ -346,57 +351,157 @@ void main() {
|
||||
return container;
|
||||
}
|
||||
|
||||
testWidgets('list uses a filmstrip with real duration above its name', (
|
||||
tester,
|
||||
) async {
|
||||
const channel = MethodChannel('cutdex_runtime');
|
||||
final times = <int>[];
|
||||
tester.binding.defaultBinaryMessenger.setMockMethodCallHandler(channel, (
|
||||
call,
|
||||
) async {
|
||||
if (call.method == 'probe') {
|
||||
return {
|
||||
'duration': {'numerator': '290', 'denominator': 1},
|
||||
'videoTrackCount': 1,
|
||||
'videoTrackIds': [1],
|
||||
'audioTrackCount': 0,
|
||||
'audioTrackIds': <int>[],
|
||||
'audioTracks': <Object?>[],
|
||||
'isProtected': false,
|
||||
};
|
||||
}
|
||||
if (call.method == 'thumbnail') {
|
||||
final args = call.arguments as Map;
|
||||
final time = args['time'] as Map;
|
||||
times.add(int.parse(time['numerator'].toString()));
|
||||
}
|
||||
throw PlatformException(code: 'no-preview');
|
||||
});
|
||||
addTearDown(
|
||||
() => tester.binding.defaultBinaryMessenger.setMockMethodCallHandler(
|
||||
channel,
|
||||
null,
|
||||
for (final touch in [false, true]) {
|
||||
testWidgets(
|
||||
'${touch ? 'touch' : 'desktop'} waits for file selection without a loading bar',
|
||||
(tester) async {
|
||||
final channel = MethodChannel(
|
||||
touch ? 'filegate' : 'cutdex_native/file_picker',
|
||||
);
|
||||
final cancelled = Completer<Object?>();
|
||||
final selected = Completer<Object?>();
|
||||
var pickerCalls = 0;
|
||||
tester.binding.defaultBinaryMessenger.setMockMethodCallHandler(
|
||||
channel,
|
||||
(_) => pickerCalls++ == 0 ? cancelled.future : selected.future,
|
||||
);
|
||||
addTearDown(
|
||||
() => tester.binding.defaultBinaryMessenger.setMockMethodCallHandler(
|
||||
channel,
|
||||
null,
|
||||
),
|
||||
);
|
||||
final container = await mount(tester, touch: touch);
|
||||
final projects = container.read(projectsProvider.notifier) as _Projects;
|
||||
final imported = Completer<void>();
|
||||
projects.importGate = imported.future;
|
||||
final button = find.byKey(const Key('media-import-button'));
|
||||
|
||||
Future<void> openPicker() async {
|
||||
await tester.tap(button);
|
||||
await tester.pump();
|
||||
await tester.pump(const Duration(milliseconds: 500));
|
||||
expect(find.byType(LinearProgressIndicator), findsNothing);
|
||||
expect(tester.widget<TextButton>(button).onPressed, isNull);
|
||||
}
|
||||
|
||||
await openPicker();
|
||||
cancelled.complete(null);
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.byType(LinearProgressIndicator), findsNothing);
|
||||
expect(tester.widget<TextButton>(button).onPressed, isNotNull);
|
||||
expect(projects.received, isEmpty);
|
||||
|
||||
await openPicker();
|
||||
selected.complete(
|
||||
touch
|
||||
? [
|
||||
{
|
||||
'path': '/originals/clip.mp4',
|
||||
'name': 'clip.mp4',
|
||||
'kind': 'file',
|
||||
},
|
||||
]
|
||||
: ['/originals/clip.mp4'],
|
||||
);
|
||||
await tester.pump();
|
||||
await tester.pump();
|
||||
await tester.pump(const Duration(milliseconds: 250));
|
||||
await tester.pump();
|
||||
expect(find.byType(LinearProgressIndicator), findsOneWidget);
|
||||
expect(tester.widget<TextButton>(button).onPressed, isNull);
|
||||
|
||||
imported.complete();
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.byType(LinearProgressIndicator), findsNothing);
|
||||
expect(tester.widget<TextButton>(button).onPressed, isNotNull);
|
||||
expect(projects.received.single.localPath, '/originals/clip.mp4');
|
||||
expect(pickerCalls, 2);
|
||||
expect(tester.takeException(), isNull);
|
||||
},
|
||||
variant: TargetPlatformVariant.only(
|
||||
touch ? TargetPlatform.android : TargetPlatform.macOS,
|
||||
),
|
||||
);
|
||||
final container = await mount(tester);
|
||||
await (container.read(projectsProvider.notifier) as _Projects)
|
||||
.importExternalMedia('project', [
|
||||
const ExternalMediaFile(path: '/movie.mp4'),
|
||||
]);
|
||||
await tester.pumpAndSettle();
|
||||
await tester.tap(find.byTooltip('列表布局'));
|
||||
await tester.pumpAndSettle();
|
||||
final strip = tester.getRect(find.byType(MediaAssetStrip));
|
||||
final name = tester.getRect(find.text('movie.mp4'));
|
||||
final duration = tester.getRect(find.text('04:50'));
|
||||
expect(strip.height, 46);
|
||||
expect(name.top, greaterThanOrEqualTo(strip.bottom));
|
||||
expect(duration.right, lessThanOrEqualTo(strip.right));
|
||||
expect(duration.left, greaterThan(strip.center.dx));
|
||||
expect(duration.top, strip.top + 5);
|
||||
expect(times.any((time) => time > 0), isTrue);
|
||||
expect(tester.takeException(), isNull);
|
||||
});
|
||||
}
|
||||
|
||||
testWidgets(
|
||||
'desktop list uses a compact cover with real duration beside its name',
|
||||
(tester) async {
|
||||
await tester.binding.setSurfaceSize(const Size(320, 600));
|
||||
addTearDown(() => tester.binding.setSurfaceSize(null));
|
||||
const channel = MethodChannel('cutdex_runtime');
|
||||
final times = <int>[];
|
||||
tester.binding.defaultBinaryMessenger.setMockMethodCallHandler(channel, (
|
||||
call,
|
||||
) async {
|
||||
if (call.method == 'probe') {
|
||||
return {
|
||||
'duration': {'numerator': '290', 'denominator': 1},
|
||||
'videoTrackCount': 1,
|
||||
'videoTrackIds': [1],
|
||||
'audioTrackCount': 0,
|
||||
'audioTrackIds': <int>[],
|
||||
'audioTracks': <Object?>[],
|
||||
'isProtected': false,
|
||||
};
|
||||
}
|
||||
if (call.method == 'thumbnail') {
|
||||
final args = call.arguments as Map;
|
||||
final time = args['time'] as Map;
|
||||
times.add(int.parse(time['numerator'].toString()));
|
||||
}
|
||||
throw PlatformException(code: 'no-preview');
|
||||
});
|
||||
addTearDown(
|
||||
() => tester.binding.defaultBinaryMessenger.setMockMethodCallHandler(
|
||||
channel,
|
||||
null,
|
||||
),
|
||||
);
|
||||
final container = await mount(tester);
|
||||
await (container.read(projectsProvider.notifier) as _Projects)
|
||||
.importExternalMedia('project', [
|
||||
const ExternalMediaFile(path: '/movie.mp4'),
|
||||
]);
|
||||
await tester.pumpAndSettle();
|
||||
await tester.tap(find.byTooltip('列表布局'));
|
||||
await tester.pumpAndSettle();
|
||||
final cover = tester.getRect(
|
||||
find.byKey(const ValueKey('desktop-media-cover-/movie.mp4')),
|
||||
);
|
||||
final name = tester.getRect(find.text('movie.mp4'));
|
||||
final duration = tester.getRect(find.text('04:50'));
|
||||
expect(cover.width, 56);
|
||||
expect(cover.height, closeTo(56 * 9 / 16, .01));
|
||||
expect(name.left, cover.right + 8);
|
||||
expect(duration.left, greaterThanOrEqualTo(name.left));
|
||||
expect(duration.center.dy, closeTo(cover.center.dy, .01));
|
||||
expect(times.every((time) => time == 0), isTrue);
|
||||
expect(tester.takeException(), isNull);
|
||||
await tester.binding.setSurfaceSize(const Size(180, 600));
|
||||
await tester.pumpWidget(
|
||||
UncontrolledProviderScope(
|
||||
container: container,
|
||||
child: MaterialApp(
|
||||
theme: EditorTheme.desktop(EditorTheme.penLight),
|
||||
locale: const Locale('zh'),
|
||||
localizationsDelegates: AppLocalizations.localizationsDelegates,
|
||||
supportedLocales: AppLocalizations.supportedLocales,
|
||||
home: const Scaffold(
|
||||
body: MediaQuery(
|
||||
data: MediaQueryData(textScaler: TextScaler.linear(1.5)),
|
||||
child: MediaPanel(projectId: 'project'),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.text('04:50'), findsOneWidget);
|
||||
expect(tester.takeException(), isNull);
|
||||
},
|
||||
);
|
||||
|
||||
testWidgets(
|
||||
'missing assets stay named and marked in both layouts without dragging',
|
||||
@@ -425,7 +530,133 @@ void main() {
|
||||
);
|
||||
|
||||
testWidgets(
|
||||
'category dropdown filters both layouts and restores all assets',
|
||||
'desktop media fits all six themes and keeps selection at narrow widths',
|
||||
(tester) async {
|
||||
final container = await mount(tester);
|
||||
final projects = container.read(projectsProvider.notifier) as _Projects;
|
||||
await projects.importExternalMedia('project', [
|
||||
const ExternalMediaFile(path: '/long-original-asset-name.txt'),
|
||||
const ExternalMediaFile(path: '/second.txt'),
|
||||
]);
|
||||
await tester.pumpAndSettle();
|
||||
final browser = container.read(mediaBrowserProvider('project'));
|
||||
browser.selectedAssetId = '/long-original-asset-name.txt';
|
||||
for (final palette in AppPalette.values) {
|
||||
for (final brightness in Brightness.values) {
|
||||
for (final width in [180.0, 240.0, 320.0, 560.0]) {
|
||||
for (final grid in [true, false]) {
|
||||
browser.grid = grid;
|
||||
await tester.pumpWidget(
|
||||
UncontrolledProviderScope(
|
||||
container: container,
|
||||
child: MaterialApp(
|
||||
theme: EditorTheme.desktop(
|
||||
EditorTheme.forPalette(palette, brightness),
|
||||
),
|
||||
localizationsDelegates:
|
||||
AppLocalizations.localizationsDelegates,
|
||||
supportedLocales: AppLocalizations.supportedLocales,
|
||||
locale: const Locale('en'),
|
||||
home: Scaffold(
|
||||
body: MediaQuery(
|
||||
data: const MediaQueryData(
|
||||
textScaler: TextScaler.linear(1.5),
|
||||
),
|
||||
child: Align(
|
||||
alignment: Alignment.topLeft,
|
||||
child: SizedBox(
|
||||
width: width,
|
||||
child: const MediaPanel(projectId: 'project'),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
expect(browser.selectedAssetId, '/long-original-asset-name.txt');
|
||||
final cover = tester.getRect(
|
||||
find.byKey(
|
||||
const ValueKey(
|
||||
'desktop-media-cover-/long-original-asset-name.txt',
|
||||
),
|
||||
),
|
||||
);
|
||||
expect(cover.width / cover.height, closeTo(16 / 9, .01));
|
||||
expect(
|
||||
tester.takeException(),
|
||||
isNull,
|
||||
reason: '$palette $brightness width=$width grid=$grid',
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
);
|
||||
|
||||
testWidgets(
|
||||
'Chinese media cards fit fractional text scaling without overflow',
|
||||
(tester) async {
|
||||
final container = await mount(tester);
|
||||
await (container.read(projectsProvider.notifier) as _Projects)
|
||||
.importExternalMedia('project', [
|
||||
const ExternalMediaFile(path: '/截屏2026-10-08 21.32.56.txt'),
|
||||
const ExternalMediaFile(path: '/gyp-ÁÉ-long-file-name.txt'),
|
||||
]);
|
||||
for (final width in [180.0, 241.0, 321.0]) {
|
||||
for (final scale in [1.0, 1.05, 1.1, 1.25, 1.5, 2.0]) {
|
||||
await tester.pumpWidget(
|
||||
UncontrolledProviderScope(
|
||||
container: container,
|
||||
child: MaterialApp(
|
||||
theme: EditorTheme.desktop(EditorTheme.penLight),
|
||||
locale: const Locale('zh'),
|
||||
localizationsDelegates: AppLocalizations.localizationsDelegates,
|
||||
supportedLocales: AppLocalizations.supportedLocales,
|
||||
home: Scaffold(
|
||||
body: Align(
|
||||
alignment: Alignment.topLeft,
|
||||
child: SizedBox(
|
||||
width: width,
|
||||
child: MediaQuery(
|
||||
data: MediaQueryData(
|
||||
textScaler: TextScaler.linear(scale),
|
||||
),
|
||||
child: const MediaPanel(projectId: 'project'),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
expect(
|
||||
tester.takeException(),
|
||||
isNull,
|
||||
reason: 'width=$width scale=$scale',
|
||||
);
|
||||
final tile = find.byKey(const ValueKey('/截屏2026-10-08 21.32.56.txt'));
|
||||
final metadata = find.descendant(of: tile, matching: find.text('素材'));
|
||||
expect(
|
||||
tester.getRect(tile).bottom - tester.getRect(metadata).bottom,
|
||||
greaterThanOrEqualTo(5),
|
||||
);
|
||||
final cover = tester.getRect(
|
||||
find.byKey(
|
||||
const ValueKey('desktop-media-cover-/截屏2026-10-08 21.32.56.txt'),
|
||||
),
|
||||
);
|
||||
expect(cover.width / cover.height, closeTo(16 / 9, .01));
|
||||
}
|
||||
}
|
||||
},
|
||||
);
|
||||
|
||||
testWidgets(
|
||||
'desktop categories filter both layouts and retain shared controls',
|
||||
(tester) async {
|
||||
final container = await mount(tester);
|
||||
final projects = container.read(projectsProvider.notifier) as _Projects;
|
||||
@@ -436,80 +667,42 @@ void main() {
|
||||
const ExternalMediaFile(path: '/notes.txt'),
|
||||
]);
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.byKey(const Key('media-import-button')), findsOneWidget);
|
||||
expect(
|
||||
tester.getSize(find.byKey(const Key('media-panel-header'))).height,
|
||||
AppControlSize.panelToolbar * 2,
|
||||
);
|
||||
expect(
|
||||
tester.getSize(find.byKey(const Key('media-import-button'))).height,
|
||||
AppControlSize.headerButton,
|
||||
);
|
||||
final header = tester.getRect(
|
||||
find.byKey(const Key('media-panel-header')),
|
||||
);
|
||||
expect(
|
||||
tester.getRect(find.byKey(const Key('media-panel-body'))).top,
|
||||
header.bottom,
|
||||
);
|
||||
final importButton = tester.getRect(
|
||||
find.byKey(const Key('media-import-button')),
|
||||
);
|
||||
final layoutButton = tester.getRect(
|
||||
find.byKey(const Key('media-layout-toggle')),
|
||||
);
|
||||
final filter = find.byWidgetPredicate(
|
||||
(widget) => widget is Semantics && widget.properties.label == '素材分类',
|
||||
final sortButton = tester.getRect(
|
||||
find.byKey(const Key('media-sort-button')),
|
||||
);
|
||||
final filterButton = tester.getRect(
|
||||
find.descendant(of: filter, matching: find.byType(TextButton)),
|
||||
);
|
||||
expect(header.right - importButton.right, AppSidebarMetrics.outerPadding);
|
||||
expect(importButton.top - header.top, AppSpacing.gap);
|
||||
expect(layoutButton.top - importButton.top, AppControlSize.panelToolbar);
|
||||
expect(header.height, 76);
|
||||
expect(importButton.height, 28);
|
||||
expect(importButton.top - header.top, 4);
|
||||
expect(header.right - importButton.right, 12);
|
||||
expect(header.right - layoutButton.right, 12);
|
||||
expect(sortButton.top, layoutButton.top);
|
||||
expect(layoutButton.left - sortButton.right, 36);
|
||||
expect(find.byKey(const Key('media-category-button')), findsOneWidget);
|
||||
expect(find.byKey(const ValueKey('media-filter-image')), findsNothing);
|
||||
expect(
|
||||
tester.getRect(find.byKey(const Key('media-project-button'))).top,
|
||||
importButton.top,
|
||||
tester.getRect(find.byKey(const Key('media-panel-body'))).top,
|
||||
header.bottom,
|
||||
);
|
||||
expect(header.right - layoutButton.right, AppSidebarMetrics.outerPadding);
|
||||
expect(
|
||||
layoutButton.left - filterButton.right,
|
||||
greaterThanOrEqualTo(AppSpacing.tiny),
|
||||
);
|
||||
expect(tester.getSize(filter).height, AppControlSize.headerButton);
|
||||
final importStyle = tester
|
||||
.widget<TextButton>(find.byKey(const Key('media-import-button')))
|
||||
.style!
|
||||
.textStyle!
|
||||
.resolve({})!;
|
||||
final filterStyle = tester
|
||||
.widget<TextButton>(find.byKey(const Key('media-category-button')))
|
||||
.style!
|
||||
.textStyle!
|
||||
.resolve({})!;
|
||||
expect(importStyle.fontSize, 13);
|
||||
expect(importStyle.height, 18 / 13);
|
||||
expect(filterStyle.fontSize, importStyle.fontSize);
|
||||
expect(filterStyle.height, importStyle.height);
|
||||
expect(find.text('4 个素材'), findsNothing);
|
||||
expect(find.text('4 个素材'), findsOneWidget);
|
||||
for (final entry in {
|
||||
'图片': 'photo.png',
|
||||
'视频': 'movie.mp4',
|
||||
'音频': 'song.wav',
|
||||
'image': 'photo.png',
|
||||
'video': 'movie.mp4',
|
||||
'audio': 'song.wav',
|
||||
}.entries) {
|
||||
await tester.tap(
|
||||
find.descendant(
|
||||
of: find.byWidgetPredicate(
|
||||
(widget) =>
|
||||
widget is Semantics && widget.properties.label == '素材分类',
|
||||
),
|
||||
matching: find.byType(TextButton),
|
||||
),
|
||||
);
|
||||
await tester.tap(find.byKey(const Key('media-category-button')));
|
||||
await tester.pumpAndSettle();
|
||||
await tester.tap(find.widgetWithText(MenuItemButton, entry.key));
|
||||
await tester.tap(find.byKey(ValueKey('media-filter-${entry.key}')));
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.text('1 个素材'), findsNothing);
|
||||
expect(find.text('1 个素材'), findsOneWidget);
|
||||
expect(find.text(entry.value), findsOneWidget);
|
||||
expect(find.text('notes.txt'), findsNothing);
|
||||
}
|
||||
@@ -517,24 +710,73 @@ void main() {
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.text('song.wav'), findsOneWidget);
|
||||
expect(find.text('movie.mp4'), findsNothing);
|
||||
await tester.tap(
|
||||
find.descendant(
|
||||
of: find.byWidgetPredicate(
|
||||
(widget) =>
|
||||
widget is Semantics && widget.properties.label == '素材分类',
|
||||
),
|
||||
matching: find.byType(TextButton),
|
||||
),
|
||||
);
|
||||
await tester.tap(find.byKey(const Key('media-category-button')));
|
||||
await tester.pumpAndSettle();
|
||||
await tester.tap(find.widgetWithText(MenuItemButton, '全部'));
|
||||
await tester.tap(find.byKey(const ValueKey('media-filter-all')));
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.text('4 个素材'), findsNothing);
|
||||
expect(find.text('4 个素材'), findsOneWidget);
|
||||
expect(find.text('notes.txt'), findsOneWidget);
|
||||
expect(tester.takeException(), isNull);
|
||||
},
|
||||
);
|
||||
|
||||
testWidgets(
|
||||
'search and sort share selection across layouts and preserve project choices',
|
||||
(tester) async {
|
||||
final container = await mount(tester);
|
||||
final projects = container.read(projectsProvider.notifier) as _Projects;
|
||||
await projects.importExternalMedia('project', [
|
||||
const ExternalMediaFile(path: '/Zebra.png'),
|
||||
const ExternalMediaFile(path: '/Alpha.png'),
|
||||
const ExternalMediaFile(path: '/song.wav'),
|
||||
]);
|
||||
await tester.pumpAndSettle();
|
||||
final browser = container.read(mediaBrowserProvider('project'));
|
||||
final search = find.byKey(const Key('media-search'));
|
||||
await tester.enterText(search, 'ALPHA');
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.text('Zebra.png'), findsNothing);
|
||||
expect(find.text('1 个素材'), findsOneWidget);
|
||||
await tester.tap(find.text('Alpha.png'));
|
||||
await tester.pumpAndSettle();
|
||||
final selected = browser.selectedAssetId!;
|
||||
final before = tester.getSize(find.byKey(ValueKey(selected)));
|
||||
await tester.tap(find.text('Alpha.png'));
|
||||
await tester.pump();
|
||||
expect(tester.getSize(find.byKey(ValueKey(selected))), before);
|
||||
await tester.tap(find.byTooltip('列表布局'));
|
||||
await tester.pumpAndSettle();
|
||||
expect(browser.selectedAssetId, selected);
|
||||
expect(tester.widget<TextField>(search).controller!.text, 'ALPHA');
|
||||
expect(find.text('已选 1 个'), findsOneWidget);
|
||||
expect(
|
||||
tester.getRect(find.byKey(const Key('media-browser-footer'))).right -
|
||||
tester.getRect(find.text('已选 1 个')).right,
|
||||
12,
|
||||
);
|
||||
await tester.enterText(search, 'not found');
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.text('没有匹配的素材'), findsOneWidget);
|
||||
expect(find.text('已选 1 个'), findsNothing);
|
||||
await tester.enterText(search, '');
|
||||
await tester.pumpAndSettle();
|
||||
await tester.tap(find.byKey(const Key('media-sort-button')));
|
||||
await tester.pumpAndSettle();
|
||||
await tester.tap(find.byKey(const ValueKey('media-sort-nameAscending')));
|
||||
await tester.pumpAndSettle();
|
||||
expect(
|
||||
tester.getTopLeft(find.text('Alpha.png')).dy,
|
||||
lessThan(tester.getTopLeft(find.text('Zebra.png')).dy),
|
||||
);
|
||||
expect(browser.sort, MediaSort.nameAscending);
|
||||
final other = container.read(mediaBrowserProvider('second'));
|
||||
expect(other.query, isEmpty);
|
||||
expect(other.sort, MediaSort.importOrder);
|
||||
expect(browser.selectedAssetId, selected);
|
||||
expect(tester.takeException(), isNull);
|
||||
},
|
||||
);
|
||||
|
||||
testWidgets(
|
||||
'media layouts resize columns and retain selection and dragging',
|
||||
(tester) async {
|
||||
@@ -551,7 +793,7 @@ void main() {
|
||||
(tester.widget<GridView>(find.byType(GridView)).gridDelegate
|
||||
as SliverGridDelegateWithFixedCrossAxisCount)
|
||||
.crossAxisCount;
|
||||
expect(columns(), 3);
|
||||
expect(columns(), 1);
|
||||
expect(
|
||||
find.ancestor(
|
||||
of: find.byType(GridView),
|
||||
@@ -598,13 +840,15 @@ void main() {
|
||||
await tester.tap(find.byTooltip('宫格布局'));
|
||||
await tester.pumpAndSettle();
|
||||
for (final (width, count) in [
|
||||
(180.0, 2),
|
||||
(280.0, 3),
|
||||
(240.0, 2),
|
||||
(360.0, 3),
|
||||
(520.0, 5),
|
||||
(560.0, 5),
|
||||
(900.0, 8),
|
||||
(120.0, 1),
|
||||
(180.0, 1),
|
||||
(220.0, 1),
|
||||
(280.0, 1),
|
||||
(240.0, 1),
|
||||
(360.0, 2),
|
||||
(520.0, 3),
|
||||
(560.0, 3),
|
||||
(900.0, 5),
|
||||
]) {
|
||||
await tester.binding.setSurfaceSize(Size(width, 600));
|
||||
await tester.pumpAndSettle();
|
||||
@@ -618,7 +862,7 @@ void main() {
|
||||
padding.horizontal -
|
||||
delegate.crossAxisSpacing * (count - 1)) /
|
||||
count;
|
||||
expect(tileWidth, lessThanOrEqualTo(120));
|
||||
expect(tileWidth, greaterThanOrEqualTo(width < 184 ? width - 24 : 160));
|
||||
expect(tester.takeException(), isNull);
|
||||
}
|
||||
expect(
|
||||
@@ -633,10 +877,223 @@ void main() {
|
||||
},
|
||||
);
|
||||
|
||||
testWidgets('thumbnail size is project-specific and retains selection', (
|
||||
tester,
|
||||
) async {
|
||||
await tester.binding.setSurfaceSize(const Size(720, 500));
|
||||
addTearDown(() => tester.binding.setSurfaceSize(null));
|
||||
final container = await mount(tester);
|
||||
await (container.read(projectsProvider.notifier) as _Projects)
|
||||
.importExternalMedia('project', [
|
||||
for (var i = 0; i < 20; i++) ExternalMediaFile(path: '/asset-$i.txt'),
|
||||
]);
|
||||
await tester.pumpAndSettle();
|
||||
final browser = container.read(mediaBrowserProvider('project'));
|
||||
browser.selectedAssetId = '/asset-0.txt';
|
||||
int columns() =>
|
||||
(tester.widget<GridView>(find.byType(GridView)).gridDelegate
|
||||
as SliverGridDelegateWithFixedCrossAxisCount)
|
||||
.crossAxisCount;
|
||||
expect(columns(), 4);
|
||||
for (final (size, count) in [
|
||||
(MediaGridSize.small, 5),
|
||||
(MediaGridSize.large, 3),
|
||||
(MediaGridSize.medium, 4),
|
||||
]) {
|
||||
await tester.tap(find.byKey(const Key('media-size-button')));
|
||||
await tester.pumpAndSettle();
|
||||
await tester.tap(find.byKey(ValueKey('media-size-${size.name}')));
|
||||
await tester.pumpAndSettle();
|
||||
expect(browser.gridSize, size);
|
||||
expect(columns(), count);
|
||||
expect(browser.selectedAssetId, '/asset-0.txt');
|
||||
}
|
||||
expect(
|
||||
container.read(mediaBrowserProvider('second')).gridSize,
|
||||
MediaGridSize.medium,
|
||||
);
|
||||
expect(tester.takeException(), isNull);
|
||||
});
|
||||
|
||||
testWidgets(
|
||||
'narrow toolbar preserves search space and exposes density in its menu',
|
||||
(tester) async {
|
||||
await tester.binding.setSurfaceSize(const Size(280, 600));
|
||||
addTearDown(() => tester.binding.setSurfaceSize(null));
|
||||
final container = await mount(tester);
|
||||
expect(
|
||||
tester.getSize(find.byKey(const Key('media-panel-header'))).height,
|
||||
76,
|
||||
);
|
||||
expect(
|
||||
tester.getSize(find.byKey(const Key('media-search'))).width,
|
||||
greaterThan(160),
|
||||
);
|
||||
expect(find.byKey(const Key('media-sort-button')), findsNothing);
|
||||
expect(find.byKey(const Key('media-size-button')), findsNothing);
|
||||
await tester.tap(find.byKey(const Key('media-category-button')));
|
||||
await tester.pumpAndSettle();
|
||||
final size = find.byKey(const ValueKey('media-size-small'));
|
||||
await tester.ensureVisible(size);
|
||||
await tester.tap(size);
|
||||
await tester.pumpAndSettle();
|
||||
expect(
|
||||
container.read(mediaBrowserProvider('project')).gridSize,
|
||||
MediaGridSize.small,
|
||||
);
|
||||
expect(tester.takeException(), isNull);
|
||||
},
|
||||
);
|
||||
|
||||
testWidgets(
|
||||
'view and density changes preserve the first visible asset before settling',
|
||||
(tester) async {
|
||||
await tester.binding.setSurfaceSize(const Size(720, 500));
|
||||
addTearDown(() => tester.binding.setSurfaceSize(null));
|
||||
final container = await mount(tester);
|
||||
await (container.read(
|
||||
projectsProvider.notifier,
|
||||
) as _Projects).importExternalMedia('project', [
|
||||
for (var i = 0; i < 120; i++) ExternalMediaFile(path: '/asset-$i.txt'),
|
||||
]);
|
||||
await tester.pumpAndSettle();
|
||||
await tester.drag(find.byType(GridView), const Offset(0, -650));
|
||||
await tester.pumpAndSettle();
|
||||
final browser = container.read(mediaBrowserProvider('project'));
|
||||
final anchor = browser.viewportAnchor!;
|
||||
expect(anchor.assetId, isNot('/asset-0.txt'));
|
||||
browser.selectedAssetId = anchor.assetId;
|
||||
browser.grid = false;
|
||||
await tester.pump();
|
||||
final selected = find.byKey(ValueKey(anchor.assetId));
|
||||
final firstRect = tester.getRect(selected);
|
||||
expect(firstRect.overlaps(tester.getRect(find.byType(ListView))), isTrue);
|
||||
await tester.pumpAndSettle();
|
||||
expect(tester.getRect(selected), firstRect);
|
||||
browser.grid = true;
|
||||
browser.gridSize = MediaGridSize.large;
|
||||
await tester.pump();
|
||||
final gridRect = tester.getRect(selected);
|
||||
expect(gridRect.overlaps(tester.getRect(find.byType(GridView))), isTrue);
|
||||
await tester.pumpAndSettle();
|
||||
expect(tester.getRect(selected), gridRect);
|
||||
expect(browser.selectedAssetId, anchor.assetId);
|
||||
await tester.binding.setSurfaceSize(const Size(560, 500));
|
||||
await tester.pump();
|
||||
final resized = tester.getRect(selected);
|
||||
expect(resized.overlaps(tester.getRect(find.byType(GridView))), isTrue);
|
||||
await tester.pumpAndSettle();
|
||||
expect(tester.getRect(selected), resized);
|
||||
expect(tester.takeException(), isNull);
|
||||
},
|
||||
);
|
||||
|
||||
testWidgets('empty search and panel remount retain the browse anchor', (
|
||||
tester,
|
||||
) async {
|
||||
await tester.binding.setSurfaceSize(const Size(720, 500));
|
||||
addTearDown(() => tester.binding.setSurfaceSize(null));
|
||||
final container = await mount(tester);
|
||||
await (container.read(
|
||||
projectsProvider.notifier,
|
||||
) as _Projects).importExternalMedia('project', [
|
||||
for (var i = 0; i < 120; i++) ExternalMediaFile(path: '/asset-$i.txt'),
|
||||
]);
|
||||
await tester.pumpAndSettle();
|
||||
await tester.drag(find.byType(GridView), const Offset(0, -650));
|
||||
await tester.pumpAndSettle();
|
||||
final browser = container.read(mediaBrowserProvider('project'));
|
||||
final anchor = browser.viewportAnchor!;
|
||||
final tile = find.byKey(ValueKey(anchor.assetId));
|
||||
final original = tester.getRect(tile);
|
||||
browser.query = 'no matching assets';
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.byType(GridView), findsNothing);
|
||||
browser.query = '';
|
||||
await tester.pump();
|
||||
expect(tester.getRect(tile), original);
|
||||
await tester.pumpAndSettle();
|
||||
final root = tester.widget(find.byType(UncontrolledProviderScope));
|
||||
await tester.pumpWidget(const SizedBox());
|
||||
await tester.pumpWidget(root);
|
||||
await tester.pump();
|
||||
expect(tester.getRect(tile), original);
|
||||
expect(browser.viewportAnchor, anchor);
|
||||
expect(tester.takeException(), isNull);
|
||||
});
|
||||
|
||||
testWidgets('bottom browse position is clamped before the first frame', (
|
||||
tester,
|
||||
) async {
|
||||
await tester.binding.setSurfaceSize(const Size(720, 500));
|
||||
addTearDown(() => tester.binding.setSurfaceSize(null));
|
||||
final container = await mount(tester);
|
||||
await (container.read(
|
||||
projectsProvider.notifier,
|
||||
) as _Projects).importExternalMedia('project', [
|
||||
for (var i = 0; i < 121; i++) ExternalMediaFile(path: '/asset-$i.txt'),
|
||||
]);
|
||||
await tester.pumpAndSettle();
|
||||
ScrollPosition position() =>
|
||||
tester.state<ScrollableState>(find.byType(Scrollable).last).position;
|
||||
position().jumpTo(position().maxScrollExtent);
|
||||
await tester.pump();
|
||||
final browser = container.read(mediaBrowserProvider('project'));
|
||||
for (final size in [MediaGridSize.small, MediaGridSize.large]) {
|
||||
final anchor = browser.viewportAnchor!;
|
||||
browser.gridSize = size;
|
||||
await tester.pump();
|
||||
final firstOffset = position().pixels;
|
||||
expect(firstOffset, lessThanOrEqualTo(position().maxScrollExtent));
|
||||
await tester.pumpAndSettle();
|
||||
expect(position().pixels, firstOffset);
|
||||
expect(
|
||||
tester
|
||||
.getRect(find.byKey(ValueKey(anchor.assetId)))
|
||||
.overlaps(tester.getRect(find.byType(GridView))),
|
||||
isTrue,
|
||||
);
|
||||
position().jumpTo(position().maxScrollExtent);
|
||||
await tester.pump();
|
||||
}
|
||||
expect(tester.takeException(), isNull);
|
||||
});
|
||||
|
||||
testWidgets('desktop density does not change touch-page geometry', (
|
||||
tester,
|
||||
) async {
|
||||
final container = await mount(tester, touch: true);
|
||||
await (container.read(projectsProvider.notifier) as _Projects)
|
||||
.importExternalMedia('project', [
|
||||
const ExternalMediaFile(path: '/asset.txt'),
|
||||
]);
|
||||
await tester.pumpAndSettle();
|
||||
final grid = tester.widget<GridView>(find.byType(GridView));
|
||||
final delegate =
|
||||
grid.gridDelegate as SliverGridDelegateWithFixedCrossAxisCount;
|
||||
final element = tester.element(find.byType(GridView));
|
||||
final tileRect = tester.getRect(find.byKey(const ValueKey('/asset.txt')));
|
||||
container.read(mediaBrowserProvider('project')).gridSize =
|
||||
MediaGridSize.large;
|
||||
await tester.pump();
|
||||
final updated = tester.widget<GridView>(find.byType(GridView));
|
||||
final updatedDelegate =
|
||||
updated.gridDelegate as SliverGridDelegateWithFixedCrossAxisCount;
|
||||
expect(tester.element(find.byType(GridView)), same(element));
|
||||
expect(updated.controller, same(grid.controller));
|
||||
expect(updatedDelegate.crossAxisCount, delegate.crossAxisCount);
|
||||
expect(updatedDelegate.mainAxisExtent, delegate.mainAxisExtent);
|
||||
expect(updatedDelegate.childAspectRatio, delegate.childAspectRatio);
|
||||
expect(tester.getRect(find.byKey(const ValueKey('/asset.txt'))), tileRect);
|
||||
expect(tester.takeException(), isNull);
|
||||
}, variant: TargetPlatformVariant.only(TargetPlatform.android));
|
||||
|
||||
testWidgets('native file event imports real paths without a success prompt', (
|
||||
tester,
|
||||
) async {
|
||||
final container = await mount(tester);
|
||||
container.read(mediaBrowserProvider('project')).query = 'no match';
|
||||
await tester.pumpAndSettle();
|
||||
final target = tester.getCenter(find.byType(NativeProjectDropRegion));
|
||||
await platformEvent(tester, 'enter', [target.dx, target.dy]);
|
||||
expect(find.byKey(const Key('media-drop-highlight')), findsOneWidget);
|
||||
@@ -662,6 +1119,7 @@ void main() {
|
||||
'/originals/中文 视频.flv',
|
||||
]);
|
||||
expect(find.text('video.mp4'), findsOneWidget);
|
||||
expect(container.read(mediaBrowserProvider('project')).query, isEmpty);
|
||||
expect(find.text('中文 视频.RMVB'), findsOneWidget);
|
||||
expect(find.text('中文 视频.flv'), findsOneWidget);
|
||||
expect(find.byType(SnackBar), findsNothing);
|
||||
@@ -680,6 +1138,9 @@ void main() {
|
||||
]);
|
||||
await tester.pumpAndSettle();
|
||||
await tester.tap(find.text('second.wav'));
|
||||
final browser = container.read(mediaBrowserProvider('project'));
|
||||
browser.query = ' FIRST ';
|
||||
await tester.pumpAndSettle();
|
||||
await platformEvent(tester, 'enter', [0.0, 0.0]);
|
||||
await platformEvent(tester, 'drop', ['/originals/first.mp4']);
|
||||
await tester.pumpAndSettle();
|
||||
@@ -691,6 +1152,7 @@ void main() {
|
||||
container.read(projectsProvider).requireValue.assets,
|
||||
hasLength(2),
|
||||
);
|
||||
expect(browser.query, ' FIRST ');
|
||||
expect(
|
||||
find.ancestor(
|
||||
of: find.text('first.mp4'),
|
||||
@@ -831,7 +1293,7 @@ void main() {
|
||||
const ExternalMediaFile(path: '/originals/bad.wav'),
|
||||
]);
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.byIcon(Icons.audio_file_outlined), findsOneWidget);
|
||||
expect(find.byIcon(AppIcons.audioFile), findsOneWidget);
|
||||
final before = tester.getSize(
|
||||
find.byKey(const ValueKey('audio-cover-/originals/bad.wav')),
|
||||
);
|
||||
@@ -966,6 +1428,8 @@ class _Projects extends Projects {
|
||||
);
|
||||
@visibleForTesting
|
||||
List<ExternalMediaFile> received = [];
|
||||
@visibleForTesting
|
||||
Future<void>? importGate;
|
||||
@override
|
||||
Future<ProjectState> build() async => const ProjectState(
|
||||
activeProject: RecentProject(
|
||||
@@ -994,6 +1458,7 @@ class _Projects extends Projects {
|
||||
List<ExternalMediaFile> files, {
|
||||
bool Function()? isCancelled,
|
||||
}) async {
|
||||
await importGate;
|
||||
received = files;
|
||||
final previous = state.requireValue.assets;
|
||||
final previousIds = {for (final asset in previous) asset.id};
|
||||
|
||||
@@ -1,11 +1,199 @@
|
||||
import 'dart:async';
|
||||
|
||||
import 'package:cutdex/app/editor_theme.dart';
|
||||
import 'package:cutdex/l10n/app_localizations.dart';
|
||||
import 'package:cutdex_ui/theme.dart';
|
||||
import 'package:cutdex/features/projects/widgets/name_dialog.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:flutter/rendering.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
|
||||
void main() {
|
||||
testWidgets('name collision keeps the dialog open and allows correction', (
|
||||
tester,
|
||||
) async {
|
||||
final validation = Completer<String?>();
|
||||
final submitted = <String>[];
|
||||
String? result;
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(
|
||||
theme: EditorTheme.penDark,
|
||||
localizationsDelegates: AppLocalizations.localizationsDelegates,
|
||||
supportedLocales: AppLocalizations.supportedLocales,
|
||||
locale: const Locale('zh'),
|
||||
home: Scaffold(
|
||||
body: Builder(
|
||||
builder: (context) => TextButton(
|
||||
onPressed: () async {
|
||||
result = await askName(
|
||||
context,
|
||||
title: '新建项目',
|
||||
label: '项目名称',
|
||||
validateName: (name) async {
|
||||
submitted.add(name);
|
||||
return name == 'Existing' ? validation.future : null;
|
||||
},
|
||||
);
|
||||
},
|
||||
child: const Text('Open'),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
await tester.tap(find.text('Open'));
|
||||
await tester.pumpAndSettle();
|
||||
await tester.enterText(find.byType(TextFormField), 'Existing');
|
||||
await tester.tap(find.byType(FilledButton));
|
||||
await tester.pump();
|
||||
expect(
|
||||
tester.widget<FilledButton>(find.byType(FilledButton)).onPressed,
|
||||
isNull,
|
||||
);
|
||||
await tester.testTextInput.receiveAction(TextInputAction.done);
|
||||
expect(submitted, ['Existing']);
|
||||
|
||||
final error = lookupAppLocalizations(const Locale('zh'))
|
||||
.projectAlreadyExists;
|
||||
validation.complete(error);
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.text(error), findsOneWidget);
|
||||
expect(find.byType(TextFormField), findsOneWidget);
|
||||
expect(
|
||||
tester.widget<EditableText>(find.byType(EditableText)).controller.text,
|
||||
'Existing',
|
||||
);
|
||||
expect(result, isNull);
|
||||
expect(tester.takeException(), isNull);
|
||||
|
||||
await tester.enterText(find.byType(TextFormField), 'Another');
|
||||
await tester.pump();
|
||||
expect(find.text(error), findsNothing);
|
||||
await tester.tap(find.byType(FilledButton));
|
||||
await tester.pumpAndSettle();
|
||||
expect(result, 'Another');
|
||||
expect(submitted, ['Existing', 'Another']);
|
||||
expect(find.byType(TextFormField), findsNothing);
|
||||
});
|
||||
|
||||
testWidgets('cancel during validation does not pop the underlying page', (
|
||||
tester,
|
||||
) async {
|
||||
final validation = Completer<String?>();
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(
|
||||
theme: EditorTheme.penDark,
|
||||
localizationsDelegates: AppLocalizations.localizationsDelegates,
|
||||
supportedLocales: AppLocalizations.supportedLocales,
|
||||
home: Builder(
|
||||
builder: (context) => TextButton(
|
||||
onPressed: () => askName(
|
||||
context,
|
||||
title: 'New project',
|
||||
label: 'Name',
|
||||
validateName: (_) => validation.future,
|
||||
),
|
||||
child: const Text('Open'),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
await tester.tap(find.text('Open'));
|
||||
await tester.pumpAndSettle();
|
||||
await tester.enterText(find.byType(TextFormField), 'Name');
|
||||
await tester.tap(find.byType(FilledButton));
|
||||
await tester.pump();
|
||||
await tester.tap(find.text('Cancel'));
|
||||
validation.complete(null);
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.text('Open'), findsOneWidget);
|
||||
expect(find.byType(TextFormField), findsNothing);
|
||||
expect(tester.takeException(), isNull);
|
||||
});
|
||||
|
||||
testWidgets('rename hint, text line and caret share the vertical center', (
|
||||
tester,
|
||||
) async {
|
||||
addTearDown(() => debugDefaultTargetPlatformOverride = null);
|
||||
for (final platform in [TargetPlatform.macOS, TargetPlatform.windows]) {
|
||||
debugDefaultTargetPlatformOverride = platform;
|
||||
for (final brightness in Brightness.values) {
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(
|
||||
theme: EditorTheme.desktop(
|
||||
EditorTheme.forPalette(AppPalette.graphite, brightness),
|
||||
),
|
||||
localizationsDelegates: AppLocalizations.localizationsDelegates,
|
||||
supportedLocales: AppLocalizations.supportedLocales,
|
||||
locale: const Locale('zh'),
|
||||
home: Scaffold(
|
||||
body: Builder(
|
||||
builder: (context) => TextButton(
|
||||
onPressed: () => askName(
|
||||
context,
|
||||
title: '重命名',
|
||||
label: '项目名称',
|
||||
submitLabel: '重命名',
|
||||
),
|
||||
child: const Text('Open'),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
await tester.tap(find.text('Open'));
|
||||
await tester.pumpAndSettle();
|
||||
final field = find.byType(TextFormField);
|
||||
final editable = find.byType(EditableText);
|
||||
final input = tester.widget<EditableText>(editable);
|
||||
final decoration = tester
|
||||
.widget<TextField>(find.byType(TextField))
|
||||
.decoration!
|
||||
.applyDefaults(
|
||||
Theme.of(tester.element(field)).inputDecorationTheme,
|
||||
);
|
||||
expect(decoration.hintStyle!.fontSize, input.style.fontSize);
|
||||
expect(decoration.hintStyle!.height, input.style.height);
|
||||
final hint = tester.renderObject<RenderParagraph>(find.text('项目名称'));
|
||||
final hintBox = hint
|
||||
.getBoxesForSelection(
|
||||
const TextSelection(baseOffset: 0, extentOffset: 4),
|
||||
)
|
||||
.first
|
||||
.toRect();
|
||||
expect(
|
||||
hint.localToGlobal(hintBox.center).dy,
|
||||
closeTo(tester.getCenter(field).dy, 1),
|
||||
);
|
||||
for (final text in ['', '剪辑项目', 'Cutdex project']) {
|
||||
await tester.enterText(field, text);
|
||||
await tester.pump();
|
||||
final render = tester
|
||||
.state<EditableTextState>(editable)
|
||||
.renderEditable;
|
||||
final caret = render.getLocalRectForCaret(
|
||||
TextPosition(offset: text.length),
|
||||
);
|
||||
expect(
|
||||
render.localToGlobal(caret.center).dy,
|
||||
closeTo(tester.getCenter(field).dy, 1),
|
||||
reason: '$platform / $brightness / "$text"',
|
||||
);
|
||||
expect(
|
||||
render.localToGlobal(render.size.center(Offset.zero)).dy,
|
||||
closeTo(tester.getCenter(field).dy, 1),
|
||||
);
|
||||
expect(tester.getSize(field).height, 36);
|
||||
}
|
||||
await tester.tap(find.text('取消'));
|
||||
await tester.pumpAndSettle();
|
||||
await tester.pumpWidget(const SizedBox());
|
||||
}
|
||||
}
|
||||
debugDefaultTargetPlatformOverride = null;
|
||||
});
|
||||
|
||||
testWidgets('rename chat uses the same dialog and compact input', (
|
||||
tester,
|
||||
) async {
|
||||
|
||||
@@ -0,0 +1,113 @@
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:cutdex/features/settings/appearance_settings.dart';
|
||||
import 'package:cutdex/persistence/app_database.dart';
|
||||
import 'package:cutdex/persistence/app_settings_repositories.dart';
|
||||
import 'package:drift/native.dart';
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:sqlite3/sqlite3.dart';
|
||||
|
||||
import 'support/memory_app_settings.dart';
|
||||
|
||||
void main() {
|
||||
test('palette survives provider recreation and failed saves', () async {
|
||||
final repository = MemoryPaletteSettingsRepository();
|
||||
ProviderContainer container() => ProviderContainer(
|
||||
overrides: [
|
||||
paletteSettingsRepositoryProvider.overrideWithValue(repository),
|
||||
],
|
||||
);
|
||||
final first = container();
|
||||
addTearDown(first.dispose);
|
||||
expect(
|
||||
await first.read(paletteSettingsProvider.future),
|
||||
AppPalette.graphite,
|
||||
);
|
||||
await first
|
||||
.read(paletteSettingsProvider.notifier)
|
||||
.setPalette(AppPalette.teal);
|
||||
final restored = container();
|
||||
addTearDown(restored.dispose);
|
||||
expect(
|
||||
await restored.read(paletteSettingsProvider.future),
|
||||
AppPalette.teal,
|
||||
);
|
||||
repository.failWrites = true;
|
||||
await expectLater(
|
||||
restored
|
||||
.read(paletteSettingsProvider.notifier)
|
||||
.setPalette(AppPalette.violet),
|
||||
throwsStateError,
|
||||
);
|
||||
expect(
|
||||
restored.read(paletteSettingsProvider).requireValue,
|
||||
AppPalette.teal,
|
||||
);
|
||||
});
|
||||
|
||||
test('appearance and palette writes preserve each other', () async {
|
||||
final database = AppDatabase(NativeDatabase.memory());
|
||||
addTearDown(database.close);
|
||||
final appearance = DriftAppearanceSettingsRepository(database);
|
||||
final palette = DriftPaletteSettingsRepository(database);
|
||||
expect(await palette.load(), AppPalette.graphite);
|
||||
await palette.save(AppPalette.teal);
|
||||
expect(await appearance.load(), AppAppearance.system);
|
||||
await appearance.save(AppAppearance.penDark);
|
||||
expect(await palette.load(), AppPalette.teal);
|
||||
await palette.save(AppPalette.violet);
|
||||
expect(await appearance.load(), AppAppearance.penDark);
|
||||
await Future.wait([
|
||||
appearance.save(AppAppearance.penLight),
|
||||
palette.save(AppPalette.graphite),
|
||||
]);
|
||||
expect(await appearance.load(), AppAppearance.penLight);
|
||||
expect(await palette.load(), AppPalette.graphite);
|
||||
await database.customStatement(
|
||||
"UPDATE appearance_configurations SET palette = 'unknown'",
|
||||
);
|
||||
expect(await palette.load(), AppPalette.graphite);
|
||||
});
|
||||
|
||||
test('schema 2 upgrades without losing saved appearance', () async {
|
||||
final directory = await Directory.systemTemp.createTemp('cutdex-palette-');
|
||||
addTearDown(() => directory.delete(recursive: true));
|
||||
final file = File('${directory.path}/app.sqlite');
|
||||
final initial = AppDatabase(NativeDatabase(file));
|
||||
await DriftAppearanceSettingsRepository(initial)
|
||||
.save(AppAppearance.penDark);
|
||||
await initial.close();
|
||||
final old = sqlite3.open(file.path);
|
||||
try {
|
||||
old.execute(
|
||||
'ALTER TABLE appearance_configurations DROP COLUMN timeline_ruler_layout',
|
||||
);
|
||||
old.execute('ALTER TABLE appearance_configurations DROP COLUMN palette');
|
||||
old.userVersion = 2;
|
||||
} finally {
|
||||
old.close();
|
||||
}
|
||||
final upgraded = AppDatabase(NativeDatabase(file));
|
||||
expect(
|
||||
await DriftAppearanceSettingsRepository(upgraded).load(),
|
||||
AppAppearance.penDark,
|
||||
);
|
||||
expect(
|
||||
await DriftPaletteSettingsRepository(upgraded).load(),
|
||||
AppPalette.graphite,
|
||||
);
|
||||
await DriftPaletteSettingsRepository(upgraded).save(AppPalette.violet);
|
||||
await upgraded.close();
|
||||
final reopened = AppDatabase(NativeDatabase(file));
|
||||
addTearDown(reopened.close);
|
||||
expect(
|
||||
await DriftPaletteSettingsRepository(reopened).load(),
|
||||
AppPalette.violet,
|
||||
);
|
||||
expect(
|
||||
await DriftAppearanceSettingsRepository(reopened).load(),
|
||||
AppAppearance.penDark,
|
||||
);
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,104 @@
|
||||
import 'package:cutdex/app/app.dart';
|
||||
import 'package:cutdex/app/router/app_router.dart';
|
||||
import 'package:cutdex/features/settings/appearance_settings.dart';
|
||||
import 'package:cutdex/features/settings/settings_content.dart';
|
||||
import 'package:cutdex/integrations/agent/conversation_repository.dart';
|
||||
import 'package:cutdex/persistence/app_settings_repositories.dart';
|
||||
import 'package:cutdex_ui/theme.dart';
|
||||
import 'package:cutdex_ui/widgets.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:go_router/go_router.dart';
|
||||
|
||||
import 'support/empty_conversation_repository.dart';
|
||||
import 'support/memory_app_settings.dart';
|
||||
|
||||
void main() {
|
||||
testWidgets('settings switch all six themes and follow system appearance', (
|
||||
tester,
|
||||
) async {
|
||||
tester.view.physicalSize = const Size(1200, 900);
|
||||
tester.view.devicePixelRatio = 1;
|
||||
addTearDown(tester.view.resetPhysicalSize);
|
||||
addTearDown(tester.view.resetDevicePixelRatio);
|
||||
addTearDown(tester.platformDispatcher.clearPlatformBrightnessTestValue);
|
||||
final appearance = MemoryAppearanceSettingsRepository();
|
||||
final palette = MemoryPaletteSettingsRepository();
|
||||
final router = GoRouter(
|
||||
routes: [
|
||||
GoRoute(
|
||||
path: '/',
|
||||
builder: (_, _) => const Scaffold(body: SettingsContent()),
|
||||
),
|
||||
],
|
||||
);
|
||||
addTearDown(router.dispose);
|
||||
final scope = ProviderContainer(
|
||||
overrides: [
|
||||
appRouterProvider.overrideWithValue(router),
|
||||
appearanceSettingsRepositoryProvider.overrideWithValue(appearance),
|
||||
paletteSettingsRepositoryProvider.overrideWithValue(palette),
|
||||
conversationRepositoryProvider.overrideWith(
|
||||
(ref) async => EmptyConversationRepository(),
|
||||
),
|
||||
],
|
||||
);
|
||||
addTearDown(scope.dispose);
|
||||
await tester.pumpWidget(
|
||||
UncontrolledProviderScope(container: scope, child: const CutdexApp()),
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
await tester.tap(find.byKey(const ValueKey('settings-navigation-3')));
|
||||
await tester.pumpAndSettle();
|
||||
final settings = tester.element(find.byType(SettingsContent));
|
||||
final select = find.byKey(const Key('settings-color-palette'));
|
||||
expect(select, findsOneWidget);
|
||||
for (final option in AppPalette.values) {
|
||||
for (final mode in [AppAppearance.penLight, AppAppearance.penDark]) {
|
||||
await scope.read(appearanceSettingsProvider.notifier).setMode(mode);
|
||||
await tester.pumpAndSettle();
|
||||
await tester.tap(select);
|
||||
await tester.pumpAndSettle();
|
||||
final field = tester.widget<AppSelect<AppPalette>>(select);
|
||||
final label = field.options
|
||||
.singleWhere((item) => item.value == option)
|
||||
.label;
|
||||
final menuItem = find.widgetWithText(MenuItemButton, label);
|
||||
await tester.tap(menuItem);
|
||||
await tester.pumpAndSettle();
|
||||
expect(palette.value, option);
|
||||
expect(appearance.value, mode);
|
||||
expect(tester.element(find.byType(SettingsContent)), same(settings));
|
||||
final theme = Theme.of(settings);
|
||||
expect(AppColors.of(theme).family, option);
|
||||
expect(
|
||||
theme.brightness,
|
||||
mode == AppAppearance.penLight ? Brightness.light : Brightness.dark,
|
||||
);
|
||||
expect(
|
||||
theme.colorScheme.primary,
|
||||
AppColors.forPalette(option, theme.brightness).primary,
|
||||
);
|
||||
expect(tester.takeException(), isNull);
|
||||
}
|
||||
}
|
||||
await scope
|
||||
.read(appearanceSettingsProvider.notifier)
|
||||
.setMode(AppAppearance.system);
|
||||
for (final brightness in Brightness.values) {
|
||||
tester.platformDispatcher.platformBrightnessTestValue = brightness;
|
||||
await tester.pumpAndSettle();
|
||||
expect(Theme.of(settings).brightness, brightness);
|
||||
expect(AppColors.of(Theme.of(settings)).family, AppPalette.teal);
|
||||
expect(palette.value, AppPalette.teal);
|
||||
}
|
||||
for (final width in [800.0, 360.0]) {
|
||||
tester.view.physicalSize = Size(width, 900);
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.byKey(const Key('settings-color-palette')), findsOneWidget);
|
||||
expect(tester.takeException(), isNull);
|
||||
}
|
||||
await tester.pumpWidget(const SizedBox());
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,112 @@
|
||||
import 'dart:math' as math;
|
||||
|
||||
import 'package:cutdex/app/editor_theme.dart';
|
||||
import 'package:cutdex_ui/theme.dart';
|
||||
import 'package:cutdex_sdk/timeline_ui.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
|
||||
void main() {
|
||||
for (final palette in AppPalette.values) {
|
||||
for (final brightness in Brightness.values) {
|
||||
test(
|
||||
'${palette.name} ${brightness.name} shares semantic colors and readable text',
|
||||
() {
|
||||
final theme = EditorTheme.forPalette(palette, brightness);
|
||||
final colors = theme.colorScheme;
|
||||
final tokens = AppColors.of(theme);
|
||||
expect(theme.brightness, brightness);
|
||||
expect(tokens.family, palette);
|
||||
final settings = AppTheme.settingsContentTheme(theme);
|
||||
final dialog = AppTheme.dialogContentTheme(theme);
|
||||
final inspector = AppTheme.propertiesPanelTheme(theme);
|
||||
final actions = AppTheme.dialogActionTheme(theme);
|
||||
final timeline = theme.extension<TimelineThemeData>()!;
|
||||
expect(
|
||||
settings.switchTheme.trackColor!.resolve({WidgetState.selected}),
|
||||
colors.primary,
|
||||
);
|
||||
expect(
|
||||
(dialog.inputDecorationTheme.focusedBorder as OutlineInputBorder)
|
||||
.borderSide
|
||||
.color,
|
||||
colors.primary,
|
||||
);
|
||||
expect(timeline.selectionOutlineColor, colors.primary);
|
||||
expect(
|
||||
(inspector.inputDecorationTheme.focusedBorder as OutlineInputBorder)
|
||||
.borderSide
|
||||
.color,
|
||||
colors.primary,
|
||||
);
|
||||
for (final style in [
|
||||
theme.filledButtonTheme.style!,
|
||||
settings.filledButtonTheme.style!,
|
||||
actions.filledButtonTheme.style!,
|
||||
]) {
|
||||
final background = style.backgroundColor!.resolve({})!;
|
||||
final foreground = style.foregroundColor!.resolve({})!;
|
||||
expect(background, colors.primary);
|
||||
expect(
|
||||
_contrast(foreground, background),
|
||||
greaterThanOrEqualTo(4.5),
|
||||
);
|
||||
}
|
||||
expect(timeline.backgroundColor, colors.surface);
|
||||
expect(settings.colorScheme.surfaceContainer, tokens.card);
|
||||
expect(settings.inputDecorationTheme.fillColor, tokens.card);
|
||||
expect(inspector.inputDecorationTheme.fillColor, tokens.card);
|
||||
expect(AppColors.of(settings), tokens);
|
||||
expect(
|
||||
theme.extension<AppSurfaces>()!.previewBackground,
|
||||
Colors.black,
|
||||
);
|
||||
for (final surface in [
|
||||
colors.surface,
|
||||
colors.surfaceContainerLow,
|
||||
colors.surfaceContainer,
|
||||
timeline.visualClipColor,
|
||||
timeline.audioClipColor,
|
||||
]) {
|
||||
expect(
|
||||
_contrast(colors.onSurface, surface),
|
||||
greaterThanOrEqualTo(4.5),
|
||||
);
|
||||
}
|
||||
for (final surface in [
|
||||
colors.surface,
|
||||
colors.surfaceContainerLow,
|
||||
colors.surfaceContainer,
|
||||
]) {
|
||||
expect(
|
||||
_contrast(colors.onSurfaceVariant, surface),
|
||||
greaterThanOrEqualTo(4.5),
|
||||
);
|
||||
}
|
||||
expect(
|
||||
_contrast(colors.onPrimary, colors.primary),
|
||||
greaterThanOrEqualTo(4.5),
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
test('six theme combinations have distinct workspace colors', () {
|
||||
final signatures = {
|
||||
for (final palette in AppPalette.values)
|
||||
for (final brightness in Brightness.values)
|
||||
(
|
||||
EditorTheme.forPalette(palette, brightness).colorScheme.surface,
|
||||
EditorTheme.forPalette(palette, brightness).colorScheme.primary,
|
||||
),
|
||||
};
|
||||
expect(signatures.length, 6);
|
||||
});
|
||||
}
|
||||
|
||||
double _contrast(Color a, Color b) {
|
||||
final first = a.computeLuminance();
|
||||
final second = b.computeLuminance();
|
||||
return (math.max(first, second) + .05) / (math.min(first, second) + .05);
|
||||
}
|
||||
@@ -5,6 +5,7 @@ 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:cutdex_ui/theme.dart';
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
|
||||
@@ -44,12 +45,14 @@ void main() {
|
||||
supportedLocales: AppLocalizations.supportedLocales,
|
||||
locale: const Locale('zh'),
|
||||
|
||||
theme: EditorTheme.penLight,
|
||||
theme: AppTheme.propertiesPanelTheme(
|
||||
EditorTheme.desktop(EditorTheme.penLight),
|
||||
),
|
||||
home: Scaffold(
|
||||
body: Align(
|
||||
alignment: Alignment.topLeft,
|
||||
child: SizedBox(
|
||||
width: 225,
|
||||
width: 280,
|
||||
child: SingleChildScrollView(
|
||||
child: PictureProperties(
|
||||
projectId: project,
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import 'package:cutdex/app/editor_theme.dart';
|
||||
import 'package:cutdex_ui/icons.dart';
|
||||
import 'package:cutdex_ui/widgets.dart';
|
||||
import 'package:cutdex/workspace/timeline_provider.dart';
|
||||
import 'package:cutdex/l10n/app_localizations.dart';
|
||||
@@ -85,7 +86,7 @@ void main() {
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.text('素材缺失'), findsOneWidget);
|
||||
expect(find.byIcon(Icons.broken_image_outlined), findsOneWidget);
|
||||
expect(find.byIcon(AppIcons.imageUnavailable), findsOneWidget);
|
||||
expect(find.textContaining('RuntimeException'), findsNothing);
|
||||
expect(tester.widget<IconButton>(playButton).onPressed, isNull);
|
||||
expect(find.byTooltip('画布比例'), findsNothing);
|
||||
@@ -451,7 +452,7 @@ void main() {
|
||||
|
||||
await preview.togglePlayback();
|
||||
await tester.pump();
|
||||
expect(find.byIcon(Icons.pause), findsOneWidget);
|
||||
expect(find.byIcon(AppIcons.pause), findsOneWidget);
|
||||
expect(tester.widget(toolbar), same(toolbarBefore));
|
||||
expect(
|
||||
tester.widget<PreviewCanvas>(find.byType(PreviewCanvas)),
|
||||
|
||||
@@ -23,8 +23,8 @@ import 'package:cutdex/workspace/projects.dart';
|
||||
import 'package:cutdex/workspace/timeline_provider.dart';
|
||||
import 'package:cutdex/workspace/project_state.dart';
|
||||
import 'package:cutdex/workspace/persistence/recent_projects.dart';
|
||||
import 'package:cutdex_ui/icons.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/gestures.dart';
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
|
||||
@@ -534,19 +534,16 @@ void main() {
|
||||
),
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
final mouse = await tester.createGesture(kind: PointerDeviceKind.mouse);
|
||||
await mouse.addPointer(location: Offset.zero);
|
||||
await mouse.moveTo(
|
||||
tester.getCenter(find.byKey(const Key('projects-heading'))),
|
||||
);
|
||||
await tester.tap(find.byKey(const Key('project-tabs-projects')));
|
||||
await tester.pumpAndSettle();
|
||||
await tester.tap(find.byKey(const Key('create-project')));
|
||||
await mouse.removePointer();
|
||||
await tester.tap(find.text('新建项目'));
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.text('新建项目'), findsOneWidget);
|
||||
expect(find.byType(TextFormField), findsOneWidget);
|
||||
await tester.tap(find.text('取消'));
|
||||
await tester.pumpAndSettle();
|
||||
await tester.tap(find.byKey(const ValueKey('sidebar-project-empty')));
|
||||
await tester.tap(find.byKey(const Key('project-tabs-projects')));
|
||||
await tester.pumpAndSettle();
|
||||
await tester.tap(find.byKey(const ValueKey('project-menu-empty')));
|
||||
await tester.pumpAndSettle();
|
||||
expect(router.routeInformationProvider.value.uri.path, '/');
|
||||
expect(find.text('项目中还没有时间线'), findsOneWidget);
|
||||
@@ -564,60 +561,50 @@ void main() {
|
||||
},
|
||||
);
|
||||
|
||||
testWidgets('missing recent project stays visible and is dimmed', (
|
||||
tester,
|
||||
) async {
|
||||
tester.platformDispatcher.localesTestValue = const [Locale('zh')];
|
||||
addTearDown(tester.platformDispatcher.clearLocalesTestValue);
|
||||
final container = ProviderContainer(
|
||||
overrides: [
|
||||
deviceExperienceProvider.overrideWithValue(DeviceExperience.desktop),
|
||||
conversationRepositoryProvider.overrideWith(
|
||||
(ref) async => EmptyConversationRepository(),
|
||||
),
|
||||
testWidgets(
|
||||
'missing recent project is marked unavailable in the project menu',
|
||||
(tester) async {
|
||||
tester.platformDispatcher.localesTestValue = const [Locale('zh')];
|
||||
addTearDown(tester.platformDispatcher.clearLocalesTestValue);
|
||||
final container = ProviderContainer(
|
||||
overrides: [
|
||||
deviceExperienceProvider.overrideWithValue(DeviceExperience.desktop),
|
||||
conversationRepositoryProvider.overrideWith(
|
||||
(ref) async => EmptyConversationRepository(),
|
||||
),
|
||||
|
||||
projectsProvider.overrideWith(_MissingProjects.new),
|
||||
workspaceViewSettingsRepositoryProvider.overrideWithValue(
|
||||
_ExpandedMissingProjectSettings(),
|
||||
projectsProvider.overrideWith(_MissingProjects.new),
|
||||
workspaceViewSettingsRepositoryProvider.overrideWithValue(
|
||||
_ExpandedMissingProjectSettings(),
|
||||
),
|
||||
],
|
||||
);
|
||||
await tester.pumpWidget(
|
||||
UncontrolledProviderScope(
|
||||
container: container,
|
||||
child: MaterialApp.router(
|
||||
builder: (context, child) => ErrorNotificationHost(child: child!),
|
||||
localizationsDelegates: AppLocalizations.localizationsDelegates,
|
||||
supportedLocales: AppLocalizations.supportedLocales,
|
||||
locale: const Locale('zh'),
|
||||
theme: EditorTheme.penDark,
|
||||
routerConfig: container.read(appRouterProvider),
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
await tester.pumpWidget(
|
||||
UncontrolledProviderScope(
|
||||
container: container,
|
||||
child: MaterialApp.router(
|
||||
builder: (context, child) => ErrorNotificationHost(child: child!),
|
||||
localizationsDelegates: AppLocalizations.localizationsDelegates,
|
||||
supportedLocales: AppLocalizations.supportedLocales,
|
||||
locale: const Locale('zh'),
|
||||
theme: EditorTheme.penDark,
|
||||
routerConfig: container.read(appRouterProvider),
|
||||
),
|
||||
),
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
final tile = tester.widget<ListTile>(
|
||||
find.byKey(const ValueKey('sidebar-project-missing')),
|
||||
);
|
||||
expect(tile.enabled, isTrue);
|
||||
expect(tile.textColor, EditorTheme.penDark.disabledColor);
|
||||
expect(
|
||||
find.descendant(
|
||||
of: find.byKey(const ValueKey('sidebar-project-missing')),
|
||||
matching: find.byIcon(Icons.folder_off_outlined),
|
||||
),
|
||||
findsOneWidget,
|
||||
);
|
||||
expect(
|
||||
find.descendant(
|
||||
of: find.byKey(const ValueKey('sidebar-project-missing')),
|
||||
matching: find.text('项目不可用'),
|
||||
),
|
||||
findsOneWidget,
|
||||
);
|
||||
await tester.pumpWidget(const SizedBox());
|
||||
container.dispose();
|
||||
});
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
await tester.tap(find.byKey(const Key('project-tabs-projects')));
|
||||
await tester.pumpAndSettle();
|
||||
expect(
|
||||
find.byKey(const ValueKey('project-menu-missing')),
|
||||
findsOneWidget,
|
||||
);
|
||||
expect(find.byIcon(AppIcons.folderUnavailable), findsOneWidget);
|
||||
expect(find.textContaining('项目不可用'), findsOneWidget);
|
||||
await tester.pumpWidget(const SizedBox());
|
||||
container.dispose();
|
||||
},
|
||||
);
|
||||
|
||||
testWidgets('project errors use a dismissible floating toast', (
|
||||
tester,
|
||||
@@ -651,10 +638,10 @@ void main() {
|
||||
),
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.byIcon(Icons.error_outline), findsOneWidget);
|
||||
expect(find.byIcon(AppIcons.error), findsOneWidget);
|
||||
expect(find.text('操作失败,请重试'), findsOneWidget);
|
||||
expect(tester.getTopRight(find.byIcon(Icons.close)).dx, lessThan(1200));
|
||||
await tester.tap(find.byIcon(Icons.close));
|
||||
expect(tester.getTopRight(find.byIcon(AppIcons.close)).dx, lessThan(1200));
|
||||
await tester.tap(find.byIcon(AppIcons.close));
|
||||
await tester.pump(const Duration(milliseconds: 200));
|
||||
expect(find.byKey(const Key('global-error-notification')), findsNothing);
|
||||
await tester.pumpWidget(const SizedBox());
|
||||
|
||||
@@ -1,4 +1,7 @@
|
||||
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';
|
||||
|
||||
@@ -16,6 +19,152 @@ 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 {
|
||||
|
||||
@@ -0,0 +1,61 @@
|
||||
import 'package:cutdex/app/editor_theme.dart';
|
||||
import 'package:cutdex/features/properties/project_properties.dart';
|
||||
import 'package:cutdex/l10n/app_localizations.dart';
|
||||
import 'package:cutdex_sdk/editor.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
|
||||
import 'support/preview_fixture.dart';
|
||||
|
||||
void main() {
|
||||
testWidgets(
|
||||
'canvas edits refresh values while preserving property shell and labels',
|
||||
(tester) async {
|
||||
final fixture = (await tester.runAsync(
|
||||
() =>
|
||||
createPreviewFixture(Uri.file('/fixture.png'), mediaType: 'image'),
|
||||
))!;
|
||||
addTearDown(
|
||||
() => tester.runAsync(() async {
|
||||
await fixture.workspace.close();
|
||||
await fixture.directory.delete(recursive: true);
|
||||
}),
|
||||
);
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(
|
||||
localizationsDelegates: AppLocalizations.localizationsDelegates,
|
||||
supportedLocales: AppLocalizations.supportedLocales,
|
||||
locale: const Locale('zh'),
|
||||
theme: EditorTheme.penDark,
|
||||
home: Scaffold(
|
||||
body: SizedBox(
|
||||
width: 280,
|
||||
child: ProjectProperties(session: fixture.timeline),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
final label = tester.element(find.text('画布尺寸'));
|
||||
final value = tester.element(find.text('1080 × 1920 px'));
|
||||
final previous = debugOnRebuildDirtyWidget;
|
||||
var shellBuilds = 0;
|
||||
var labelBuilds = 0;
|
||||
debugOnRebuildDirtyWidget = (element, built) {
|
||||
previous?.call(element, built);
|
||||
if (element.widget is ProjectProperties) shellBuilds++;
|
||||
if (identical(element, label)) labelBuilds++;
|
||||
};
|
||||
addTearDown(() => debugOnRebuildDirtyWidget = previous);
|
||||
fixture.timeline.commands.setCanvas(ProjectCanvas.widescreen);
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.text('1920 × 1080 px'), findsOneWidget);
|
||||
expect(tester.element(find.text('1920 × 1080 px')), same(value));
|
||||
expect(shellBuilds, 0);
|
||||
expect(labelBuilds, 0);
|
||||
expect(tester.takeException(), isNull);
|
||||
await tester.pumpWidget(const SizedBox());
|
||||
await tester.runAsync(fixture.timeline.flush);
|
||||
},
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,249 @@
|
||||
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_sdk/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);
|
||||
}
|
||||
@@ -7,55 +7,37 @@ void main() {
|
||||
textDirection: TextDirection.ltr,
|
||||
child: ProjectSwitchRegion(
|
||||
pendingProjectId: pending,
|
||||
builder: (context, showDefaults) =>
|
||||
Text(showDefaults ? 'defaults' : 'content'),
|
||||
child: const Text('content'),
|
||||
),
|
||||
);
|
||||
|
||||
testWidgets(
|
||||
'fast completion never displays defaults or waits for the timer',
|
||||
(tester) async {
|
||||
await tester.pumpWidget(region('A'));
|
||||
expect(find.text('content'), findsOneWidget);
|
||||
testWidgets('slow and superseded switches retain mounted content', (
|
||||
tester,
|
||||
) async {
|
||||
await tester.pumpWidget(region(null));
|
||||
final content = tester.element(find.text('content'));
|
||||
for (final target in ['A', 'B', null]) {
|
||||
await tester.pumpWidget(region(target));
|
||||
await tester.pump(const Duration(seconds: 5));
|
||||
expect(tester.element(find.text('content')), same(content));
|
||||
expect(
|
||||
tester.widget<IgnorePointer>(find.byType(IgnorePointer)).ignoring,
|
||||
isTrue,
|
||||
target != null,
|
||||
);
|
||||
await tester.pump(const Duration(milliseconds: 100));
|
||||
await tester.pumpWidget(region(null));
|
||||
expect(find.text('defaults'), findsNothing);
|
||||
expect(
|
||||
tester.widget<IgnorePointer>(find.byType(IgnorePointer)).ignoring,
|
||||
isFalse,
|
||||
tester.widget<ExcludeFocus>(find.byType(ExcludeFocus)).excluding,
|
||||
target != null,
|
||||
);
|
||||
await tester.pump(const Duration(milliseconds: 200));
|
||||
expect(find.text('defaults'), findsNothing);
|
||||
},
|
||||
);
|
||||
expect(tester.takeException(), isNull);
|
||||
}
|
||||
});
|
||||
|
||||
testWidgets(
|
||||
'slow switches show defaults after 150ms and reset on a new target',
|
||||
(tester) async {
|
||||
await tester.pumpWidget(region('A'));
|
||||
await tester.pump(const Duration(milliseconds: 149));
|
||||
expect(find.text('defaults'), findsNothing);
|
||||
await tester.pump(const Duration(milliseconds: 1));
|
||||
expect(find.text('defaults'), findsOneWidget);
|
||||
await tester.pumpWidget(region('B'));
|
||||
expect(find.text('defaults'), findsNothing);
|
||||
await tester.pump(const Duration(milliseconds: 150));
|
||||
expect(find.text('defaults'), findsOneWidget);
|
||||
await tester.pumpWidget(region(null));
|
||||
expect(find.text('content'), findsOneWidget);
|
||||
},
|
||||
);
|
||||
|
||||
testWidgets('disposing during a switch cancels the pending timer', (
|
||||
testWidgets('disposing during preparation leaves no pending work', (
|
||||
tester,
|
||||
) async {
|
||||
await tester.pumpWidget(region('A'));
|
||||
await tester.pumpWidget(const SizedBox());
|
||||
await tester.pump(const Duration(milliseconds: 200));
|
||||
await tester.pump(const Duration(seconds: 5));
|
||||
expect(tester.takeException(), isNull);
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,521 @@
|
||||
import 'package:cutdex/features/projects/project_tabs_bar.dart';
|
||||
import 'package:cutdex/l10n/app_localizations.dart';
|
||||
import 'package:cutdex/workspace/project_state.dart';
|
||||
import 'package:cutdex_ui/theme.dart';
|
||||
import 'package:cutdex_native/cutdex_native.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/gestures.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
|
||||
void main() {
|
||||
const recent = [
|
||||
RecentProject(id: 'a', name: '旅行短片', path: '/Projects/A.cutdex'),
|
||||
RecentProject(
|
||||
id: 'b',
|
||||
name: '这是一个很长的中文项目名称用于验证窗口标签不会溢出',
|
||||
path: '/Projects/B.cutdex',
|
||||
),
|
||||
RecentProject(id: 'c', name: '尚未打开的项目', path: '/Projects/C.cutdex'),
|
||||
];
|
||||
Future<void> pumpTabs(
|
||||
WidgetTester tester, {
|
||||
required Widget tabs,
|
||||
double width = 720,
|
||||
}) => tester.pumpWidget(
|
||||
MaterialApp(
|
||||
theme: AppTheme.desktopWorkspaceTheme(
|
||||
AppTheme.forPalette(AppPalette.graphite, Brightness.dark),
|
||||
),
|
||||
locale: const Locale('zh'),
|
||||
localizationsDelegates: AppLocalizations.localizationsDelegates,
|
||||
supportedLocales: AppLocalizations.supportedLocales,
|
||||
home: Scaffold(
|
||||
body: SizedBox(width: width, height: 44, child: tabs),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
testWidgets(
|
||||
'plus follows the last tab while the menu leaves empty drag space',
|
||||
(tester) async {
|
||||
var created = 0;
|
||||
for (final opened in [recent.take(2).toList(), <RecentProject>[]]) {
|
||||
await pumpTabs(
|
||||
tester,
|
||||
tabs: ProjectTabsBar(
|
||||
projects: opened,
|
||||
recent: recent,
|
||||
selectedId: opened.firstOrNull?.id,
|
||||
onSelect: (_) {},
|
||||
onClose: (_) {},
|
||||
onCreate: () => created++,
|
||||
onOpen: () {},
|
||||
onRename: (_) {},
|
||||
),
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
final entry = tester.getRect(
|
||||
find.byKey(const Key('project-tabs-projects')),
|
||||
);
|
||||
final plus = tester.getRect(find.byKey(const Key('project-tabs-add')));
|
||||
final list = tester.getRect(find.byKey(const Key('project-tabs-list')));
|
||||
expect(entry.left, 4);
|
||||
expect(list.right, 716);
|
||||
if (opened.isNotEmpty) {
|
||||
final last = tester.getRect(
|
||||
find.byKey(ValueKey('project-tab-surface-${opened.last.id}')),
|
||||
);
|
||||
expect(plus.left - last.right, 4);
|
||||
} else {
|
||||
expect(plus.left - entry.right, 4);
|
||||
}
|
||||
final dragPoint = Offset((plus.right + list.left) / 2, 22);
|
||||
expect(list.left - plus.right, greaterThan(100));
|
||||
expect(
|
||||
find
|
||||
.byType(HeaderControlRegion)
|
||||
.evaluate()
|
||||
.any(
|
||||
(element) => tester
|
||||
.getRect(find.byWidget(element.widget))
|
||||
.contains(dragPoint),
|
||||
),
|
||||
isFalse,
|
||||
);
|
||||
await tester.tap(find.byKey(const Key('project-tabs-add')));
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.byKey(const ValueKey('project-menu-a')), findsNothing);
|
||||
expect(tester.takeException(), isNull);
|
||||
}
|
||||
expect(created, 2);
|
||||
},
|
||||
);
|
||||
|
||||
testWidgets('header menus do not swallow tab, create or other menu clicks', (
|
||||
tester,
|
||||
) async {
|
||||
final selected = <String>[];
|
||||
var created = 0;
|
||||
await pumpTabs(
|
||||
tester,
|
||||
tabs: ProjectTabsBar(
|
||||
projects: recent.take(2).toList(),
|
||||
recent: recent,
|
||||
selectedId: 'a',
|
||||
onSelect: (project) => selected.add(project.id),
|
||||
onClose: (_) {},
|
||||
onCreate: () => created++,
|
||||
onOpen: () {},
|
||||
onRename: (_) {},
|
||||
),
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
final projects = find.byKey(const Key('project-tabs-projects'));
|
||||
final list = find.byKey(const Key('project-tabs-list'));
|
||||
Future<void> click(Finder target) async {
|
||||
await tester.tap(target, kind: PointerDeviceKind.mouse);
|
||||
await tester.pumpAndSettle();
|
||||
}
|
||||
|
||||
await click(projects);
|
||||
expect(find.byKey(const ValueKey('project-menu-a')), findsOneWidget);
|
||||
await click(find.byKey(const ValueKey('project-tab-b')));
|
||||
expect(selected, ['b']);
|
||||
expect(find.byKey(const ValueKey('project-menu-a')), findsNothing);
|
||||
|
||||
await click(projects);
|
||||
await click(find.byKey(const Key('project-tabs-add')));
|
||||
expect(created, 1);
|
||||
expect(find.byKey(const ValueKey('project-menu-a')), findsNothing);
|
||||
|
||||
await click(projects);
|
||||
await click(list);
|
||||
expect(find.byKey(const ValueKey('project-menu-a')), findsNothing);
|
||||
expect(find.byKey(const ValueKey('project-tabs-menu-a')), findsOneWidget);
|
||||
await click(projects);
|
||||
expect(find.byKey(const ValueKey('project-tabs-menu-a')), findsNothing);
|
||||
expect(find.byKey(const ValueKey('project-menu-a')), findsOneWidget);
|
||||
await click(projects);
|
||||
expect(find.byKey(const ValueKey('project-menu-a')), findsNothing);
|
||||
expect(tester.takeException(), isNull);
|
||||
});
|
||||
|
||||
testWidgets('recent menu manages records without closing opened tabs', (
|
||||
tester,
|
||||
) async {
|
||||
var history = recent.toList();
|
||||
final renamed = <String>[];
|
||||
final closed = <String>[];
|
||||
await pumpTabs(
|
||||
tester,
|
||||
tabs: StatefulBuilder(
|
||||
builder: (context, setState) => ProjectTabsBar(
|
||||
projects: recent.take(2).toList(),
|
||||
recent: history,
|
||||
selectedId: 'a',
|
||||
onSelect: (_) {},
|
||||
onClose: (project) => closed.add(project.id),
|
||||
onCreate: () {},
|
||||
onOpen: () {},
|
||||
onRename: (project) => renamed.add(project.id),
|
||||
onRemoveRecent: (project) => setState(() {
|
||||
history = history.where((item) => item.id != project.id).toList();
|
||||
}),
|
||||
),
|
||||
),
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
await tester.tap(find.byKey(const Key('project-tabs-projects')));
|
||||
await tester.pumpAndSettle();
|
||||
await tester.tap(
|
||||
find.byKey(const ValueKey('project-menu-b')),
|
||||
buttons: kSecondaryMouseButton,
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
await tester.tap(find.text('重命名'));
|
||||
await tester.pumpAndSettle();
|
||||
expect(renamed, ['b']);
|
||||
// Reopen the recent menu if the context action dismissed it.
|
||||
if (find.byKey(const ValueKey('project-menu-b')).evaluate().isEmpty) {
|
||||
await tester.tap(find.byKey(const Key('project-tabs-projects')));
|
||||
await tester.pumpAndSettle();
|
||||
}
|
||||
await tester.tap(
|
||||
find.byKey(const ValueKey('project-menu-b')),
|
||||
buttons: kSecondaryMouseButton,
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
await tester.tap(find.text('从最近项目移除'));
|
||||
await tester.pumpAndSettle();
|
||||
expect(history.map((item) => item.id), ['a', 'c']);
|
||||
expect(find.byKey(const ValueKey('project-tab-b')), findsOneWidget);
|
||||
expect(closed, isEmpty);
|
||||
expect(tester.takeException(), isNull);
|
||||
});
|
||||
|
||||
testWidgets(
|
||||
'hover and keyboard focus reveal close without moving the label',
|
||||
(tester) async {
|
||||
var closed = 0;
|
||||
await pumpTabs(
|
||||
tester,
|
||||
tabs: ProjectTabsBar(
|
||||
projects: recent.take(2).toList(),
|
||||
recent: recent,
|
||||
selectedId: 'a',
|
||||
onSelect: (_) {},
|
||||
onClose: (_) => closed++,
|
||||
onCreate: () {},
|
||||
onOpen: () {},
|
||||
onRename: (_) {},
|
||||
),
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
final close = find.byKey(const ValueKey('project-tab-close-b'));
|
||||
final label = find.text(recent[1].name);
|
||||
final surface = find.byKey(const ValueKey('project-tab-surface-b'));
|
||||
final labelBefore = tester.getRect(label);
|
||||
final surfaceBefore = tester.getRect(surface);
|
||||
double opacity() => tester
|
||||
.widget<Opacity>(
|
||||
find.ancestor(of: close, matching: find.byType(Opacity)).first,
|
||||
)
|
||||
.opacity;
|
||||
expect(opacity(), 0);
|
||||
await tester.tap(close, warnIfMissed: false);
|
||||
expect(closed, 0);
|
||||
final mouse = await tester.createGesture(kind: PointerDeviceKind.mouse);
|
||||
await mouse.addPointer(location: const Offset(700, 80));
|
||||
await mouse.moveTo(tester.getCenter(label));
|
||||
await tester.pumpAndSettle();
|
||||
expect(opacity(), 1);
|
||||
expect(tester.getRect(label), labelBefore);
|
||||
expect(tester.getRect(surface), surfaceBefore);
|
||||
await mouse.moveTo(const Offset(700, 80));
|
||||
await tester.pumpAndSettle();
|
||||
expect(opacity(), 0);
|
||||
Focus.of(tester.element(label)).requestFocus();
|
||||
await tester.pumpAndSettle();
|
||||
expect(opacity(), 1);
|
||||
expect(tester.getRect(label), labelBefore);
|
||||
await tester.tap(close);
|
||||
expect(closed, 1);
|
||||
await mouse.removePointer();
|
||||
expect(tester.takeException(), isNull);
|
||||
},
|
||||
);
|
||||
|
||||
testWidgets(
|
||||
'opened project menu reveals a clipped tab and excludes recent files',
|
||||
(tester) async {
|
||||
var selected = 'a';
|
||||
await pumpTabs(
|
||||
tester,
|
||||
width: 240,
|
||||
tabs: StatefulBuilder(
|
||||
builder: (context, setState) => ProjectTabsBar(
|
||||
projects: recent.take(2).toList(),
|
||||
recent: recent,
|
||||
selectedId: selected,
|
||||
onSelect: (project) => setState(() => selected = project.id),
|
||||
onClose: (_) {},
|
||||
onCreate: () {},
|
||||
onOpen: () {},
|
||||
onRename: (_) {},
|
||||
),
|
||||
),
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
await tester.tap(find.byKey(const Key('project-tabs-list')));
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.byKey(const ValueKey('project-tabs-menu-a')), findsOneWidget);
|
||||
expect(find.byKey(const ValueKey('project-tabs-menu-b')), findsOneWidget);
|
||||
expect(find.byKey(const ValueKey('project-tabs-menu-c')), findsNothing);
|
||||
await tester.tap(find.byKey(const ValueKey('project-tabs-menu-b')));
|
||||
await tester.pumpAndSettle();
|
||||
expect(selected, 'b');
|
||||
final tab = tester.getRect(
|
||||
find.byKey(const ValueKey('project-tab-surface-b')),
|
||||
);
|
||||
expect(tab.left, greaterThanOrEqualTo(36));
|
||||
expect(
|
||||
tab.right,
|
||||
lessThanOrEqualTo(
|
||||
tester.getRect(find.byKey(const Key('project-tabs-list'))).left -
|
||||
AppProjectTabMetrics.gap,
|
||||
),
|
||||
);
|
||||
final plus = tester.getRect(find.byKey(const Key('project-tabs-add')));
|
||||
expect(plus.left - tab.right, AppProjectTabMetrics.gap);
|
||||
expect(
|
||||
plus.right,
|
||||
lessThanOrEqualTo(
|
||||
tester.getRect(find.byKey(const Key('project-tabs-list'))).left -
|
||||
AppProjectTabMetrics.gap,
|
||||
),
|
||||
);
|
||||
await tester.tap(find.byKey(const ValueKey('project-tab-b')));
|
||||
expect(tester.takeException(), isNull);
|
||||
},
|
||||
);
|
||||
|
||||
testWidgets('selection keeps geometry and navigation controls available', (
|
||||
tester,
|
||||
) async {
|
||||
var selected = 'a';
|
||||
late StateSetter update;
|
||||
await pumpTabs(
|
||||
tester,
|
||||
tabs: StatefulBuilder(
|
||||
builder: (context, setState) {
|
||||
update = setState;
|
||||
return ProjectTabsBar(
|
||||
projects: recent.take(2).toList(),
|
||||
recent: recent,
|
||||
selectedId: selected,
|
||||
onSelect: (project) => setState(() => selected = project.id),
|
||||
onClose: (_) {},
|
||||
onCreate: () {},
|
||||
onOpen: () {},
|
||||
onRename: (_) {},
|
||||
);
|
||||
},
|
||||
),
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
final surface = find.byKey(const ValueKey('project-tab-surface-a'));
|
||||
final before = tester.getRect(surface);
|
||||
update(() => selected = 'b');
|
||||
await tester.pumpAndSettle();
|
||||
expect(tester.getRect(surface), before);
|
||||
expect(find.byType(CircularProgressIndicator), findsNothing);
|
||||
expect(
|
||||
tester
|
||||
.widget<TextButton>(find.byKey(const ValueKey('project-tab-a')))
|
||||
.onPressed,
|
||||
isNotNull,
|
||||
);
|
||||
for (final key in [
|
||||
'project-tab-close-b',
|
||||
'project-tabs-add',
|
||||
'project-tabs-list',
|
||||
'project-tabs-projects',
|
||||
]) {
|
||||
expect(
|
||||
tester.widget<IconButton>(find.byKey(ValueKey(key))).onPressed,
|
||||
isNotNull,
|
||||
);
|
||||
}
|
||||
await tester.tap(find.byKey(const ValueKey('project-tab-a')));
|
||||
await tester.pumpAndSettle();
|
||||
expect(selected, 'a');
|
||||
expect(tester.takeException(), isNull);
|
||||
});
|
||||
|
||||
testWidgets('empty project bar keeps creation available', (tester) async {
|
||||
await pumpTabs(
|
||||
tester,
|
||||
width: 240,
|
||||
tabs: ProjectTabsBar(
|
||||
projects: const [],
|
||||
recent: recent,
|
||||
selectedId: null,
|
||||
onSelect: (_) {},
|
||||
onClose: (_) {},
|
||||
onCreate: () {},
|
||||
onOpen: () {},
|
||||
onRename: (_) {},
|
||||
),
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
expect(
|
||||
tester
|
||||
.widget<IconButton>(find.byKey(const Key('project-tabs-add')))
|
||||
.onPressed,
|
||||
isNotNull,
|
||||
);
|
||||
expect(
|
||||
tester
|
||||
.widget<IconButton>(find.byKey(const Key('project-tabs-list')))
|
||||
.onPressed,
|
||||
isNull,
|
||||
);
|
||||
expect(tester.takeException(), isNull);
|
||||
});
|
||||
testWidgets('open tabs, recent menu and close actions stay separate', (
|
||||
tester,
|
||||
) async {
|
||||
var selected = 'a';
|
||||
var opened = recent.take(2).toList();
|
||||
var created = 0;
|
||||
var picked = 0;
|
||||
late StateSetter update;
|
||||
Widget content() => StatefulBuilder(
|
||||
builder: (context, setState) {
|
||||
update = setState;
|
||||
return ProjectTabsBar(
|
||||
projects: opened,
|
||||
recent: recent,
|
||||
selectedId: selected,
|
||||
onSelect: (project) => setState(() {
|
||||
selected = project.id;
|
||||
if (!opened.contains(project)) opened = [...opened, project];
|
||||
}),
|
||||
onClose: (project) => setState(
|
||||
() => opened = opened.where((item) => item != project).toList(),
|
||||
),
|
||||
onCreate: () => created++,
|
||||
onOpen: () => picked++,
|
||||
onRename: (_) {},
|
||||
);
|
||||
},
|
||||
);
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(
|
||||
theme: AppTheme.desktopWorkspaceTheme(
|
||||
AppTheme.forPalette(AppPalette.graphite, Brightness.dark),
|
||||
),
|
||||
locale: const Locale('zh'),
|
||||
localizationsDelegates: AppLocalizations.localizationsDelegates,
|
||||
supportedLocales: AppLocalizations.supportedLocales,
|
||||
home: Scaffold(
|
||||
body: SizedBox(width: 320, height: 44, child: content()),
|
||||
),
|
||||
),
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.byKey(const ValueKey('project-tab-c')), findsNothing);
|
||||
await tester.tap(find.byKey(const Key('project-tabs-projects')));
|
||||
await tester.pumpAndSettle();
|
||||
await tester.tap(find.byKey(const ValueKey('project-menu-c')));
|
||||
await tester.pumpAndSettle();
|
||||
expect(selected, 'c');
|
||||
expect(find.byKey(const ValueKey('project-tab-c')), findsOneWidget);
|
||||
expect(
|
||||
tester.getRect(find.byKey(const ValueKey('project-tab-c'))).right,
|
||||
lessThanOrEqualTo(320),
|
||||
);
|
||||
await tester.tap(find.byKey(const ValueKey('project-tab-close-c')));
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.byKey(const ValueKey('project-tab-c')), findsNothing);
|
||||
expect(recent.length, 3);
|
||||
update(() => selected = 'a');
|
||||
await tester.pumpAndSettle();
|
||||
await tester.tap(find.byKey(const Key('project-tabs-projects')));
|
||||
await tester.pumpAndSettle();
|
||||
await tester.tap(find.text('新建项目'));
|
||||
await tester.pumpAndSettle();
|
||||
expect(created, 1);
|
||||
await tester.tap(find.byKey(const Key('project-tabs-projects')));
|
||||
await tester.pumpAndSettle();
|
||||
await tester.tap(find.text('打开项目…'));
|
||||
await tester.pumpAndSettle();
|
||||
expect(picked, 1);
|
||||
expect(tester.takeException(), isNull);
|
||||
});
|
||||
testWidgets('project tabs fit six themes, long names and scaled text', (
|
||||
tester,
|
||||
) async {
|
||||
for (final palette in AppPalette.values) {
|
||||
for (final brightness in Brightness.values) {
|
||||
for (final width in [240.0, 320.0, 720.0]) {
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(
|
||||
theme: AppTheme.desktopWorkspaceTheme(
|
||||
AppTheme.forPalette(palette, brightness),
|
||||
),
|
||||
locale: const Locale('zh'),
|
||||
localizationsDelegates: AppLocalizations.localizationsDelegates,
|
||||
supportedLocales: AppLocalizations.supportedLocales,
|
||||
home: MediaQuery(
|
||||
data: const MediaQueryData(textScaler: TextScaler.linear(1.5)),
|
||||
child: Scaffold(
|
||||
body: SizedBox(
|
||||
width: width,
|
||||
height: 44,
|
||||
child: ProjectTabsBar(
|
||||
projects: recent,
|
||||
recent: recent,
|
||||
selectedId: 'b',
|
||||
onSelect: (_) {},
|
||||
onClose: (_) {},
|
||||
onCreate: () {},
|
||||
onOpen: () {},
|
||||
onRename: (_) {},
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
final tab = tester.getRect(
|
||||
find.byKey(const ValueKey('project-tab-b')),
|
||||
);
|
||||
final close = tester.getRect(
|
||||
find.byKey(const ValueKey('project-tab-close-b')),
|
||||
);
|
||||
final add = tester.getRect(find.byKey(const Key('project-tabs-add')));
|
||||
expect(tab.height, AppProjectTabMetrics.height);
|
||||
expect(close.height, AppProjectTabMetrics.close);
|
||||
expect(add.height, tab.height);
|
||||
expect(close.center.dy, tab.center.dy);
|
||||
expect(add.center.dy, tab.center.dy);
|
||||
expect(tab.center.dy, 22);
|
||||
final list = tester.getRect(
|
||||
find.byKey(const Key('project-tabs-list')),
|
||||
);
|
||||
expect(list.height, tab.height);
|
||||
expect(list.center.dy, tab.center.dy);
|
||||
expect(width - list.right, AppProjectTabMetrics.gap);
|
||||
expect(
|
||||
close.right,
|
||||
lessThanOrEqualTo(list.left - AppProjectTabMetrics.gap),
|
||||
);
|
||||
expect(tab.right, lessThanOrEqualTo(width));
|
||||
expect(tester.takeException(), isNull);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -2,6 +2,8 @@ import 'support/creation_names.dart';
|
||||
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:cutdex/errors/app_failure.dart';
|
||||
|
||||
import 'package:cutdex_sdk/editor/commands.dart';
|
||||
|
||||
import 'package:cutdex/workspace/persistence/project_workspace.dart';
|
||||
@@ -267,12 +269,24 @@ void main() {
|
||||
expect(workspace.project!.info.id, id);
|
||||
await expectLater(
|
||||
workspace.open(path, expectedId: 'wrong'),
|
||||
throwsStateError,
|
||||
throwsA(
|
||||
isA<AppException>().having(
|
||||
(error) => error.failure.code,
|
||||
'code',
|
||||
AppErrorCode.projectMismatch,
|
||||
),
|
||||
),
|
||||
);
|
||||
expect(workspace.project!.info.id, id);
|
||||
await expectLater(
|
||||
workspace.open(path, name: 'Overwrite'),
|
||||
throwsA(isA<ProjectFileException>()),
|
||||
throwsA(
|
||||
isA<AppException>().having(
|
||||
(error) => error.failure.code,
|
||||
'code',
|
||||
AppErrorCode.projectAlreadyExists,
|
||||
),
|
||||
),
|
||||
);
|
||||
expect(workspace.project!.info.id, id);
|
||||
await workspace.open('${root.path}/Two.cutdex', name: 'Two');
|
||||
|
||||
@@ -12,6 +12,62 @@ import 'package:flutter_test/flutter_test.dart';
|
||||
import 'support/preview_fixture.dart';
|
||||
|
||||
void main() {
|
||||
testWidgets('inactive picture properties ignore replacement notifications', (
|
||||
tester,
|
||||
) async {
|
||||
final fixture = (await tester.runAsync(
|
||||
() =>
|
||||
createPreviewFixture(Uri.file('/test/image.png'), mediaType: 'image'),
|
||||
))!;
|
||||
addTearDown(
|
||||
() => tester.runAsync(() async {
|
||||
await fixture.workspace.close();
|
||||
await fixture.directory.delete(recursive: true);
|
||||
}),
|
||||
);
|
||||
final view = fixture.timeline.view(SequenceId('one'));
|
||||
final clip = view.version.kernelVersion.query().element(
|
||||
view.version.kernelVersion.query().elementById(ElementId('clip'))!,
|
||||
);
|
||||
final project = fixture.workspace.project!.info.id;
|
||||
final container = ProviderContainer(
|
||||
overrides: [
|
||||
editorPreviewProvider(project, 'project').overrideWith((ref) => null),
|
||||
],
|
||||
);
|
||||
addTearDown(container.dispose);
|
||||
Widget host(Widget child) => UncontrolledProviderScope(
|
||||
container: container,
|
||||
child: MaterialApp(
|
||||
localizationsDelegates: AppLocalizations.localizationsDelegates,
|
||||
supportedLocales: AppLocalizations.supportedLocales,
|
||||
locale: const Locale('zh'),
|
||||
theme: EditorTheme.penLight,
|
||||
home: Scaffold(body: SingleChildScrollView(child: child)),
|
||||
),
|
||||
);
|
||||
await tester.pumpWidget(
|
||||
host(
|
||||
PictureProperties(
|
||||
projectId: project,
|
||||
timelineId: 'project',
|
||||
session: fixture.timeline,
|
||||
sequence: SequenceId('one'),
|
||||
clip: clip,
|
||||
),
|
||||
),
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.byKey(const ValueKey('picture-x')), findsOneWidget);
|
||||
await tester.pumpWidget(
|
||||
host(_NotifyOnMount(() => view.seekTo(TimelineClock.ticksPerSecond))),
|
||||
);
|
||||
expect(view.playheadTick, TimelineClock.ticksPerSecond);
|
||||
expect(find.byType(PictureProperties), findsNothing);
|
||||
expect(tester.takeException(), isNull);
|
||||
await tester.pumpWidget(const SizedBox());
|
||||
});
|
||||
|
||||
testWidgets('cursor changes preserve inspector selection subscriptions', (
|
||||
tester,
|
||||
) async {
|
||||
@@ -35,6 +91,17 @@ void main() {
|
||||
view.setSelection([clip]);
|
||||
expect(inspector.selectedClips.single.id, ElementId('clip'));
|
||||
final selectedCount = notifications;
|
||||
f.timeline.commands.setTransform(
|
||||
sequence: SequenceId('one'),
|
||||
clip: ElementId('clip'),
|
||||
tick: 0,
|
||||
change: (value) => value.copyWith(x: .25),
|
||||
);
|
||||
expect(
|
||||
notifications,
|
||||
selectedCount,
|
||||
reason: 'Property values belong to editors, not selection shell',
|
||||
);
|
||||
view.beginScrubbing();
|
||||
for (var i = 1; i <= 120; i++) {
|
||||
view.seekTo(i * TimelineClock.ticksPerSecond ~/ 120);
|
||||
@@ -53,6 +120,7 @@ void main() {
|
||||
switchedCount,
|
||||
reason: 'Old sequence listener is detached',
|
||||
);
|
||||
await tester.runAsync(f.timeline.flush);
|
||||
});
|
||||
|
||||
testWidgets('static controls stay stable and discard edits after a seek', (
|
||||
@@ -144,3 +212,22 @@ void main() {
|
||||
await tester.pumpWidget(const SizedBox.shrink());
|
||||
});
|
||||
}
|
||||
|
||||
class _NotifyOnMount extends StatefulWidget {
|
||||
const _NotifyOnMount(this.notify);
|
||||
final VoidCallback notify;
|
||||
|
||||
@override
|
||||
State<_NotifyOnMount> createState() => _NotifyOnMountState();
|
||||
}
|
||||
|
||||
class _NotifyOnMountState extends State<_NotifyOnMount> {
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
widget.notify();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) => const SizedBox();
|
||||
}
|
||||
@@ -0,0 +1,126 @@
|
||||
import 'package:cutdex/app/editor_theme.dart';
|
||||
import 'package:cutdex/features/preview/preview_panel.dart';
|
||||
import 'package:cutdex/features/properties/properties_panel.dart';
|
||||
import 'package:cutdex/l10n/app_localizations.dart';
|
||||
import 'package:cutdex/workspace/timeline_provider.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(
|
||||
'property categories restore scroll and expansion independently',
|
||||
(tester) async {
|
||||
final f = (await tester.runAsync(
|
||||
() => createPreviewFixture(Uri.file('/test/video.mov'), hasAudio: true),
|
||||
))!;
|
||||
addTearDown(
|
||||
() => tester.runAsync(() async {
|
||||
await f.workspace.close();
|
||||
await f.directory.delete(recursive: true);
|
||||
}),
|
||||
);
|
||||
final project = f.workspace.project!.info.id;
|
||||
final view = f.timeline.view(SequenceId('one'));
|
||||
view.setSelection([
|
||||
view.version.kernelVersion.query().elementById(ElementId('clip'))!,
|
||||
]);
|
||||
final container = ProviderContainer(
|
||||
overrides: [
|
||||
editorTimelineProvider(
|
||||
project,
|
||||
'project',
|
||||
).overrideWith((_) => f.timeline),
|
||||
editorPreviewProvider(project, 'project').overrideWith((_) => null),
|
||||
],
|
||||
);
|
||||
addTearDown(container.dispose);
|
||||
final bucket = PageStorageBucket();
|
||||
Widget host(Widget child) => UncontrolledProviderScope(
|
||||
container: container,
|
||||
child: MaterialApp(
|
||||
theme: EditorTheme.desktop(EditorTheme.penDark),
|
||||
locale: const Locale('zh'),
|
||||
localizationsDelegates: AppLocalizations.localizationsDelegates,
|
||||
supportedLocales: AppLocalizations.supportedLocales,
|
||||
home: Scaffold(
|
||||
body: Align(
|
||||
alignment: Alignment.topLeft,
|
||||
child: SizedBox(
|
||||
width: 280,
|
||||
height: 240,
|
||||
child: PageStorage(bucket: bucket, child: child),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
// A running app can still have the old bool saved when hot reloaded.
|
||||
await tester.pumpWidget(
|
||||
host(
|
||||
Builder(
|
||||
key: PageStorageKey((ElementId('clip'), PropertyCategory.picture)),
|
||||
builder: (context) {
|
||||
bucket.writeState(context, true);
|
||||
return const SizedBox();
|
||||
},
|
||||
),
|
||||
),
|
||||
);
|
||||
await tester.pumpWidget(
|
||||
host(EditorPropertiesPanel(projectId: project, timelineId: 'project')),
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
expect(tester.takeException(), isNull);
|
||||
expect(find.byKey(const Key('media-color-menu')), findsNothing);
|
||||
await tester.tap(find.text('素材色彩解释'));
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.byKey(const Key('media-color-menu')), findsOneWidget);
|
||||
|
||||
Future<void> switchBack() async {
|
||||
await tester.tap(find.byKey(const ValueKey('property-tab-audio')));
|
||||
await tester.pumpAndSettle();
|
||||
expect(tester.takeException(), isNull);
|
||||
await tester.tap(find.byKey(const ValueKey('property-tab-picture')));
|
||||
await tester.pumpAndSettle();
|
||||
expect(tester.takeException(), isNull);
|
||||
}
|
||||
|
||||
ScrollPosition position() {
|
||||
final scrollView = find.byWidgetPredicate(
|
||||
(widget) =>
|
||||
widget is SingleChildScrollView &&
|
||||
widget.scrollDirection == Axis.vertical,
|
||||
);
|
||||
return tester
|
||||
.state<ScrollableState>(
|
||||
find
|
||||
.descendant(of: scrollView, matching: find.byType(Scrollable))
|
||||
.first,
|
||||
)
|
||||
.position;
|
||||
}
|
||||
|
||||
await switchBack();
|
||||
expect(find.byKey(const Key('media-color-menu')), findsOneWidget);
|
||||
position().jumpTo(55);
|
||||
await tester.pumpAndSettle();
|
||||
expect(position().pixels, 55);
|
||||
await switchBack();
|
||||
expect(position().pixels, 55);
|
||||
expect(find.byKey(const Key('media-color-menu')), findsOneWidget);
|
||||
|
||||
position().jumpTo(0);
|
||||
await tester.pumpAndSettle();
|
||||
await tester.tap(find.text('素材色彩解释'));
|
||||
await tester.pumpAndSettle();
|
||||
await switchBack();
|
||||
expect(find.byKey(const Key('media-color-menu')), findsNothing);
|
||||
expect(position().pixels, 0);
|
||||
await tester.pumpWidget(const SizedBox());
|
||||
},
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,250 @@
|
||||
import 'dart:async';
|
||||
|
||||
import 'package:cutdex/app/editor_theme.dart';
|
||||
import 'package:cutdex/features/properties/property_number_input.dart';
|
||||
import 'package:cutdex/l10n/app_localizations.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:cutdex_ui/theme.dart';
|
||||
import 'package:cutdex_ui/widgets.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
|
||||
void main() {
|
||||
testWidgets('top parameter label retains drag, submit and escape', (
|
||||
tester,
|
||||
) async {
|
||||
var starts = 0;
|
||||
var ends = 0;
|
||||
var distance = 0.0;
|
||||
final submitted = <double>[];
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(
|
||||
localizationsDelegates: AppLocalizations.localizationsDelegates,
|
||||
supportedLocales: AppLocalizations.supportedLocales,
|
||||
theme: AppTheme.propertiesPanelTheme(
|
||||
EditorTheme.desktop(EditorTheme.penDark),
|
||||
),
|
||||
home: Scaffold(
|
||||
body: Center(
|
||||
child: SizedBox(
|
||||
width: 256,
|
||||
child: PropertyNumberInput(
|
||||
label: 'Rotation',
|
||||
unit: '°',
|
||||
value: 0,
|
||||
enabled: true,
|
||||
readOnly: false,
|
||||
scrubbing: false,
|
||||
editContext: 0,
|
||||
submit: (value) async {
|
||||
submitted.add(value);
|
||||
return true;
|
||||
},
|
||||
onScrubStart: () {
|
||||
starts++;
|
||||
return true;
|
||||
},
|
||||
onScrubUpdate: (value) => distance = value,
|
||||
onScrubEnd: () => ends++,
|
||||
onScrubCancel: () {},
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
expect(tester.getSize(find.byType(TextField)).height, 28);
|
||||
expect(
|
||||
tester
|
||||
.getRect(
|
||||
find
|
||||
.ancestor(
|
||||
of: find.byType(AppScrubLabel),
|
||||
matching: find.byType(Row),
|
||||
)
|
||||
.first,
|
||||
)
|
||||
.bottom,
|
||||
tester.getTopLeft(find.byType(TextField)).dy - 4,
|
||||
);
|
||||
await tester.drag(find.byType(AppScrubLabel), const Offset(30, 0));
|
||||
await tester.pump();
|
||||
expect(starts, 1);
|
||||
expect(ends, 1);
|
||||
expect(distance, greaterThan(0));
|
||||
await tester.enterText(find.byType(TextField), '45');
|
||||
await tester.testTextInput.receiveAction(TextInputAction.done);
|
||||
await tester.pumpAndSettle();
|
||||
expect(submitted, [45]);
|
||||
await tester.enterText(find.byType(TextField), '90');
|
||||
await tester.sendKeyEvent(LogicalKeyboardKey.escape);
|
||||
await tester.pumpAndSettle();
|
||||
expect(
|
||||
tester.widget<TextField>(find.byType(TextField)).controller!.text,
|
||||
'0',
|
||||
);
|
||||
expect(submitted, [45]);
|
||||
expect(tester.takeException(), isNull);
|
||||
});
|
||||
|
||||
testWidgets('old submission cannot overwrite input in a new edit context', (
|
||||
tester,
|
||||
) async {
|
||||
final input = _Input();
|
||||
await input.mount(tester);
|
||||
await input.submit(tester, '11');
|
||||
input.update(() {
|
||||
input.editContext = 1;
|
||||
input.value = 2;
|
||||
});
|
||||
await tester.pump();
|
||||
await tester.enterText(find.byType(TextField), '33');
|
||||
input.pending.single.complete(false);
|
||||
await tester.pump();
|
||||
expect(input.field(tester).controller!.text, '33');
|
||||
expect(input.field(tester).decoration!.errorText, isNull);
|
||||
});
|
||||
|
||||
testWidgets('old submission cannot overwrite new input in the same context', (
|
||||
tester,
|
||||
) async {
|
||||
final input = _Input();
|
||||
await input.mount(tester);
|
||||
await input.submit(tester, '11');
|
||||
await tester.enterText(find.byType(TextField), '33');
|
||||
input.pending.single.complete(false);
|
||||
await tester.pump();
|
||||
expect(input.field(tester).controller!.text, '33');
|
||||
expect(input.field(tester).decoration!.errorText, isNull);
|
||||
});
|
||||
|
||||
testWidgets('returning to the old context does not revive its submission', (
|
||||
tester,
|
||||
) async {
|
||||
final input = _Input();
|
||||
await input.mount(tester);
|
||||
await input.submit(tester, '11');
|
||||
input.update(() => input.editContext = 1);
|
||||
await tester.pump();
|
||||
input.update(() => input.editContext = 0);
|
||||
await tester.pump();
|
||||
input.pending.single.complete(false);
|
||||
await tester.pump();
|
||||
expect(input.field(tester).controller!.text, '1');
|
||||
expect(input.field(tester).decoration!.errorText, isNull);
|
||||
});
|
||||
|
||||
testWidgets(
|
||||
'out of order completion preserves the latest submission result',
|
||||
(tester) async {
|
||||
final input = _Input();
|
||||
await input.mount(tester);
|
||||
await input.submit(tester, '11');
|
||||
await input.submit(tester, '33');
|
||||
expect(input.values, [11, 33]);
|
||||
input.pending[1].complete(false);
|
||||
await tester.pump();
|
||||
final error = input.field(tester).decoration!.errorText;
|
||||
expect(error, isNotEmpty);
|
||||
input.pending[0].complete(true);
|
||||
await tester.pump();
|
||||
expect(input.field(tester).decoration!.errorText, error);
|
||||
},
|
||||
);
|
||||
|
||||
testWidgets(
|
||||
'normal save still completes when the parent disables the input',
|
||||
(tester) async {
|
||||
final input = _Input();
|
||||
await input.mount(tester);
|
||||
await input.submit(tester, '11');
|
||||
input.update(() => input.enabled = false);
|
||||
await tester.pump();
|
||||
input.update(() {
|
||||
input.enabled = true;
|
||||
input.value = 11;
|
||||
});
|
||||
await tester.pump();
|
||||
input.pending.single.complete(true);
|
||||
await tester.pump();
|
||||
expect(input.field(tester).controller!.text, '11');
|
||||
expect(input.field(tester).decoration!.errorText, isNull);
|
||||
},
|
||||
);
|
||||
|
||||
testWidgets('escape discards an outstanding submission result', (
|
||||
tester,
|
||||
) async {
|
||||
final input = _Input();
|
||||
await input.mount(tester);
|
||||
await input.submit(tester, '11');
|
||||
await tester.sendKeyEvent(LogicalKeyboardKey.escape);
|
||||
await tester.pump();
|
||||
input.pending.single.complete(false);
|
||||
await tester.pump();
|
||||
expect(input.field(tester).controller!.text, '1');
|
||||
expect(input.field(tester).decoration!.errorText, isNull);
|
||||
});
|
||||
|
||||
testWidgets('submission completion ignores a disposed input', (tester) async {
|
||||
final input = _Input();
|
||||
await input.mount(tester);
|
||||
await input.submit(tester, '11');
|
||||
await tester.pumpWidget(const SizedBox());
|
||||
input.pending.single.complete(false);
|
||||
await tester.pump();
|
||||
expect(tester.takeException(), isNull);
|
||||
});
|
||||
}
|
||||
|
||||
class _Input {
|
||||
int editContext = 0;
|
||||
double value = 1;
|
||||
bool enabled = true;
|
||||
final pending = <Completer<bool>>[];
|
||||
final values = <double>[];
|
||||
late StateSetter update;
|
||||
|
||||
TextField field(WidgetTester tester) =>
|
||||
tester.widget<TextField>(find.byType(TextField));
|
||||
|
||||
Future<void> submit(WidgetTester tester, String text) async {
|
||||
await tester.enterText(find.byType(TextField), text);
|
||||
await tester.testTextInput.receiveAction(TextInputAction.done);
|
||||
await tester.pump();
|
||||
}
|
||||
|
||||
Future<void> mount(WidgetTester tester) => tester.pumpWidget(
|
||||
MaterialApp(
|
||||
theme: EditorTheme.penLight,
|
||||
localizationsDelegates: AppLocalizations.localizationsDelegates,
|
||||
supportedLocales: AppLocalizations.supportedLocales,
|
||||
locale: const Locale('zh'),
|
||||
home: Scaffold(
|
||||
body: StatefulBuilder(
|
||||
builder: (_, setState) {
|
||||
update = setState;
|
||||
return PropertyNumberInput(
|
||||
label: 'X',
|
||||
value: value,
|
||||
enabled: enabled,
|
||||
readOnly: false,
|
||||
submit: (value) {
|
||||
values.add(value);
|
||||
final result = Completer<bool>();
|
||||
pending.add(result);
|
||||
return result.future;
|
||||
},
|
||||
onScrubUpdate: (_) {},
|
||||
onScrubEnd: () {},
|
||||
onScrubCancel: () {},
|
||||
scrubbing: false,
|
||||
editContext: editContext,
|
||||
);
|
||||
},
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,322 @@
|
||||
import 'dart:async';
|
||||
|
||||
import 'package:cutdex/app/editor_theme.dart';
|
||||
import 'package:cutdex/features/preview/preview_panel.dart';
|
||||
import 'package:cutdex/features/properties/picture_properties.dart';
|
||||
import 'package:cutdex/features/properties/mask_properties.dart';
|
||||
import 'package:cutdex/l10n/app_localizations.dart';
|
||||
import 'package:cutdex/workspace/timeline_session.dart';
|
||||
import 'package:cutdex_sdk/editor.dart';
|
||||
import 'package:cutdex_sdk/preview.dart';
|
||||
import 'package:cutdex_sdk/runtime.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('old mask cleanup cannot release the new editing binding', (
|
||||
tester,
|
||||
) async {
|
||||
final fixture = (await tester.runAsync(
|
||||
() => createPreviewFixture(
|
||||
Uri.file('/test/video.mov'),
|
||||
timelineOverride: _sequence(),
|
||||
),
|
||||
))!;
|
||||
final preview = _BlockedPreview(fixture.timeline);
|
||||
addTearDown(
|
||||
() => tester.runAsync(() async {
|
||||
await preview.close();
|
||||
await fixture.workspace.close();
|
||||
await fixture.directory.delete(recursive: true);
|
||||
}),
|
||||
);
|
||||
final container = ProviderContainer(
|
||||
overrides: [
|
||||
editorPreviewProvider(
|
||||
'project',
|
||||
'timeline',
|
||||
).overrideWith((_) => preview),
|
||||
],
|
||||
);
|
||||
addTearDown(container.dispose);
|
||||
var selected = ElementId('clip');
|
||||
late StateSetter update;
|
||||
await tester.pumpWidget(
|
||||
_host(
|
||||
container,
|
||||
StatefulBuilder(
|
||||
builder: (_, setState) {
|
||||
update = setState;
|
||||
return MaskProperties(
|
||||
projectId: 'project',
|
||||
timelineId: 'timeline',
|
||||
element: selected,
|
||||
);
|
||||
},
|
||||
),
|
||||
),
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
expect(preview.maskEditingElement, ElementId('clip'));
|
||||
update(() => selected = ElementId('other'));
|
||||
await tester.pumpAndSettle();
|
||||
expect(preview.maskEditingElement, ElementId('other'));
|
||||
expect(tester.takeException(), isNull);
|
||||
await tester.pumpWidget(const SizedBox());
|
||||
await tester.pump();
|
||||
expect(preview.maskEditingElement, isNull);
|
||||
});
|
||||
|
||||
testWidgets(
|
||||
'unsubmitted values are discarded when another clip is selected',
|
||||
(tester) async {
|
||||
final fixture = (await tester.runAsync(
|
||||
() => createPreviewFixture(
|
||||
Uri.file('/test/video.mov'),
|
||||
timelineOverride: _sequence(),
|
||||
),
|
||||
))!;
|
||||
addTearDown(
|
||||
() => tester.runAsync(() async {
|
||||
await fixture.workspace.close();
|
||||
await fixture.directory.delete(recursive: true);
|
||||
}),
|
||||
);
|
||||
final container = ProviderContainer(
|
||||
overrides: [
|
||||
editorPreviewProvider(
|
||||
'project',
|
||||
'timeline',
|
||||
).overrideWith((_) => null),
|
||||
],
|
||||
);
|
||||
addTearDown(container.dispose);
|
||||
final view = fixture.timeline.view(SequenceId('one'));
|
||||
var selected = ElementId('clip');
|
||||
late StateSetter update;
|
||||
await tester.pumpWidget(
|
||||
_host(
|
||||
container,
|
||||
StatefulBuilder(
|
||||
builder: (_, setState) {
|
||||
update = setState;
|
||||
final query = view.version.kernelVersion.query();
|
||||
return PictureProperties(
|
||||
projectId: 'project',
|
||||
timelineId: 'timeline',
|
||||
session: fixture.timeline,
|
||||
sequence: SequenceId('one'),
|
||||
clip: query.element(query.elementById(selected)!),
|
||||
);
|
||||
},
|
||||
),
|
||||
),
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
final field = find.descendant(
|
||||
of: find.byKey(const ValueKey('picture-x')),
|
||||
matching: find.byType(TextField),
|
||||
);
|
||||
final element = tester.element(field);
|
||||
await tester.enterText(field, '999');
|
||||
update(() => selected = ElementId('other'));
|
||||
await tester.pump();
|
||||
expect(tester.element(field), same(element));
|
||||
expect(tester.widget<TextField>(field).controller!.text, '0');
|
||||
await tester.testTextInput.receiveAction(TextInputAction.done);
|
||||
await tester.pumpAndSettle();
|
||||
final query = view.version.kernelVersion.query();
|
||||
expect(
|
||||
ClipTransform.fromRecord(query.element(query.elementById(selected)!)).x,
|
||||
0,
|
||||
);
|
||||
expect(tester.takeException(), isNull);
|
||||
await tester.pumpWidget(const SizedBox());
|
||||
},
|
||||
);
|
||||
|
||||
for (final change in [
|
||||
'clip',
|
||||
'clip-return',
|
||||
'timeline',
|
||||
'preview',
|
||||
'position',
|
||||
'new-seek',
|
||||
'none',
|
||||
]) {
|
||||
testWidgets('pending keyframe seek follows its captured context: $change', (
|
||||
tester,
|
||||
) async {
|
||||
final fixture = (await tester.runAsync(
|
||||
() => createPreviewFixture(
|
||||
Uri.file('/test/video.mov'),
|
||||
timelineOverride: _sequence(),
|
||||
),
|
||||
))!;
|
||||
final session = fixture.timeline;
|
||||
final sequence = SequenceId('one');
|
||||
final view = session.view(sequence);
|
||||
session.commands.editKeyframeChannel(
|
||||
sequence: sequence,
|
||||
clip: ElementId('clip'),
|
||||
tick: 0,
|
||||
parameterIds: TransformChannel.position.ids,
|
||||
);
|
||||
session.commands.setTransform(
|
||||
sequence: sequence,
|
||||
clip: ElementId('clip'),
|
||||
tick: 2 * TimelineClock.ticksPerSecond,
|
||||
change: (value) => value.copyWith(x: .2),
|
||||
);
|
||||
await tester.runAsync(session.flush);
|
||||
view.seekTo(TimelineClock.ticksPerSecond);
|
||||
final preview = _BlockedPreview(session);
|
||||
final replacement = _BlockedPreview(session);
|
||||
var boundPreview = preview;
|
||||
addTearDown(
|
||||
() => tester.runAsync(() async {
|
||||
if (!preview.pause.isCompleted) preview.pause.complete();
|
||||
await preview.close();
|
||||
await replacement.close();
|
||||
await fixture.workspace.close();
|
||||
await fixture.directory.delete(recursive: true);
|
||||
}),
|
||||
);
|
||||
final container = ProviderContainer(
|
||||
overrides: [
|
||||
for (final id in ['timeline', 'other-timeline'])
|
||||
editorPreviewProvider(
|
||||
'project',
|
||||
id,
|
||||
).overrideWith((_) => boundPreview),
|
||||
],
|
||||
);
|
||||
addTearDown(container.dispose);
|
||||
var selected = ElementId('clip');
|
||||
var timelineId = 'timeline';
|
||||
late StateSetter update;
|
||||
await tester.pumpWidget(
|
||||
_host(
|
||||
container,
|
||||
StatefulBuilder(
|
||||
builder: (_, setState) {
|
||||
update = setState;
|
||||
final query = view.version.kernelVersion.query();
|
||||
return PictureProperties(
|
||||
projectId: 'project',
|
||||
timelineId: timelineId,
|
||||
session: session,
|
||||
sequence: sequence,
|
||||
clip: query.element(query.elementById(selected)!),
|
||||
animationView: true,
|
||||
);
|
||||
},
|
||||
),
|
||||
),
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
final button = tester.widget<IconButton>(
|
||||
find.byKey(const ValueKey('picture-key-next-position')),
|
||||
);
|
||||
final operation = Function.apply(button.onPressed!, []) as Future<void>;
|
||||
Future<void>? newerSeek;
|
||||
await tester.pump();
|
||||
if (change == 'clip' || change == 'clip-return') {
|
||||
update(() => selected = ElementId('other'));
|
||||
await tester.pump();
|
||||
if (change == 'clip-return') {
|
||||
update(() => selected = ElementId('clip'));
|
||||
await tester.pump();
|
||||
}
|
||||
} else if (change == 'timeline') {
|
||||
update(() => timelineId = 'other-timeline');
|
||||
await tester.pump();
|
||||
} else if (change == 'position') {
|
||||
view.seekTo(3 * TimelineClock.ticksPerSecond);
|
||||
await tester.pump();
|
||||
} else if (change == 'preview') {
|
||||
boundPreview = replacement;
|
||||
container.invalidate(editorPreviewProvider('project', 'timeline'));
|
||||
await tester.pumpAndSettle();
|
||||
} else if (change == 'new-seek') {
|
||||
final previous = tester.widget<IconButton>(
|
||||
find.byKey(const ValueKey('picture-key-previous-position')),
|
||||
);
|
||||
newerSeek = Function.apply(previous.onPressed!, []) as Future<void>;
|
||||
}
|
||||
preview.pause.complete();
|
||||
await expectLater(operation, completes);
|
||||
if (newerSeek != null) await expectLater(newerSeek, completes);
|
||||
final seconds = switch (change) {
|
||||
'none' => 2,
|
||||
'position' => 3,
|
||||
'new-seek' => 0,
|
||||
_ => 1,
|
||||
};
|
||||
expect(view.playheadTick, TimelineClock.ticksPerSecond * seconds);
|
||||
expect(tester.takeException(), isNull);
|
||||
await tester.pumpWidget(const SizedBox());
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
Widget _host(ProviderContainer container, Widget child) =>
|
||||
UncontrolledProviderScope(
|
||||
container: container,
|
||||
child: MaterialApp(
|
||||
theme: EditorTheme.desktop(EditorTheme.penLight),
|
||||
localizationsDelegates: AppLocalizations.localizationsDelegates,
|
||||
supportedLocales: AppLocalizations.supportedLocales,
|
||||
locale: const Locale('zh'),
|
||||
home: Scaffold(body: SingleChildScrollView(child: child)),
|
||||
),
|
||||
);
|
||||
|
||||
TimelineDto _sequence() => TimelineDto(
|
||||
id: SequenceId('one'),
|
||||
name: 'One',
|
||||
format: TimelineFormat.fps30,
|
||||
primaryStorylineId: StorylineId('primary'),
|
||||
storylines: [
|
||||
StorylineDto(
|
||||
id: StorylineId('primary'),
|
||||
elementIds: [ElementId('clip'), ElementId('other')],
|
||||
),
|
||||
],
|
||||
elements: [
|
||||
for (final id in ['clip', 'other'])
|
||||
ElementDto(
|
||||
id: ElementId(id),
|
||||
name: id,
|
||||
structure: ElementStructure.content,
|
||||
payloadRef: PayloadRef('source'),
|
||||
duration: RationalTime.seconds(5),
|
||||
sourceRange: TimeRange(
|
||||
start: RationalTime.zero,
|
||||
duration: RationalTime.seconds(5),
|
||||
),
|
||||
mediaRange: TimeRange(
|
||||
start: RationalTime.zero,
|
||||
duration: RationalTime.seconds(5),
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
|
||||
class _BlockedPreview extends PreviewController {
|
||||
_BlockedPreview(EditorTimelineSession session)
|
||||
: super(
|
||||
timeline: session,
|
||||
runtime: CutdexRuntime(),
|
||||
activeSequence: () => session.activeSequenceId,
|
||||
viewForSequence: session.view,
|
||||
);
|
||||
final pause = Completer<void>();
|
||||
|
||||
@override
|
||||
Future<void> pauseForCanvasInteraction() => pause.future;
|
||||
}
|
||||
@@ -0,0 +1,173 @@
|
||||
import 'package:cutdex/features/media/resource_navigation.dart';
|
||||
import 'package:cutdex/l10n/app_localizations.dart';
|
||||
import 'package:cutdex_ui/theme.dart';
|
||||
import 'package:cutdex_ui/widgets.dart';
|
||||
import 'package:flutter/gestures.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
|
||||
void main() {
|
||||
Future<void> mount(
|
||||
WidgetTester tester, {
|
||||
double width = 240,
|
||||
double scale = 1,
|
||||
Locale locale = const Locale('zh'),
|
||||
AppPalette palette = AppPalette.graphite,
|
||||
Brightness brightness = Brightness.dark,
|
||||
}) async {
|
||||
var selected = ResourceSection.imported;
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(
|
||||
theme: AppTheme.desktopWorkspaceTheme(
|
||||
AppTheme.forPalette(palette, brightness),
|
||||
),
|
||||
locale: locale,
|
||||
localizationsDelegates: AppLocalizations.localizationsDelegates,
|
||||
supportedLocales: AppLocalizations.supportedLocales,
|
||||
home: Scaffold(
|
||||
body: Align(
|
||||
alignment: Alignment.topLeft,
|
||||
child: SizedBox(
|
||||
width: width,
|
||||
child: MediaQuery(
|
||||
data: MediaQueryData(textScaler: TextScaler.linear(scale)),
|
||||
child: StatefulBuilder(
|
||||
builder: (context, setState) => ResourceSectionTabs(
|
||||
selected: selected,
|
||||
onSelected: (value) => setState(() => selected = value),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
}
|
||||
|
||||
testWidgets('translated tabs fit scaled text in all desktop palettes', (
|
||||
tester,
|
||||
) async {
|
||||
for (final palette in AppPalette.values) {
|
||||
for (final brightness in Brightness.values) {
|
||||
for (final locale in [
|
||||
const Locale('zh'),
|
||||
const Locale('en'),
|
||||
const Locale('de'),
|
||||
const Locale('ru'),
|
||||
]) {
|
||||
for (final width in [120.0, 240.0, 400.0, 640.0]) {
|
||||
await mount(
|
||||
tester,
|
||||
width: width,
|
||||
scale: 1.3,
|
||||
locale: locale,
|
||||
palette: palette,
|
||||
brightness: brightness,
|
||||
);
|
||||
expect(
|
||||
tester.takeException(),
|
||||
isNull,
|
||||
reason: '$palette $brightness $locale $width',
|
||||
);
|
||||
expect(
|
||||
tester
|
||||
.getSize(find.byKey(const Key('resource-section-tabs')))
|
||||
.height,
|
||||
36,
|
||||
);
|
||||
final header = tester.getRect(
|
||||
find.byKey(const Key('resource-section-tabs')),
|
||||
);
|
||||
for (final button in find.byType(TextButton).evaluate()) {
|
||||
final bounds = tester.getRect(find.byWidget(button.widget));
|
||||
expect(bounds.top, greaterThanOrEqualTo(header.top));
|
||||
expect(bounds.bottom, lessThanOrEqualTo(header.bottom));
|
||||
expect(bounds.height, AppDesktopMetrics.timelineTabControl);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
testWidgets(
|
||||
'narrow tabs scroll with wheel and drag through the shared edge fade',
|
||||
(tester) async {
|
||||
await mount(tester, width: 160);
|
||||
final list = find.byKey(const Key('resource-tabs-list'));
|
||||
final scroll = tester.widget<SingleChildScrollView>(list);
|
||||
final fade = tester.widget<ScrollEdgeFade>(find.byType(ScrollEdgeFade));
|
||||
expect(fade.axis, Axis.horizontal);
|
||||
expect(fade.controller, same(scroll.controller));
|
||||
final position = scroll.controller!.position;
|
||||
expect(position.pixels, 0);
|
||||
expect(position.extentAfter, greaterThan(0));
|
||||
expect(find.byKey(const Key('resource-tabs-more')), findsNothing);
|
||||
for (final section in ResourceSection.values) {
|
||||
expect(
|
||||
find.byKey(ValueKey('resource-tab-${section.name}')),
|
||||
findsOneWidget,
|
||||
);
|
||||
}
|
||||
await tester.sendEventToBinding(
|
||||
PointerScrollEvent(
|
||||
position: tester.getCenter(list),
|
||||
scrollDelta: const Offset(0, 70),
|
||||
),
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
expect(position.pixels, 70);
|
||||
expect(position.extentBefore, greaterThan(0));
|
||||
expect(position.extentAfter, greaterThan(0));
|
||||
await tester.drag(list, const Offset(-600, 0));
|
||||
await tester.pumpAndSettle();
|
||||
expect(position.pixels, position.maxScrollExtent);
|
||||
await tester.tap(find.byKey(const ValueKey('resource-tab-transitions')));
|
||||
await tester.pumpAndSettle();
|
||||
expect(
|
||||
tester
|
||||
.widget<ResourceSectionTabs>(find.byType(ResourceSectionTabs))
|
||||
.selected,
|
||||
ResourceSection.transitions,
|
||||
);
|
||||
tester
|
||||
.widget<ResourceSectionTabs>(find.byType(ResourceSectionTabs))
|
||||
.onSelected!(ResourceSection.imported);
|
||||
await tester.pumpAndSettle();
|
||||
expect(position.pixels, 0);
|
||||
expect(tester.takeException(), isNull);
|
||||
},
|
||||
);
|
||||
|
||||
testWidgets('a programmatically selected tab scrolls into view', (
|
||||
tester,
|
||||
) async {
|
||||
await mount(tester, width: 160);
|
||||
tester
|
||||
.widget<ResourceSectionTabs>(find.byType(ResourceSectionTabs))
|
||||
.onSelected!(ResourceSection.transitions);
|
||||
await tester.pumpAndSettle();
|
||||
final viewport = tester.getRect(
|
||||
find.byKey(const Key('resource-tabs-list')),
|
||||
);
|
||||
final selected = tester.getRect(
|
||||
find.byKey(const ValueKey('resource-tab-transitions')),
|
||||
);
|
||||
expect(selected.left, greaterThanOrEqualTo(viewport.left));
|
||||
expect(selected.right, lessThanOrEqualTo(viewport.right));
|
||||
expect(tester.takeException(), isNull);
|
||||
});
|
||||
|
||||
testWidgets('wide panel exposes every category directly', (tester) async {
|
||||
await mount(tester, width: 640);
|
||||
for (final section in ResourceSection.values) {
|
||||
expect(
|
||||
find.byKey(ValueKey('resource-tab-${section.name}')),
|
||||
findsOneWidget,
|
||||
);
|
||||
}
|
||||
expect(find.byKey(const Key('resource-tabs-more')), findsNothing);
|
||||
});
|
||||
}
|
||||
@@ -2,11 +2,47 @@ import 'dart:async';
|
||||
|
||||
import 'package:cutdex/features/settings/appearance_settings.dart';
|
||||
import 'package:cutdex/features/settings/language_settings.dart';
|
||||
import 'package:cutdex/features/settings/timeline_ruler_settings.dart';
|
||||
import 'package:cutdex/persistence/app_settings_repositories.dart';
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
|
||||
void main() {
|
||||
_testSettings<TimelineRulerTimecodeLayout>(
|
||||
name: 'timeline ruler',
|
||||
initial: TimelineRulerTimecodeLayout.inline,
|
||||
first: TimelineRulerTimecodeLayout.centered,
|
||||
second: TimelineRulerTimecodeLayout.overlay,
|
||||
container: (store) => ProviderContainer(
|
||||
overrides: [
|
||||
timelineRulerSettingsRepositoryProvider.overrideWithValue(
|
||||
_TimelineRulerRepository(store),
|
||||
),
|
||||
],
|
||||
),
|
||||
load: (container) => container.read(timelineRulerSettingsProvider.future),
|
||||
value: (container) =>
|
||||
container.read(timelineRulerSettingsProvider).requireValue,
|
||||
save: (container, value) =>
|
||||
container.read(timelineRulerSettingsProvider.notifier).setLayout(value),
|
||||
);
|
||||
_testSettings<AppPalette>(
|
||||
name: 'palette',
|
||||
initial: AppPalette.graphite,
|
||||
first: AppPalette.violet,
|
||||
second: AppPalette.teal,
|
||||
container: (store) => ProviderContainer(
|
||||
overrides: [
|
||||
paletteSettingsRepositoryProvider.overrideWithValue(
|
||||
_PaletteRepository(store),
|
||||
),
|
||||
],
|
||||
),
|
||||
load: (container) => container.read(paletteSettingsProvider.future),
|
||||
value: (container) => container.read(paletteSettingsProvider).requireValue,
|
||||
save: (container, value) =>
|
||||
container.read(paletteSettingsProvider.notifier).setPalette(value),
|
||||
);
|
||||
_testSettings<AppAppearance>(
|
||||
name: 'appearance',
|
||||
initial: AppAppearance.system,
|
||||
@@ -141,6 +177,28 @@ class _Store<T> {
|
||||
}
|
||||
}
|
||||
|
||||
class _TimelineRulerRepository implements TimelineRulerSettingsRepository {
|
||||
_TimelineRulerRepository(this.store);
|
||||
final _Store<TimelineRulerTimecodeLayout> store;
|
||||
|
||||
@override
|
||||
Future<TimelineRulerTimecodeLayout> load() => store.load();
|
||||
|
||||
@override
|
||||
Future<void> save(TimelineRulerTimecodeLayout layout) => store.save(layout);
|
||||
}
|
||||
|
||||
class _PaletteRepository implements PaletteSettingsRepository {
|
||||
_PaletteRepository(this.store);
|
||||
final _Store<AppPalette> store;
|
||||
|
||||
@override
|
||||
Future<AppPalette> load() => store.load();
|
||||
|
||||
@override
|
||||
Future<void> save(AppPalette palette) => store.save(palette);
|
||||
}
|
||||
|
||||
class _AppearanceRepository implements AppearanceSettingsRepository {
|
||||
_AppearanceRepository(this.store);
|
||||
final _Store<AppAppearance> store;
|
||||
|
||||
@@ -0,0 +1,78 @@
|
||||
import 'package:cutdex/features/projects/sidebar_category_tabs.dart';
|
||||
import 'package:cutdex/l10n/app_localizations.dart';
|
||||
import 'package:cutdex_ui/theme.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
|
||||
void main() {
|
||||
testWidgets('sidebar categories fit themes, narrow widths and large text', (
|
||||
tester,
|
||||
) async {
|
||||
for (final palette in AppPalette.values) {
|
||||
for (final brightness in Brightness.values) {
|
||||
for (final locale in const [Locale('zh'), Locale('en'), Locale('de')]) {
|
||||
for (final width in [120.0, 180.0, 280.0]) {
|
||||
var media = false;
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(
|
||||
theme: AppTheme.desktopWorkspaceTheme(
|
||||
AppTheme.forPalette(palette, brightness),
|
||||
),
|
||||
locale: locale,
|
||||
localizationsDelegates: AppLocalizations.localizationsDelegates,
|
||||
supportedLocales: AppLocalizations.supportedLocales,
|
||||
home: Scaffold(
|
||||
body: Align(
|
||||
alignment: Alignment.topLeft,
|
||||
child: SizedBox(
|
||||
width: width,
|
||||
child: MediaQuery(
|
||||
data: const MediaQueryData(
|
||||
textScaler: TextScaler.linear(2),
|
||||
),
|
||||
child: StatefulBuilder(
|
||||
builder: (context, setState) => SidebarCategoryTabs(
|
||||
mediaSelected: media,
|
||||
onSelected: (value) =>
|
||||
setState(() => media = value),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
final header = tester.getRect(
|
||||
find.byKey(const Key('sidebar-category-header')),
|
||||
);
|
||||
final chat = tester.getRect(
|
||||
find.byKey(const Key('sidebar-tab-chat')),
|
||||
);
|
||||
final resources = tester.getRect(
|
||||
find.byKey(const Key('sidebar-tab-resources')),
|
||||
);
|
||||
expect(header.height, 36);
|
||||
expect(chat.height, 28);
|
||||
expect(resources.height, 28);
|
||||
expect(chat.left - header.left, 12);
|
||||
expect(header.right - resources.right, 12);
|
||||
expect(resources.left - chat.right, 4);
|
||||
await tester.tap(find.byKey(const Key('sidebar-tab-resources')));
|
||||
await tester.pump();
|
||||
expect(media, isTrue);
|
||||
await tester.tap(find.byKey(const Key('sidebar-tab-chat')));
|
||||
await tester.pump();
|
||||
expect(media, isFalse);
|
||||
expect(
|
||||
tester.takeException(),
|
||||
isNull,
|
||||
reason: '$palette $brightness $locale width=$width',
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -1,4 +1,5 @@
|
||||
import 'package:cutdex/persistence/app_settings_repositories.dart';
|
||||
import 'package:cutdex_sdk/timeline_ui.dart' show TimelineRulerTimecodeLayout;
|
||||
import 'package:cutdex/workspace/project_state.dart';
|
||||
import 'package:cutdex/workspace/persistence/recent_projects.dart';
|
||||
|
||||
@@ -57,6 +58,35 @@ class MemoryAppearanceSettingsRepository
|
||||
}
|
||||
}
|
||||
|
||||
class MemoryPaletteSettingsRepository implements PaletteSettingsRepository {
|
||||
AppPalette value = AppPalette.graphite;
|
||||
bool failWrites = false;
|
||||
|
||||
@override
|
||||
Future<AppPalette> load() async => value;
|
||||
|
||||
@override
|
||||
Future<void> save(AppPalette palette) async {
|
||||
if (failWrites) throw StateError('write failed');
|
||||
value = palette;
|
||||
}
|
||||
}
|
||||
|
||||
class MemoryTimelineRulerSettingsRepository
|
||||
implements TimelineRulerSettingsRepository {
|
||||
TimelineRulerTimecodeLayout value = TimelineRulerTimecodeLayout.inline;
|
||||
bool failWrites = false;
|
||||
|
||||
@override
|
||||
Future<TimelineRulerTimecodeLayout> load() async => value;
|
||||
|
||||
@override
|
||||
Future<void> save(TimelineRulerTimecodeLayout layout) async {
|
||||
if (failWrites) throw StateError('write failed');
|
||||
value = layout;
|
||||
}
|
||||
}
|
||||
|
||||
class MemoryRecentProjectsRepository implements RecentProjectsRepository {
|
||||
List<RecentProject> recent = [];
|
||||
final projects = <String, String>{};
|
||||
|
||||
@@ -0,0 +1,295 @@
|
||||
import 'dart:async';
|
||||
|
||||
import 'package:cutdex/app/app.dart';
|
||||
import 'package:cutdex/features/editor/editor_panel_defaults.dart';
|
||||
import 'package:cutdex/features/editor/editor_page.dart';
|
||||
import 'package:cutdex/features/projects/projects_page.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/persistence/recent_projects.dart';
|
||||
import 'package:cutdex/workspace/projects.dart';
|
||||
import 'package:cutdex/workspace/view_settings.dart';
|
||||
import 'package:cutdex/workspace/workspace_mode.dart';
|
||||
import 'package:cutdex/workspace/workspace_navigation.dart';
|
||||
import 'package:drift/native.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
|
||||
import 'support/empty_conversation_repository.dart';
|
||||
import 'support/memory_app_settings.dart';
|
||||
import 'support/preview_fixture.dart';
|
||||
|
||||
void main() {
|
||||
testWidgets(
|
||||
'real timeline creation retains panels on every published frame',
|
||||
(tester) async {
|
||||
tester.view.physicalSize = const Size(1800, 900);
|
||||
tester.view.devicePixelRatio = 1;
|
||||
tester.platformDispatcher.localesTestValue = const [Locale('zh')];
|
||||
addTearDown(tester.platformDispatcher.clearLocalesTestValue);
|
||||
addTearDown(tester.view.resetPhysicalSize);
|
||||
addTearDown(tester.view.resetDevicePixelRatio);
|
||||
final fixture = (await tester.runAsync(
|
||||
() => createPreviewFixture(
|
||||
Uri.file('/test/image.png'),
|
||||
mediaType: 'image',
|
||||
),
|
||||
))!;
|
||||
await tester.runAsync(fixture.workspace.close);
|
||||
final views = _CreationViews();
|
||||
final database = AppDatabase(NativeDatabase.memory());
|
||||
final container = ProviderContainer(
|
||||
overrides: [
|
||||
deviceExperienceProvider.overrideWithValue(DeviceExperience.desktop),
|
||||
appDatabaseProvider.overrideWithValue(database),
|
||||
recentProjectsProvider.overrideWithValue(
|
||||
MemoryRecentProjectsRepository(),
|
||||
),
|
||||
resourceLocationSettingsRepositoryProvider.overrideWithValue(
|
||||
MemoryResourceLocationSettingsRepository(fixture.directory.path),
|
||||
),
|
||||
timelineViewSettingsRepositoryProvider.overrideWithValue(views),
|
||||
appearanceSettingsRepositoryProvider.overrideWithValue(
|
||||
MemoryAppearanceSettingsRepository(),
|
||||
),
|
||||
paletteSettingsRepositoryProvider.overrideWithValue(
|
||||
MemoryPaletteSettingsRepository(),
|
||||
),
|
||||
conversationRepositoryProvider.overrideWith(
|
||||
(ref) async => EmptyConversationRepository(),
|
||||
),
|
||||
editorPreviewProvider.overrideWith((ref, ids) => null),
|
||||
],
|
||||
);
|
||||
final projects = (await tester.runAsync(() async {
|
||||
final projects = container.read(projectsProvider.notifier);
|
||||
await container.read(projectsProvider.future);
|
||||
return projects;
|
||||
}))!;
|
||||
addTearDown(() async {
|
||||
if (!views.gate.isCompleted) {
|
||||
views.gate.complete(const TimelineViewState());
|
||||
}
|
||||
await tester.pumpWidget(const SizedBox());
|
||||
for (var frame = 0; frame < 5; frame++) {
|
||||
await tester.pump(const Duration(milliseconds: 200));
|
||||
await tester.runAsync(
|
||||
() => Future<void>.delayed(const Duration(milliseconds: 10)),
|
||||
);
|
||||
}
|
||||
var closed = false;
|
||||
late Future<bool> closing;
|
||||
await tester.runAsync(() async {
|
||||
closing = projects.prepareToQuit();
|
||||
unawaited(closing.whenComplete(() => closed = true));
|
||||
});
|
||||
for (var frame = 0; frame < 500 && !closed; frame++) {
|
||||
await tester.pump(const Duration(milliseconds: 10));
|
||||
await tester.runAsync(
|
||||
() => Future<void>.delayed(const Duration(milliseconds: 10)),
|
||||
);
|
||||
}
|
||||
expect(closed, isTrue);
|
||||
await tester.runAsync(() async {
|
||||
await closing;
|
||||
container.dispose();
|
||||
await database.close();
|
||||
await fixture.directory.delete(recursive: true);
|
||||
});
|
||||
});
|
||||
await tester.runAsync(() async {
|
||||
expect(
|
||||
await projects.open(
|
||||
'${fixture.directory.path}/Preview.cutdex',
|
||||
timelineId: 'project',
|
||||
),
|
||||
isTrue,
|
||||
);
|
||||
await container.read(workspaceViewSettingsProvider.future);
|
||||
container
|
||||
.read(workspaceViewSettingsProvider.notifier)
|
||||
.setMode(WorkspaceMode.cut);
|
||||
await container.read(
|
||||
projectViewSettingsProvider(
|
||||
container.read(projectsProvider).requireValue.activeProject!.id,
|
||||
).future,
|
||||
);
|
||||
container.read(workspaceNavigationProvider);
|
||||
while (!container.read(workspaceNavigationProvider).ready) {
|
||||
await Future<void>.delayed(const Duration(milliseconds: 5));
|
||||
}
|
||||
});
|
||||
await tester.pumpWidget(
|
||||
UncontrolledProviderScope(
|
||||
container: container,
|
||||
child: const CutdexApp(),
|
||||
),
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
await tester.tap(find.byKey(const Key('editor-properties-button')));
|
||||
await tester.pumpAndSettle();
|
||||
final properties = tester.element(find.byType(ProjectProperties));
|
||||
final label = tester.element(find.text('画布尺寸'));
|
||||
final value = tester.element(find.text('1080 × 1920 px'));
|
||||
final preview = tester.element(find.byType(EditorPreviewPanel));
|
||||
final timeline = tester.element(
|
||||
find.byKey(const Key('editor-timeline-surface')),
|
||||
);
|
||||
final bounds = tester.getRect(find.byType(ProjectProperties));
|
||||
final previewBounds = tester.getRect(find.byType(EditorPreviewPanel));
|
||||
final timelineBounds = tester.getRect(
|
||||
find.byKey(const Key('editor-timeline-surface')),
|
||||
);
|
||||
final initialCount = container
|
||||
.read(projectsProvider)
|
||||
.requireValue
|
||||
.timelines
|
||||
.length;
|
||||
final initial = container
|
||||
.read(projectsProvider)
|
||||
.requireValue
|
||||
.timeline!
|
||||
.id;
|
||||
|
||||
void stable() {
|
||||
expect(find.byKey(const Key('properties-pending')), findsNothing);
|
||||
expect(find.byKey(const Key('timeline-default-tracks')), findsNothing);
|
||||
expect(find.byType(EditorEmptyPanel), findsNothing);
|
||||
expect(
|
||||
tester.element(find.byType(ProjectProperties)),
|
||||
same(properties),
|
||||
);
|
||||
expect(tester.element(find.text('画布尺寸')), same(label));
|
||||
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)), bounds);
|
||||
expect(tester.getRect(find.byType(EditorPreviewPanel)), previewBounds);
|
||||
expect(
|
||||
tester.getRect(find.byKey(const Key('editor-timeline-surface'))),
|
||||
timelineBounds,
|
||||
);
|
||||
expect(tester.takeException(), isNull);
|
||||
}
|
||||
|
||||
var windowBuilds = 0;
|
||||
var workspaceBuilds = 0;
|
||||
var previewBuilds = 0;
|
||||
var labelBuilds = 0;
|
||||
final previousBuild = debugOnRebuildDirtyWidget;
|
||||
debugOnRebuildDirtyWidget = (element, built) {
|
||||
previousBuild?.call(element, built);
|
||||
if (element.widget is EditingPage) windowBuilds++;
|
||||
if (element.widget is EditorWorkspace) workspaceBuilds++;
|
||||
if (element.widget is EditorPreviewPanel) previewBuilds++;
|
||||
if (identical(element, label)) labelBuilds++;
|
||||
};
|
||||
addTearDown(() => debugOnRebuildDirtyWidget = previousBuild);
|
||||
|
||||
Future<void> advanceUntil(
|
||||
bool Function() complete, {
|
||||
VoidCallback? onFrame,
|
||||
}) async {
|
||||
for (var attempt = 0; attempt < 500 && !complete(); attempt++) {
|
||||
await tester.pump(const Duration(milliseconds: 10));
|
||||
onFrame?.call();
|
||||
await tester.runAsync(
|
||||
() => Future<void>.delayed(const Duration(milliseconds: 10)),
|
||||
);
|
||||
}
|
||||
expect(complete(), isTrue, reason: 'Real filesystem work completes');
|
||||
await tester.pump();
|
||||
onFrame?.call();
|
||||
}
|
||||
|
||||
views.blockCreation = true;
|
||||
await tester.tap(find.byKey(const Key('timeline-add-button')));
|
||||
await advanceUntil(() => views.started.isCompleted);
|
||||
for (var frame = 0; frame < 5; frame++) {
|
||||
await tester.pump(const Duration(milliseconds: 100));
|
||||
stable();
|
||||
final state = container.read(projectsProvider).requireValue;
|
||||
expect(state.creatingTimeline, isTrue);
|
||||
expect(state.timeline!.id, initial);
|
||||
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);
|
||||
stable();
|
||||
expect(windowBuilds, 0, reason: 'Creation progress is local to controls');
|
||||
expect(workspaceBuilds, 0);
|
||||
expect(previewBuilds, 0);
|
||||
expect(labelBuilds, 0);
|
||||
views.gate.complete(const TimelineViewState());
|
||||
await advanceUntil(
|
||||
() => !container.read(projectsProvider).requireValue.creatingTimeline,
|
||||
onFrame: () {
|
||||
stable();
|
||||
if (container.read(projectsProvider).requireValue.timeline!.id !=
|
||||
initial) {
|
||||
expect(find.text('1920 × 1080 px'), findsOneWidget);
|
||||
expect(tester.element(find.text('1920 × 1080 px')), same(value));
|
||||
}
|
||||
},
|
||||
);
|
||||
// Verify the first committed frame as well as subsequent settling frames.
|
||||
for (var frame = 0; frame < 5; frame++) {
|
||||
await tester.pump(const Duration(milliseconds: 16));
|
||||
stable();
|
||||
expect(find.text('1920 × 1080 px'), findsOneWidget);
|
||||
expect(tester.element(find.text('1920 × 1080 px')), same(value));
|
||||
}
|
||||
expect(
|
||||
container.read(projectsProvider).requireValue.timeline!.id,
|
||||
isNot(initial),
|
||||
);
|
||||
expect(
|
||||
container.read(projectsProvider).requireValue.creatingTimeline,
|
||||
isFalse,
|
||||
);
|
||||
expect(
|
||||
container.read(projectsProvider).requireValue.timelines,
|
||||
hasLength(initialCount + 1),
|
||||
);
|
||||
await tester.tap(find.byKey(const ValueKey('project-settings-edit')));
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.byKey(const ValueKey('project-width')), findsOneWidget);
|
||||
await tester.pumpWidget(const SizedBox());
|
||||
// Dispose view bindings and drain their debounce in the fake clock.
|
||||
await tester.pump(const Duration(seconds: 1));
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
class _CreationViews implements TimelineViewSettingsRepository {
|
||||
bool blockCreation = false;
|
||||
final started = Completer<void>();
|
||||
final gate = Completer<TimelineViewState>();
|
||||
@override
|
||||
Future<TimelineViewState> load(String projectId, String timelineId) {
|
||||
if (blockCreation) {
|
||||
if (!started.isCompleted) started.complete();
|
||||
return gate.future;
|
||||
}
|
||||
return Future.value(const TimelineViewState());
|
||||
}
|
||||
|
||||
@override
|
||||
Future<void> save(
|
||||
String projectId,
|
||||
String timelineId,
|
||||
Object sequenceId,
|
||||
TimelineSequenceViewState value,
|
||||
) async {}
|
||||
}
|
||||
@@ -0,0 +1,65 @@
|
||||
import 'package:cutdex/features/timeline/timeline_ruler_previews.dart';
|
||||
import 'package:cutdex_sdk/timeline_ui.dart';
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
|
||||
void main() {
|
||||
for (final (layout, light, dark, frames) in [
|
||||
(
|
||||
TimelineRulerTimecodeLayout.inline,
|
||||
timecodeRulerLightPreview,
|
||||
timecodeRulerDarkPreview,
|
||||
timecodeRulerFramePreview,
|
||||
),
|
||||
(
|
||||
TimelineRulerTimecodeLayout.centered,
|
||||
centeredTimecodeRulerLightPreview,
|
||||
centeredTimecodeRulerDarkPreview,
|
||||
centeredTimecodeRulerFramePreview,
|
||||
),
|
||||
(
|
||||
TimelineRulerTimecodeLayout.overlay,
|
||||
overlayTimecodeRulerLightPreview,
|
||||
overlayTimecodeRulerDarkPreview,
|
||||
overlayTimecodeRulerFramePreview,
|
||||
),
|
||||
]) {
|
||||
testWidgets('${layout.name} previews render and zoom at both widths', (
|
||||
tester,
|
||||
) async {
|
||||
debugDefaultTargetPlatformOverride = TargetPlatform.macOS;
|
||||
try {
|
||||
tester.view.devicePixelRatio = 1;
|
||||
addTearDown(tester.view.resetDevicePixelRatio);
|
||||
addTearDown(tester.view.resetPhysicalSize);
|
||||
for (final (width, factory) in [
|
||||
(640.0, light),
|
||||
(640.0, dark),
|
||||
(640.0, frames),
|
||||
(320.0, dark),
|
||||
]) {
|
||||
// Remount to give each configuration its own camera state.
|
||||
await tester.pumpWidget(const SizedBox.shrink());
|
||||
tester.view.physicalSize = Size(width, 152);
|
||||
await tester.pumpWidget(factory());
|
||||
await tester.pump();
|
||||
final ruler = tester.widget<TimelineRuler>(
|
||||
find.byType(TimelineRuler),
|
||||
);
|
||||
expect(ruler.style, TimelineRulerStyle.timecode);
|
||||
expect(ruler.timecodeLayout, layout);
|
||||
expect(tester.takeException(), isNull);
|
||||
final before = ruler.controller.camera.pixelsPerTick;
|
||||
await tester.tap(find.byTooltip('Zoom in'));
|
||||
await tester.pump();
|
||||
expect(ruler.controller.camera.pixelsPerTick, greaterThan(before));
|
||||
expect(tester.takeException(), isNull);
|
||||
}
|
||||
await tester.pumpWidget(const SizedBox.shrink());
|
||||
} finally {
|
||||
debugDefaultTargetPlatformOverride = null;
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,140 @@
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:cutdex/features/settings/timeline_ruler_settings.dart';
|
||||
import 'package:cutdex/persistence/app_database.dart';
|
||||
import 'package:cutdex/persistence/app_settings_repositories.dart';
|
||||
import 'package:drift/native.dart';
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:sqlite3/sqlite3.dart';
|
||||
|
||||
import 'support/memory_app_settings.dart';
|
||||
|
||||
void main() {
|
||||
test(
|
||||
'layout survives provider recreation and failed saves retain selection',
|
||||
() async {
|
||||
final repository = MemoryTimelineRulerSettingsRepository();
|
||||
ProviderContainer container() => ProviderContainer(
|
||||
overrides: [
|
||||
timelineRulerSettingsRepositoryProvider.overrideWithValue(repository),
|
||||
],
|
||||
);
|
||||
final first = container();
|
||||
addTearDown(first.dispose);
|
||||
expect(
|
||||
await first.read(timelineRulerSettingsProvider.future),
|
||||
TimelineRulerTimecodeLayout.inline,
|
||||
);
|
||||
await first
|
||||
.read(timelineRulerSettingsProvider.notifier)
|
||||
.setLayout(TimelineRulerTimecodeLayout.centered);
|
||||
final restored = container();
|
||||
addTearDown(restored.dispose);
|
||||
expect(
|
||||
await restored.read(timelineRulerSettingsProvider.future),
|
||||
TimelineRulerTimecodeLayout.centered,
|
||||
);
|
||||
repository.failWrites = true;
|
||||
await expectLater(
|
||||
restored
|
||||
.read(timelineRulerSettingsProvider.notifier)
|
||||
.setLayout(TimelineRulerTimecodeLayout.overlay),
|
||||
throwsStateError,
|
||||
);
|
||||
expect(
|
||||
restored.read(timelineRulerSettingsProvider).requireValue,
|
||||
TimelineRulerTimecodeLayout.centered,
|
||||
);
|
||||
repository.failWrites = false;
|
||||
await restored
|
||||
.read(timelineRulerSettingsProvider.notifier)
|
||||
.setLayout(TimelineRulerTimecodeLayout.overlay);
|
||||
expect(repository.value, TimelineRulerTimecodeLayout.overlay);
|
||||
},
|
||||
);
|
||||
|
||||
test('ruler, palette and appearance writes preserve each other', () async {
|
||||
final db = AppDatabase(NativeDatabase.memory());
|
||||
addTearDown(db.close);
|
||||
final ruler = DriftTimelineRulerSettingsRepository(db);
|
||||
final palette = DriftPaletteSettingsRepository(db);
|
||||
final appearance = DriftAppearanceSettingsRepository(db);
|
||||
expect(await ruler.load(), TimelineRulerTimecodeLayout.inline);
|
||||
await palette.save(AppPalette.teal);
|
||||
await appearance.save(AppAppearance.penDark);
|
||||
for (final layout in TimelineRulerTimecodeLayout.values) {
|
||||
await ruler.save(layout);
|
||||
expect(await ruler.load(), layout);
|
||||
expect(await palette.load(), AppPalette.teal);
|
||||
expect(await appearance.load(), AppAppearance.penDark);
|
||||
}
|
||||
await Future.wait([
|
||||
palette.save(AppPalette.violet),
|
||||
appearance.save(AppAppearance.penLight),
|
||||
ruler.save(TimelineRulerTimecodeLayout.centered),
|
||||
]);
|
||||
expect(await ruler.load(), TimelineRulerTimecodeLayout.centered);
|
||||
expect(await palette.load(), AppPalette.violet);
|
||||
expect(await appearance.load(), AppAppearance.penLight);
|
||||
await db.customStatement(
|
||||
"UPDATE appearance_configurations SET timeline_ruler_layout = 'unknown'",
|
||||
);
|
||||
expect(await ruler.load(), TimelineRulerTimecodeLayout.inline);
|
||||
});
|
||||
|
||||
for (final schema in [2, 3]) {
|
||||
test(
|
||||
'schema $schema upgrades and ruler style survives reopening',
|
||||
() async {
|
||||
final directory = await Directory.systemTemp.createTemp(
|
||||
'cutdex-ruler-settings-',
|
||||
);
|
||||
addTearDown(() => directory.delete(recursive: true));
|
||||
final file = File('${directory.path}/app.sqlite');
|
||||
final initial = AppDatabase(NativeDatabase(file));
|
||||
await DriftAppearanceSettingsRepository(initial)
|
||||
.save(AppAppearance.penDark);
|
||||
await DriftPaletteSettingsRepository(initial).save(AppPalette.teal);
|
||||
await initial.close();
|
||||
final old = sqlite3.open(file.path);
|
||||
try {
|
||||
old.execute(
|
||||
'ALTER TABLE appearance_configurations DROP COLUMN timeline_ruler_layout',
|
||||
);
|
||||
if (schema == 2) {
|
||||
old.execute(
|
||||
'ALTER TABLE appearance_configurations DROP COLUMN palette',
|
||||
);
|
||||
}
|
||||
old.userVersion = schema;
|
||||
} finally {
|
||||
old.close();
|
||||
}
|
||||
final upgraded = AppDatabase(NativeDatabase(file));
|
||||
expect(
|
||||
await DriftAppearanceSettingsRepository(upgraded).load(),
|
||||
AppAppearance.penDark,
|
||||
);
|
||||
expect(
|
||||
await DriftPaletteSettingsRepository(upgraded).load(),
|
||||
schema == 2 ? AppPalette.graphite : AppPalette.teal,
|
||||
);
|
||||
final ruler = DriftTimelineRulerSettingsRepository(upgraded);
|
||||
expect(await ruler.load(), TimelineRulerTimecodeLayout.inline);
|
||||
await ruler.save(TimelineRulerTimecodeLayout.overlay);
|
||||
await upgraded.close();
|
||||
final reopened = AppDatabase(NativeDatabase(file));
|
||||
addTearDown(reopened.close);
|
||||
expect(
|
||||
await DriftTimelineRulerSettingsRepository(reopened).load(),
|
||||
TimelineRulerTimecodeLayout.overlay,
|
||||
);
|
||||
expect(
|
||||
await DriftAppearanceSettingsRepository(reopened).load(),
|
||||
AppAppearance.penDark,
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,253 @@
|
||||
import 'package:cutdex/app/editor_theme.dart';
|
||||
import 'package:cutdex/features/settings/settings_content.dart';
|
||||
import 'package:cutdex/features/settings/timeline_ruler_settings.dart';
|
||||
import 'package:cutdex/features/settings/timeline_ruler_settings_field.dart';
|
||||
import 'package:cutdex/features/timeline/editor_timeline_viewport.dart';
|
||||
import 'package:cutdex/integrations/agent/conversation_repository.dart';
|
||||
import 'package:cutdex/l10n/app_localizations.dart';
|
||||
import 'package:cutdex/persistence/app_database.dart';
|
||||
import 'package:cutdex/persistence/app_settings_repositories.dart';
|
||||
import 'package:cutdex_sdk/timeline/engine.dart';
|
||||
import 'package:cutdex_sdk/timeline/layout.dart';
|
||||
import 'package:cutdex_sdk/timeline/model.dart';
|
||||
import 'package:cutdex_sdk/timeline_ui.dart';
|
||||
import 'package:cutdex_ui/widgets.dart';
|
||||
import 'package:drift/native.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
|
||||
import 'support/empty_conversation_repository.dart';
|
||||
import 'support/memory_app_settings.dart';
|
||||
|
||||
void main() {
|
||||
testWidgets(
|
||||
'appearance settings switch the live ruler and retain its camera',
|
||||
(tester) async {
|
||||
tester.view.physicalSize = const Size(1200, 900);
|
||||
tester.view.devicePixelRatio = 1;
|
||||
addTearDown(tester.view.resetPhysicalSize);
|
||||
addTearDown(tester.view.resetDevicePixelRatio);
|
||||
final database = AppDatabase(NativeDatabase.memory());
|
||||
addTearDown(database.close);
|
||||
final repository = MemoryTimelineRulerSettingsRepository();
|
||||
final scope = ProviderContainer(
|
||||
overrides: [
|
||||
appDatabaseProvider.overrideWithValue(database),
|
||||
timelineRulerSettingsRepositoryProvider.overrideWithValue(repository),
|
||||
conversationRepositoryProvider.overrideWith(
|
||||
(ref) async => EmptyConversationRepository(),
|
||||
),
|
||||
],
|
||||
);
|
||||
addTearDown(scope.dispose);
|
||||
final controller = _controller();
|
||||
addTearDown(controller.dispose);
|
||||
await tester.pumpWidget(
|
||||
UncontrolledProviderScope(
|
||||
container: scope,
|
||||
child: MaterialApp(
|
||||
locale: const Locale('zh'),
|
||||
localizationsDelegates: AppLocalizations.localizationsDelegates,
|
||||
supportedLocales: AppLocalizations.supportedLocales,
|
||||
theme: EditorTheme.desktop(
|
||||
EditorTheme.forPalette(AppPalette.graphite, Brightness.dark),
|
||||
),
|
||||
home: Scaffold(
|
||||
body: Column(
|
||||
children: [
|
||||
const Expanded(child: SettingsContent()),
|
||||
SizedBox(
|
||||
height: 180,
|
||||
child: EditorTimelineViewport(
|
||||
controller: controller,
|
||||
child: TimelineView(
|
||||
key: const Key('retained-timeline'),
|
||||
controller: controller,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
expect(
|
||||
find.byKey(const Key('settings-timeline-ruler-style')),
|
||||
findsNothing,
|
||||
);
|
||||
await tester.tap(find.byKey(const ValueKey('settings-navigation-3')));
|
||||
await tester.pumpAndSettle();
|
||||
final select = find.byKey(const Key('settings-timeline-ruler-style'));
|
||||
expect(select, findsOneWidget);
|
||||
expect(find.text('时间线刻度风格'), findsWidgets);
|
||||
final retained = tester.element(
|
||||
find.byKey(const Key('retained-timeline')),
|
||||
);
|
||||
controller.seekTo(2 * TimelineClock.ticksPerSecond);
|
||||
final camera = (
|
||||
controller.camera.baseTick,
|
||||
controller.camera.fractionalTick,
|
||||
controller.camera.pixelsPerTick,
|
||||
controller.camera.verticalOffset,
|
||||
);
|
||||
final tick = controller.playheadTick;
|
||||
var editing = 0;
|
||||
controller.editingChanges.addListener(() => editing++);
|
||||
Future<void> choose(TimelineRulerTimecodeLayout layout) async {
|
||||
await tester.ensureVisible(select);
|
||||
await tester.tap(select);
|
||||
await tester.pumpAndSettle();
|
||||
final field = tester.widget<AppSelect<TimelineRulerTimecodeLayout>>(
|
||||
select,
|
||||
);
|
||||
final label = field.options.singleWhere((o) => o.value == layout).label;
|
||||
await tester.tap(find.widgetWithText(MenuItemButton, label));
|
||||
await tester.pumpAndSettle();
|
||||
}
|
||||
|
||||
for (final layout in [
|
||||
TimelineRulerTimecodeLayout.centered,
|
||||
TimelineRulerTimecodeLayout.overlay,
|
||||
TimelineRulerTimecodeLayout.inline,
|
||||
]) {
|
||||
await choose(layout);
|
||||
expect(repository.value, layout);
|
||||
expect(
|
||||
tester
|
||||
.widget<TimelineRuler>(find.byType(TimelineRuler))
|
||||
.timecodeLayout,
|
||||
layout,
|
||||
);
|
||||
expect(
|
||||
tester.element(find.byKey(const Key('retained-timeline'))),
|
||||
same(retained),
|
||||
);
|
||||
expect((
|
||||
controller.camera.baseTick,
|
||||
controller.camera.fractionalTick,
|
||||
controller.camera.pixelsPerTick,
|
||||
controller.camera.verticalOffset,
|
||||
), camera);
|
||||
expect(controller.playheadTick, tick);
|
||||
expect(editing, 0);
|
||||
expect(tester.takeException(), isNull);
|
||||
}
|
||||
repository.failWrites = true;
|
||||
await choose(TimelineRulerTimecodeLayout.centered);
|
||||
expect(find.text('无法保存外观设置,请重试'), findsOneWidget);
|
||||
expect(
|
||||
tester.widget<TimelineRuler>(find.byType(TimelineRuler)).timecodeLayout,
|
||||
TimelineRulerTimecodeLayout.inline,
|
||||
);
|
||||
expect(
|
||||
tester.widget<AppSelect<TimelineRulerTimecodeLayout>>(select).value,
|
||||
TimelineRulerTimecodeLayout.inline,
|
||||
);
|
||||
repository.failWrites = false;
|
||||
await choose(TimelineRulerTimecodeLayout.overlay);
|
||||
expect(find.text('无法保存外观设置,请重试'), findsNothing);
|
||||
expect(repository.value, TimelineRulerTimecodeLayout.overlay);
|
||||
await tester.tap(find.byKey(const ValueKey('settings-navigation-0')));
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.byKey(const Key('settings-color-palette')), findsNothing);
|
||||
expect(
|
||||
find.byKey(const Key('settings-timeline-ruler-style')),
|
||||
findsNothing,
|
||||
);
|
||||
await tester.tap(find.byKey(const ValueKey('settings-navigation-3')));
|
||||
await tester.pumpAndSettle();
|
||||
expect(
|
||||
tester.widget<AppSelect<TimelineRulerTimecodeLayout>>(select).value,
|
||||
TimelineRulerTimecodeLayout.overlay,
|
||||
);
|
||||
await tester.pumpWidget(const SizedBox.shrink());
|
||||
},
|
||||
);
|
||||
|
||||
testWidgets(
|
||||
'mobile keeps its elapsed ruler and does not load desktop settings',
|
||||
(tester) async {
|
||||
final scope = ProviderContainer(
|
||||
overrides: [
|
||||
timelineRulerSettingsRepositoryProvider.overrideWith(
|
||||
(ref) => throw StateError('Desktop settings should not be loaded'),
|
||||
),
|
||||
],
|
||||
);
|
||||
addTearDown(scope.dispose);
|
||||
final controller = _controller();
|
||||
addTearDown(controller.dispose);
|
||||
await tester.pumpWidget(
|
||||
UncontrolledProviderScope(
|
||||
container: scope,
|
||||
child: MaterialApp(
|
||||
theme: EditorTheme.forPalette(
|
||||
AppPalette.graphite,
|
||||
Brightness.light,
|
||||
),
|
||||
home: Column(
|
||||
children: [
|
||||
const TimelineRulerSettingsField(),
|
||||
Expanded(
|
||||
child: EditorTimelineViewport(
|
||||
controller: controller,
|
||||
child: TimelineView(controller: controller),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
await tester.pump();
|
||||
expect(
|
||||
find.byKey(const Key('settings-timeline-ruler-style')),
|
||||
findsNothing,
|
||||
);
|
||||
expect(
|
||||
tester.widget<TimelineRuler>(find.byType(TimelineRuler)).style,
|
||||
TimelineRulerStyle.elapsed,
|
||||
);
|
||||
expect(scope.exists(timelineRulerSettingsProvider), isFalse);
|
||||
expect(tester.takeException(), isNull);
|
||||
await tester.pumpWidget(const SizedBox.shrink());
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
TimelineViewController _controller() {
|
||||
final kernel = TimelineKernel.importDto(
|
||||
TimelineDto(
|
||||
id: SequenceId('settings-test'),
|
||||
format: TimelineFormat.fps30,
|
||||
primaryStorylineId: StorylineId('primary'),
|
||||
storylines: [
|
||||
StorylineDto(id: StorylineId('primary'), elementIds: const []),
|
||||
],
|
||||
elements: const [],
|
||||
),
|
||||
);
|
||||
final projection = const TimelineLayoutSceneBuilder().project(
|
||||
version: kernel.current,
|
||||
stacks: const [],
|
||||
appearance: (_, _, _) => throw StateError('no connections'),
|
||||
);
|
||||
final layout = TimelineLayoutEngine(kernel: kernel).initializeProjection(
|
||||
kernel: kernel,
|
||||
projection: projection,
|
||||
policy: LayoutPolicy(version: 1, stacks: const []),
|
||||
);
|
||||
return TimelineViewController(
|
||||
version: layout.version,
|
||||
storyline: kernel.current.query().primaryStoryline,
|
||||
geometry: TimelineViewportGeometry(primaryTop: 0, primaryHeight: 48),
|
||||
format: TimelineFormat.fps30,
|
||||
camera: TimelineCamera(
|
||||
baseTick: 0,
|
||||
pixelsPerTick: 60 / TimelineClock.ticksPerSecond,
|
||||
),
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,226 @@
|
||||
import 'package:cutdex/features/projects/projects_page.dart';
|
||||
|
||||
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_sdk/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(
|
||||
'timeline navigation retains panels through preparation and failure',
|
||||
(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 = _DelayedTimelineProjects();
|
||||
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(
|
||||
'project',
|
||||
'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();
|
||||
var windowBuilds = 0;
|
||||
final previousBuild = debugOnRebuildDirtyWidget;
|
||||
debugOnRebuildDirtyWidget = (element, built) {
|
||||
previousBuild?.call(element, built);
|
||||
if (element.widget is EditingPage || element.widget is MaterialApp) {
|
||||
windowBuilds++;
|
||||
}
|
||||
};
|
||||
projects.updateAssets([
|
||||
AssetDocument(
|
||||
id: 'new-media',
|
||||
name: 'New media',
|
||||
storage: AssetStorage.external,
|
||||
location: 'file:///test/new.png',
|
||||
metadata: const {'kind': 'image'},
|
||||
),
|
||||
]);
|
||||
await tester.pumpAndSettle();
|
||||
debugOnRebuildDirtyWidget = previousBuild;
|
||||
expect(
|
||||
windowBuilds,
|
||||
0,
|
||||
reason: 'Asset changes belong to content, not window/navigation',
|
||||
);
|
||||
await tester.tap(find.byKey(const Key('editor-properties-button')));
|
||||
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 ValueKey('timeline-tab-second')));
|
||||
await tester.pump();
|
||||
expect(
|
||||
container.read(projectsProvider).requireValue.openingTimelineId,
|
||||
'second',
|
||||
);
|
||||
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(
|
||||
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 _DelayedTimelineProjects extends Projects {
|
||||
Completer<bool>? _pending;
|
||||
void updateAssets(List<AssetDocument> assets) =>
|
||||
state = AsyncData(state.requireValue.copyWith(assets: assets));
|
||||
TimelineDocument _document(String id) =>
|
||||
TimelineDocument(id: id, name: id, sequences: []);
|
||||
@override
|
||||
Future<ProjectState> build() async => ProjectState(
|
||||
activeProject: const RecentProject(
|
||||
id: 'project',
|
||||
name: 'Project',
|
||||
path: '/test/Project.cutdex',
|
||||
),
|
||||
recent: const [
|
||||
RecentProject(
|
||||
id: 'project',
|
||||
name: 'Project',
|
||||
path: '/test/Project.cutdex',
|
||||
),
|
||||
],
|
||||
timelines: const [
|
||||
TimelineSummary(id: 'first', name: 'First', revision: 1),
|
||||
TimelineSummary(id: 'second', name: 'Second', revision: 1),
|
||||
],
|
||||
timeline: _document('first'),
|
||||
);
|
||||
@override
|
||||
Future<bool> openTimeline(String projectId, String timelineId) async {
|
||||
_pending = Completer<bool>();
|
||||
state = AsyncData(
|
||||
state.requireValue.copyWith(openingTimelineId: timelineId),
|
||||
);
|
||||
final success = await _pending!.future;
|
||||
state = AsyncData(
|
||||
state.requireValue.copyWith(
|
||||
timeline: success ? _document(timelineId) : state.requireValue.timeline,
|
||||
openingTimelineId: null,
|
||||
),
|
||||
);
|
||||
return success;
|
||||
}
|
||||
|
||||
void finish(bool success) => _pending!.complete(success);
|
||||
}
|
||||
+378
-349
@@ -5,6 +5,7 @@ import 'package:crypto/crypto.dart';
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
import 'package:cutdex/integrations/runtime/processing_resource_repository.dart';
|
||||
import 'package:cutdex/l10n/app_localizations.dart';
|
||||
import 'package:cutdex_ui/icons.dart';
|
||||
import 'package:cutdex_ui/theme.dart';
|
||||
import 'package:cutdex_ui/widgets.dart';
|
||||
|
||||
@@ -1763,156 +1764,230 @@ void main() {
|
||||
},
|
||||
);
|
||||
|
||||
testWidgets(
|
||||
'MCP caption edit updates visible fields and undo restores them',
|
||||
(tester) async {
|
||||
late String id;
|
||||
await tester.runAsync(() async {
|
||||
final task = await applyFixture();
|
||||
final result = await session.applyTranscription(
|
||||
sequence,
|
||||
ApplyTranscription(taskId: task, clipId: 'clip'),
|
||||
);
|
||||
id = (result['captionIds'] as List).single as String;
|
||||
});
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(
|
||||
localizationsDelegates: AppLocalizations.localizationsDelegates,
|
||||
supportedLocales: AppLocalizations.supportedLocales,
|
||||
locale: const Locale('zh'),
|
||||
for (final desktop in [false, true]) {
|
||||
testWidgets(
|
||||
'MCP caption edit desktop=$desktop updates visible fields and undo restores them',
|
||||
(tester) async {
|
||||
late String id;
|
||||
await tester.runAsync(() async {
|
||||
final task = await applyFixture();
|
||||
final result = await session.applyTranscription(
|
||||
sequence,
|
||||
ApplyTranscription(taskId: task, clipId: 'clip'),
|
||||
);
|
||||
id = (result['captionIds'] as List).single as String;
|
||||
});
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(
|
||||
localizationsDelegates: AppLocalizations.localizationsDelegates,
|
||||
supportedLocales: AppLocalizations.supportedLocales,
|
||||
locale: const Locale('zh'),
|
||||
theme: desktop
|
||||
? AppTheme.propertiesPanelTheme(
|
||||
EditorTheme.desktop(EditorTheme.penDark),
|
||||
)
|
||||
: EditorTheme.penDark,
|
||||
|
||||
home: Scaffold(
|
||||
body: Align(
|
||||
alignment: Alignment.topRight,
|
||||
child: SizedBox(
|
||||
width: 280,
|
||||
child: CaptionProperties(
|
||||
session: session,
|
||||
sequence: sequence,
|
||||
clipId: id,
|
||||
home: Scaffold(
|
||||
body: Align(
|
||||
alignment: Alignment.topRight,
|
||||
child: SizedBox(
|
||||
width: 280,
|
||||
child: CaptionProperties(
|
||||
session: session,
|
||||
sequence: sequence,
|
||||
clipId: id,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
expect(find.text('测试字幕'), findsOneWidget);
|
||||
expect(
|
||||
find.ancestor(of: find.text('测试字幕'), matching: find.byType(ShaderMask)),
|
||||
findsOneWidget,
|
||||
);
|
||||
expect(
|
||||
find.byKey(const ValueKey('caption-property-tab-captions')),
|
||||
findsOneWidget,
|
||||
);
|
||||
expect(
|
||||
find.byKey(const ValueKey('caption-property-tab-text')),
|
||||
findsOneWidget,
|
||||
);
|
||||
for (final key in const [
|
||||
'caption-fontSize',
|
||||
'caption-strokeWidth',
|
||||
'caption-positionY',
|
||||
'caption-start',
|
||||
'caption-duration',
|
||||
]) {
|
||||
expect(find.byKey(Key(key)), findsOneWidget);
|
||||
}
|
||||
expect(find.text('描边颜色'), findsOneWidget);
|
||||
await tester.runAsync(() async {
|
||||
session.setCaption(
|
||||
sequence,
|
||||
SetCaption(
|
||||
captionId: id,
|
||||
start: CommandTime(1, 1000),
|
||||
duration: CommandTime(1, 1000),
|
||||
positionY: -.298,
|
||||
);
|
||||
expect(find.text('测试字幕'), findsOneWidget);
|
||||
expect(
|
||||
find.ancestor(
|
||||
of: find.text('测试字幕'),
|
||||
matching: find.byType(ShaderMask),
|
||||
),
|
||||
findsOneWidget,
|
||||
);
|
||||
expect(
|
||||
find.byKey(const ValueKey('caption-property-tab-captions')),
|
||||
findsOneWidget,
|
||||
);
|
||||
expect(
|
||||
find.byKey(const ValueKey('caption-property-tab-text')),
|
||||
findsOneWidget,
|
||||
);
|
||||
for (final key in const [
|
||||
'caption-fontSize',
|
||||
'caption-strokeWidth',
|
||||
'caption-positionY',
|
||||
'caption-start',
|
||||
'caption-duration',
|
||||
]) {
|
||||
expect(find.byKey(Key(key)), findsOneWidget);
|
||||
}
|
||||
expect(find.text('描边颜色'), findsOneWidget);
|
||||
await tester.runAsync(() async {
|
||||
session.setCaption(
|
||||
sequence,
|
||||
SetCaption(
|
||||
captionId: id,
|
||||
start: CommandTime(1, 1000),
|
||||
duration: CommandTime(1, 1000),
|
||||
positionY: -.298,
|
||||
),
|
||||
);
|
||||
await session.flush();
|
||||
});
|
||||
await tester.pump();
|
||||
String fieldText(String key) => tester
|
||||
.widget<TextField>(
|
||||
find.descendant(
|
||||
of: find.byKey(ValueKey(key)),
|
||||
matching: find.byType(TextField),
|
||||
),
|
||||
)
|
||||
.controller!
|
||||
.text;
|
||||
expect(fieldText('caption-start'), '0.001');
|
||||
expect(fieldText('caption-duration'), '0.001');
|
||||
expect(fieldText('caption-positionY'), '-0.298');
|
||||
await tester.runAsync(() async => session.undo(sequence));
|
||||
await tester.pump();
|
||||
|
||||
await tester.tap(
|
||||
find.byKey(const ValueKey('caption-property-tab-captions')),
|
||||
);
|
||||
await tester.pump();
|
||||
expect(find.byKey(ValueKey('caption-list-$id')), findsOneWidget);
|
||||
expect(find.byKey(const Key('caption-fontSize')), findsNothing);
|
||||
await tester.tap(find.byKey(ValueKey('caption-list-$id')));
|
||||
await tester.pump();
|
||||
expect(find.byKey(ValueKey('caption-list-$id')), findsOneWidget);
|
||||
expect(find.byKey(const Key('caption-fontSize')), findsNothing);
|
||||
await tester.tap(
|
||||
find.byKey(const ValueKey('caption-property-tab-text')),
|
||||
);
|
||||
await tester.pump();
|
||||
expect(find.byKey(const Key('caption-fontSize')), findsOneWidget);
|
||||
final versionBeforeScrub = session.version;
|
||||
await tester.drag(find.text('字号'), const Offset(50, 0));
|
||||
await tester.pump();
|
||||
expect(session.caption(sequence, id).fontSize, closeTo(58, 1e-9));
|
||||
expect(session.version, isNot(versionBeforeScrub));
|
||||
await tester.runAsync(() async => session.undo(sequence));
|
||||
await tester.pump();
|
||||
expect(session.caption(sequence, id).fontSize, 48);
|
||||
final access = EditorToolAccess(session);
|
||||
addTearDown(access.dispose);
|
||||
final connection = access.server.connect();
|
||||
addTearDown(connection.close);
|
||||
final response = await tester.runAsync(
|
||||
() => connection.handleJson(
|
||||
jsonEncode({
|
||||
'jsonrpc': '2.0',
|
||||
'id': 1,
|
||||
'method': 'tools/call',
|
||||
'params': {
|
||||
'_meta': {
|
||||
'io.modelcontextprotocol/protocolVersion': '2026-07-28',
|
||||
'io.modelcontextprotocol/clientCapabilities':
|
||||
<String, Object?>{},
|
||||
},
|
||||
'name': 'caption.set',
|
||||
'arguments': {
|
||||
'workspaceId': access.workspaces.keys.single,
|
||||
'operationId': 'mcp-text',
|
||||
'captionId': id,
|
||||
'text': '来自 MCP 的字幕',
|
||||
'strokeColor': '#FF0000',
|
||||
'strokeWidth': 2,
|
||||
},
|
||||
},
|
||||
}),
|
||||
),
|
||||
);
|
||||
await session.flush();
|
||||
});
|
||||
await tester.pump();
|
||||
String fieldText(String key) => tester
|
||||
.widget<TextField>(
|
||||
find.descendant(
|
||||
of: find.byKey(ValueKey(key)),
|
||||
matching: find.byType(TextField),
|
||||
),
|
||||
)
|
||||
.controller!
|
||||
.text;
|
||||
expect(fieldText('caption-start'), '0.001');
|
||||
expect(fieldText('caption-duration'), '0.001');
|
||||
expect(fieldText('caption-positionY'), '-0.298');
|
||||
await tester.runAsync(() async => session.undo(sequence));
|
||||
await tester.pump();
|
||||
expect(response.toString(), contains('来自 MCP 的字幕'));
|
||||
await tester.pump();
|
||||
expect(find.text('来自 MCP 的字幕'), findsOneWidget);
|
||||
expect(session.caption(sequence, id).strokeColor, '#FF0000');
|
||||
expect(session.caption(sequence, id).strokeWidth, 2);
|
||||
await tester.runAsync(() async {
|
||||
session.undo(sequence);
|
||||
});
|
||||
await tester.pump();
|
||||
expect(find.text('测试字幕'), findsOneWidget);
|
||||
final role = session.captionRole(sequence)!;
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(
|
||||
localizationsDelegates: AppLocalizations.localizationsDelegates,
|
||||
supportedLocales: AppLocalizations.supportedLocales,
|
||||
locale: const Locale('zh'),
|
||||
|
||||
await tester.tap(
|
||||
find.byKey(const ValueKey('caption-property-tab-captions')),
|
||||
);
|
||||
await tester.pump();
|
||||
expect(find.byKey(ValueKey('caption-list-$id')), findsOneWidget);
|
||||
expect(find.byKey(const Key('caption-fontSize')), findsNothing);
|
||||
await tester.tap(find.byKey(ValueKey('caption-list-$id')));
|
||||
await tester.pump();
|
||||
expect(find.byKey(ValueKey('caption-list-$id')), findsOneWidget);
|
||||
expect(find.byKey(const Key('caption-fontSize')), findsNothing);
|
||||
await tester.tap(find.byKey(const ValueKey('caption-property-tab-text')));
|
||||
await tester.pump();
|
||||
expect(find.byKey(const Key('caption-fontSize')), findsOneWidget);
|
||||
final versionBeforeScrub = session.version;
|
||||
await tester.drag(find.text('字号'), const Offset(50, 0));
|
||||
await tester.pump();
|
||||
expect(session.caption(sequence, id).fontSize, closeTo(58, 1e-9));
|
||||
expect(session.version, isNot(versionBeforeScrub));
|
||||
await tester.runAsync(() async => session.undo(sequence));
|
||||
await tester.pump();
|
||||
expect(session.caption(sequence, id).fontSize, 48);
|
||||
final access = EditorToolAccess(session);
|
||||
addTearDown(access.dispose);
|
||||
final connection = access.server.connect();
|
||||
addTearDown(connection.close);
|
||||
final response = await tester.runAsync(
|
||||
() => connection.handleJson(
|
||||
jsonEncode({
|
||||
'jsonrpc': '2.0',
|
||||
'id': 1,
|
||||
'method': 'tools/call',
|
||||
'params': {
|
||||
'_meta': {
|
||||
'io.modelcontextprotocol/protocolVersion': '2026-07-28',
|
||||
'io.modelcontextprotocol/clientCapabilities':
|
||||
<String, Object?>{},
|
||||
},
|
||||
'name': 'caption.set',
|
||||
'arguments': {
|
||||
'workspaceId': access.workspaces.keys.single,
|
||||
'operationId': 'mcp-text',
|
||||
'captionId': id,
|
||||
'text': '来自 MCP 的字幕',
|
||||
'strokeColor': '#FF0000',
|
||||
'strokeWidth': 2,
|
||||
},
|
||||
},
|
||||
}),
|
||||
),
|
||||
);
|
||||
expect(response.toString(), contains('来自 MCP 的字幕'));
|
||||
await tester.pump();
|
||||
expect(find.text('来自 MCP 的字幕'), findsOneWidget);
|
||||
expect(session.caption(sequence, id).strokeColor, '#FF0000');
|
||||
expect(session.caption(sequence, id).strokeWidth, 2);
|
||||
await tester.runAsync(() async {
|
||||
session.undo(sequence);
|
||||
});
|
||||
await tester.pump();
|
||||
expect(find.text('测试字幕'), findsOneWidget);
|
||||
final role = session.captionRole(sequence)!;
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(
|
||||
home: Scaffold(
|
||||
body: SizedBox(
|
||||
width: 280,
|
||||
child: CaptionProperties(
|
||||
session: session,
|
||||
sequence: sequence,
|
||||
clipId: session.persistence
|
||||
.timeline(sequence)
|
||||
.current
|
||||
.query()
|
||||
.element(role)
|
||||
.id
|
||||
.value,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
expect(
|
||||
find.byKey(const ValueKey('caption-property-tab-captions')),
|
||||
findsOneWidget,
|
||||
);
|
||||
expect(
|
||||
find.byKey(const ValueKey('caption-property-tab-text')),
|
||||
findsNothing,
|
||||
);
|
||||
expect(find.byKey(ValueKey('caption-list-$id')), findsOneWidget);
|
||||
await tester.pumpWidget(const SizedBox.shrink());
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
for (final desktop in [false, true]) {
|
||||
testWidgets(
|
||||
'caption overview desktop=$desktop selects the chosen text cue',
|
||||
(tester) async {
|
||||
await tester.binding.setSurfaceSize(const Size(280, 240));
|
||||
addTearDown(() => tester.binding.setSurfaceSize(null));
|
||||
late String firstId;
|
||||
late String secondId;
|
||||
await tester.runAsync(() async {
|
||||
final task = await applyFixture();
|
||||
final first = await session.applyTranscription(
|
||||
sequence,
|
||||
ApplyTranscription(taskId: task, clipId: 'clip'),
|
||||
);
|
||||
final second = await session.applyTranscription(
|
||||
sequence,
|
||||
ApplyTranscription(taskId: task, clipId: 'clip'),
|
||||
);
|
||||
firstId = (first['captionIds'] as List).single as String;
|
||||
secondId = (second['captionIds'] as List).single as String;
|
||||
});
|
||||
Widget panel(String clipId) => MaterialApp(
|
||||
localizationsDelegates: AppLocalizations.localizationsDelegates,
|
||||
supportedLocales: AppLocalizations.supportedLocales,
|
||||
locale: const Locale('zh'),
|
||||
theme: desktop
|
||||
? AppTheme.propertiesPanelTheme(
|
||||
EditorTheme.desktop(EditorTheme.penDark),
|
||||
)
|
||||
: EditorTheme.penDark,
|
||||
|
||||
home: Scaffold(
|
||||
body: SizedBox(
|
||||
@@ -1920,220 +1995,174 @@ void main() {
|
||||
child: CaptionProperties(
|
||||
session: session,
|
||||
sequence: sequence,
|
||||
clipId: session.persistence
|
||||
.timeline(sequence)
|
||||
.current
|
||||
.query()
|
||||
.element(role)
|
||||
.id
|
||||
.value,
|
||||
clipId: clipId,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
expect(
|
||||
find.byKey(const ValueKey('caption-property-tab-captions')),
|
||||
findsOneWidget,
|
||||
);
|
||||
expect(
|
||||
find.byKey(const ValueKey('caption-property-tab-text')),
|
||||
findsNothing,
|
||||
);
|
||||
expect(find.byKey(ValueKey('caption-list-$id')), findsOneWidget);
|
||||
await tester.pumpWidget(const SizedBox.shrink());
|
||||
},
|
||||
);
|
||||
);
|
||||
await tester.pumpWidget(panel(firstId));
|
||||
await tester.tap(
|
||||
find.byKey(const ValueKey('caption-property-tab-captions')),
|
||||
);
|
||||
await tester.pump();
|
||||
for (final id in [firstId, secondId]) {
|
||||
final row = tester.getRect(find.byKey(ValueKey('caption-list-$id')));
|
||||
final number = tester.getRect(
|
||||
find.byKey(ValueKey('caption-number-$id')),
|
||||
);
|
||||
final content = tester.getRect(
|
||||
find.byKey(ValueKey('caption-content-$id')),
|
||||
);
|
||||
final action = tester.getRect(
|
||||
find.byKey(ValueKey('caption-action-$id')),
|
||||
);
|
||||
expect(row.height, 28);
|
||||
final list = tester.getRect(
|
||||
find.ancestor(
|
||||
of: find.byKey(ValueKey('caption-list-$id')),
|
||||
matching: find.byType(ListView),
|
||||
),
|
||||
);
|
||||
expect(row.left - list.left, desktop ? 12 : 14);
|
||||
expect(number.left - row.left, 0);
|
||||
expect(content.left - number.right, 6);
|
||||
expect(number.right, lessThan(content.left));
|
||||
expect(content.right, lessThan(action.left));
|
||||
expect(number.center.dy, closeTo(content.center.dy, 0.1));
|
||||
expect(content.center.dy, closeTo(action.center.dy, 0.1));
|
||||
expect(action.right, lessThanOrEqualTo(row.right));
|
||||
}
|
||||
await tester.runAsync(() async {
|
||||
session.setCaption(
|
||||
sequence,
|
||||
SetCaption(captionId: secondId, text: 'Searchable CAPTION ' * 20),
|
||||
);
|
||||
await session.flush();
|
||||
});
|
||||
await tester.pump();
|
||||
final search = find.byKey(const ValueKey('caption-search'));
|
||||
final searchBounds = tester.getRect(search);
|
||||
final wrapBounds = tester.getRect(
|
||||
find.byKey(const ValueKey('caption-wrap-toggle')),
|
||||
);
|
||||
expect(searchBounds.height, 28);
|
||||
expect(wrapBounds.height, desktop ? 24 : 28);
|
||||
expect(searchBounds.center.dy, wrapBounds.center.dy);
|
||||
await tester.enterText(search, ' searchable ');
|
||||
await tester.pump();
|
||||
expect(find.byKey(ValueKey('caption-list-$firstId')), findsNothing);
|
||||
expect(find.byKey(ValueKey('caption-list-$secondId')), findsOneWidget);
|
||||
expect(
|
||||
tester
|
||||
.widget<Text>(find.byKey(ValueKey('caption-number-$secondId')))
|
||||
.data,
|
||||
'2',
|
||||
);
|
||||
expect(
|
||||
tester.getSize(find.byKey(ValueKey('caption-list-$secondId'))).height,
|
||||
28,
|
||||
);
|
||||
await tester.enterText(search, 'no such caption');
|
||||
await tester.pump();
|
||||
expect(find.text('没有匹配的字幕'), findsOneWidget);
|
||||
await tester.enterText(search, '');
|
||||
await tester.pump();
|
||||
expect(find.byKey(ValueKey('caption-list-$firstId')), findsOneWidget);
|
||||
final toolbarPosition = tester.getTopLeft(search);
|
||||
await tester.tap(find.byKey(const ValueKey('caption-wrap-toggle')));
|
||||
await tester.pump();
|
||||
expect(
|
||||
tester.getSize(find.byKey(ValueKey('caption-list-$secondId'))).height,
|
||||
greaterThan(28),
|
||||
);
|
||||
expect(tester.getTopLeft(search), toolbarPosition);
|
||||
final list = find.byKey(const ValueKey('caption-scroll-list'));
|
||||
expect(list, findsOneWidget);
|
||||
expect(
|
||||
find.ancestor(of: search, matching: find.byType(ShaderMask)),
|
||||
findsNothing,
|
||||
);
|
||||
expect(
|
||||
find.ancestor(of: list, matching: find.byType(ShaderMask)),
|
||||
findsOneWidget,
|
||||
);
|
||||
expect(
|
||||
tester.widget<ListView>(list).physics,
|
||||
isA<ClampingScrollPhysics>(),
|
||||
);
|
||||
final scroll = tester
|
||||
.state<ScrollableState>(
|
||||
find.descendant(of: list, matching: find.byType(Scrollable)),
|
||||
)
|
||||
.position;
|
||||
expect(scroll.extentBefore, 0);
|
||||
expect(scroll.extentAfter, greaterThan(24));
|
||||
await tester.drag(list, const Offset(0, -60));
|
||||
await tester.pumpAndSettle();
|
||||
expect(scroll.pixels, greaterThan(0));
|
||||
scroll.jumpTo(scroll.maxScrollExtent / 2);
|
||||
await tester.pumpAndSettle();
|
||||
expect(scroll.extentBefore, greaterThan(0));
|
||||
expect(scroll.extentAfter, greaterThan(0));
|
||||
scroll.jumpTo(scroll.maxScrollExtent);
|
||||
await tester.pumpAndSettle();
|
||||
expect(scroll.extentAfter, 0);
|
||||
expect(tester.getTopLeft(search), toolbarPosition);
|
||||
expect(tester.takeException(), isNull);
|
||||
await tester.tap(find.byKey(const ValueKey('caption-wrap-toggle')));
|
||||
await tester.pump();
|
||||
expect(
|
||||
tester.getSize(find.byKey(ValueKey('caption-list-$secondId'))).height,
|
||||
28,
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
expect(scroll.extentAfter, 0);
|
||||
expect(scroll.extentBefore, 0);
|
||||
await tester.tap(find.byKey(ValueKey('caption-action-$secondId')));
|
||||
await tester.pump();
|
||||
|
||||
testWidgets('caption overview selects the chosen text cue', (tester) async {
|
||||
await tester.binding.setSurfaceSize(const Size(280, 240));
|
||||
addTearDown(() => tester.binding.setSurfaceSize(null));
|
||||
late String firstId;
|
||||
late String secondId;
|
||||
await tester.runAsync(() async {
|
||||
final task = await applyFixture();
|
||||
final first = await session.applyTranscription(
|
||||
sequence,
|
||||
ApplyTranscription(taskId: task, clipId: 'clip'),
|
||||
);
|
||||
final second = await session.applyTranscription(
|
||||
sequence,
|
||||
ApplyTranscription(taskId: task, clipId: 'clip'),
|
||||
);
|
||||
firstId = (first['captionIds'] as List).single as String;
|
||||
secondId = (second['captionIds'] as List).single as String;
|
||||
});
|
||||
Widget panel(String clipId) => MaterialApp(
|
||||
localizationsDelegates: AppLocalizations.localizationsDelegates,
|
||||
supportedLocales: AppLocalizations.supportedLocales,
|
||||
locale: const Locale('zh'),
|
||||
|
||||
home: Scaffold(
|
||||
body: SizedBox(
|
||||
width: 280,
|
||||
child: CaptionProperties(
|
||||
session: session,
|
||||
sequence: sequence,
|
||||
clipId: clipId,
|
||||
final identity = session.view(sequence).selectedIdentities.single;
|
||||
expect(identity, isA<LayoutBodyId>());
|
||||
final selected = session.resolveCaptionComponent(
|
||||
sequence,
|
||||
identity as LayoutBodyId,
|
||||
);
|
||||
expect(
|
||||
session.persistence
|
||||
.timeline(sequence)
|
||||
.current
|
||||
.query()
|
||||
.element(selected!)
|
||||
.id
|
||||
.value,
|
||||
secondId,
|
||||
);
|
||||
await tester.pumpWidget(panel(secondId));
|
||||
await tester.pumpAndSettle();
|
||||
final selectedRow = find.byKey(ValueKey('caption-list-$secondId'));
|
||||
expect(selectedRow, findsOneWidget);
|
||||
expect(find.byKey(const ValueKey('caption-search')), findsOneWidget);
|
||||
expect(find.byKey(const Key('caption-fontSize')), findsNothing);
|
||||
final selectedColor = Theme.of(tester.element(selectedRow))
|
||||
.colorScheme
|
||||
.onSurface
|
||||
.withValues(alpha: .05);
|
||||
expect(
|
||||
find.ancestor(
|
||||
of: selectedRow,
|
||||
matching: find.byWidgetPredicate(
|
||||
(widget) => widget is Material && widget.color == selectedColor,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
findsOneWidget,
|
||||
);
|
||||
await tester.tap(selectedRow);
|
||||
await tester.pump();
|
||||
expect(selectedRow, findsOneWidget);
|
||||
expect(find.byKey(const Key('caption-fontSize')), findsNothing);
|
||||
},
|
||||
);
|
||||
await tester.pumpWidget(panel(firstId));
|
||||
await tester.tap(
|
||||
find.byKey(const ValueKey('caption-property-tab-captions')),
|
||||
);
|
||||
await tester.pump();
|
||||
for (final id in [firstId, secondId]) {
|
||||
final row = tester.getRect(find.byKey(ValueKey('caption-list-$id')));
|
||||
final number = tester.getRect(find.byKey(ValueKey('caption-number-$id')));
|
||||
final content = tester.getRect(
|
||||
find.byKey(ValueKey('caption-content-$id')),
|
||||
);
|
||||
final action = tester.getRect(find.byKey(ValueKey('caption-action-$id')));
|
||||
expect(row.height, 28);
|
||||
final list = tester.getRect(
|
||||
find.ancestor(
|
||||
of: find.byKey(ValueKey('caption-list-$id')),
|
||||
matching: find.byType(ListView),
|
||||
),
|
||||
);
|
||||
expect(row.left - list.left, 14);
|
||||
expect(number.left - row.left, 0);
|
||||
expect(content.left - number.right, 6);
|
||||
expect(number.right, lessThan(content.left));
|
||||
expect(content.right, lessThan(action.left));
|
||||
expect(number.center.dy, closeTo(content.center.dy, 0.1));
|
||||
expect(content.center.dy, closeTo(action.center.dy, 0.1));
|
||||
expect(action.right, lessThanOrEqualTo(row.right));
|
||||
}
|
||||
await tester.runAsync(() async {
|
||||
session.setCaption(
|
||||
sequence,
|
||||
SetCaption(captionId: secondId, text: 'Searchable CAPTION ' * 20),
|
||||
);
|
||||
await session.flush();
|
||||
});
|
||||
await tester.pump();
|
||||
final search = find.byKey(const ValueKey('caption-search'));
|
||||
final searchBounds = tester.getRect(search);
|
||||
final wrapBounds = tester.getRect(
|
||||
find.byKey(const ValueKey('caption-wrap-toggle')),
|
||||
);
|
||||
expect(searchBounds.height, 28);
|
||||
expect(wrapBounds.height, 28);
|
||||
expect(searchBounds.top, wrapBounds.top);
|
||||
expect(searchBounds.bottom, wrapBounds.bottom);
|
||||
await tester.enterText(search, ' searchable ');
|
||||
await tester.pump();
|
||||
expect(find.byKey(ValueKey('caption-list-$firstId')), findsNothing);
|
||||
expect(find.byKey(ValueKey('caption-list-$secondId')), findsOneWidget);
|
||||
expect(
|
||||
tester
|
||||
.widget<Text>(find.byKey(ValueKey('caption-number-$secondId')))
|
||||
.data,
|
||||
'2',
|
||||
);
|
||||
expect(
|
||||
tester.getSize(find.byKey(ValueKey('caption-list-$secondId'))).height,
|
||||
28,
|
||||
);
|
||||
await tester.enterText(search, 'no such caption');
|
||||
await tester.pump();
|
||||
expect(find.text('没有匹配的字幕'), findsOneWidget);
|
||||
await tester.enterText(search, '');
|
||||
await tester.pump();
|
||||
expect(find.byKey(ValueKey('caption-list-$firstId')), findsOneWidget);
|
||||
final toolbarPosition = tester.getTopLeft(search);
|
||||
await tester.tap(find.byKey(const ValueKey('caption-wrap-toggle')));
|
||||
await tester.pump();
|
||||
expect(
|
||||
tester.getSize(find.byKey(ValueKey('caption-list-$secondId'))).height,
|
||||
greaterThan(28),
|
||||
);
|
||||
expect(tester.getTopLeft(search), toolbarPosition);
|
||||
final list = find.byKey(const ValueKey('caption-scroll-list'));
|
||||
expect(list, findsOneWidget);
|
||||
expect(
|
||||
find.ancestor(of: search, matching: find.byType(ShaderMask)),
|
||||
findsNothing,
|
||||
);
|
||||
expect(
|
||||
find.ancestor(of: list, matching: find.byType(ShaderMask)),
|
||||
findsOneWidget,
|
||||
);
|
||||
expect(tester.widget<ListView>(list).physics, isA<ClampingScrollPhysics>());
|
||||
final scroll = tester
|
||||
.state<ScrollableState>(
|
||||
find.descendant(of: list, matching: find.byType(Scrollable)),
|
||||
)
|
||||
.position;
|
||||
expect(scroll.extentBefore, 0);
|
||||
expect(scroll.extentAfter, greaterThan(24));
|
||||
await tester.drag(list, const Offset(0, -60));
|
||||
await tester.pumpAndSettle();
|
||||
expect(scroll.pixels, greaterThan(0));
|
||||
scroll.jumpTo(scroll.maxScrollExtent / 2);
|
||||
await tester.pumpAndSettle();
|
||||
expect(scroll.extentBefore, greaterThan(0));
|
||||
expect(scroll.extentAfter, greaterThan(0));
|
||||
scroll.jumpTo(scroll.maxScrollExtent);
|
||||
await tester.pumpAndSettle();
|
||||
expect(scroll.extentAfter, 0);
|
||||
expect(tester.getTopLeft(search), toolbarPosition);
|
||||
expect(tester.takeException(), isNull);
|
||||
await tester.tap(find.byKey(const ValueKey('caption-wrap-toggle')));
|
||||
await tester.pump();
|
||||
expect(
|
||||
tester.getSize(find.byKey(ValueKey('caption-list-$secondId'))).height,
|
||||
28,
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
expect(scroll.extentAfter, 0);
|
||||
expect(scroll.extentBefore, 0);
|
||||
await tester.tap(find.byKey(ValueKey('caption-action-$secondId')));
|
||||
await tester.pump();
|
||||
|
||||
final identity = session.view(sequence).selectedIdentities.single;
|
||||
expect(identity, isA<LayoutBodyId>());
|
||||
final selected = session.resolveCaptionComponent(
|
||||
sequence,
|
||||
identity as LayoutBodyId,
|
||||
);
|
||||
expect(
|
||||
session.persistence
|
||||
.timeline(sequence)
|
||||
.current
|
||||
.query()
|
||||
.element(selected!)
|
||||
.id
|
||||
.value,
|
||||
secondId,
|
||||
);
|
||||
await tester.pumpWidget(panel(secondId));
|
||||
await tester.pumpAndSettle();
|
||||
final selectedRow = find.byKey(ValueKey('caption-list-$secondId'));
|
||||
expect(selectedRow, findsOneWidget);
|
||||
expect(find.byKey(const ValueKey('caption-search')), findsOneWidget);
|
||||
expect(find.byKey(const Key('caption-fontSize')), findsNothing);
|
||||
final selectedColor = Theme.of(tester.element(selectedRow))
|
||||
.colorScheme
|
||||
.onSurface
|
||||
.withValues(alpha: .05);
|
||||
expect(
|
||||
find.ancestor(
|
||||
of: selectedRow,
|
||||
matching: find.byWidgetPredicate(
|
||||
(widget) => widget is Material && widget.color == selectedColor,
|
||||
),
|
||||
),
|
||||
findsOneWidget,
|
||||
);
|
||||
await tester.tap(selectedRow);
|
||||
await tester.pump();
|
||||
expect(selectedRow, findsOneWidget);
|
||||
expect(find.byKey(const Key('caption-fontSize')), findsNothing);
|
||||
});
|
||||
}
|
||||
|
||||
test(
|
||||
'completed transcription output is reused and persists inside the project',
|
||||
@@ -2552,7 +2581,7 @@ void main() {
|
||||
maxHeight: 180,
|
||||
builder: (_, toggle) => IconButton(
|
||||
onPressed: toggle,
|
||||
icon: const Icon(Icons.task_alt),
|
||||
icon: const Icon(AppIcons.success),
|
||||
),
|
||||
child: BackgroundTasksContent(session: session),
|
||||
),
|
||||
@@ -2566,7 +2595,7 @@ void main() {
|
||||
expect(find.text('后台任务'), findsNothing);
|
||||
expect(find.textContaining('字幕已生成'), findsOneWidget);
|
||||
expect(find.text('应用原文字幕'), findsNothing);
|
||||
expect(find.byIcon(Icons.chevron_right), findsNothing);
|
||||
expect(find.byIcon(AppIcons.chevronRight), findsNothing);
|
||||
final taskRow = find
|
||||
.ancestor(of: find.text('source'), matching: find.byType(InkWell))
|
||||
.first;
|
||||
|
||||
+352
-868
File diff suppressed because it is too large.
Load diff
@@ -87,4 +87,95 @@ void main() {
|
||||
}
|
||||
},
|
||||
);
|
||||
test(
|
||||
'LRU trims idle output but preserves leased controllers until release',
|
||||
() async {
|
||||
var sessionId = 0;
|
||||
final closed = <String>[];
|
||||
for (final id in ['1', '2', '3']) {
|
||||
final events = MethodChannel('cutdex_runtime/sessions/$id');
|
||||
messenger.setMockMethodCallHandler(events, (call) async {
|
||||
if (call.method == 'listen') {
|
||||
scheduleMicrotask(
|
||||
() => messenger.handlePlatformMessage(
|
||||
events.name,
|
||||
const StandardMethodCodec().encodeSuccessEnvelope({
|
||||
'type': 'attached',
|
||||
}),
|
||||
(_) {},
|
||||
),
|
||||
);
|
||||
}
|
||||
return null;
|
||||
});
|
||||
}
|
||||
messenger.setMockMethodCallHandler(channel, (call) async {
|
||||
switch (call.method) {
|
||||
case 'capabilities':
|
||||
return {
|
||||
'contractVersion': 1,
|
||||
'features': {'playback.preview': 'available'},
|
||||
};
|
||||
case 'createSession':
|
||||
return {'sessionId': '${++sessionId}'};
|
||||
case 'probe':
|
||||
return {
|
||||
'duration': MediaTime(2, 1).toMap(),
|
||||
'videoTrackCount': 1,
|
||||
'videoTrackIds': [1],
|
||||
'audioTrackCount': 0,
|
||||
'audioTrackIds': <int>[],
|
||||
'isProtected': false,
|
||||
};
|
||||
case 'load':
|
||||
return (call.arguments as Map)['plan']['revision'];
|
||||
case 'close':
|
||||
closed.add((call.arguments as Map)['sessionId'] as String);
|
||||
}
|
||||
return null;
|
||||
});
|
||||
final first = await createPreviewFixture(Uri.file('/fixture-1.mov'));
|
||||
final second = await createPreviewFixture(Uri.file('/fixture-2.mov'));
|
||||
final third = await createPreviewFixture(Uri.file('/fixture-3.mov'));
|
||||
final registry = PreviewControllerRegistry(
|
||||
CutdexRuntime(channel: channel),
|
||||
maximumCachedControllers: 2,
|
||||
);
|
||||
try {
|
||||
final releaseFirst = registry.retain(('p', 'first'));
|
||||
final releaseSecond = registry.retain(('p', 'second'));
|
||||
final releaseThird = registry.retain(('p', 'third'));
|
||||
final one = await registry.prepare(('p', 'first'), first.timeline);
|
||||
final two = await registry.prepare(('p', 'second'), second.timeline);
|
||||
final three = await registry.prepare(('p', 'third'), third.timeline);
|
||||
expect(one!.ready, isTrue);
|
||||
expect(two!.ready, isTrue);
|
||||
expect(three!.ready, isTrue);
|
||||
expect(registry.cached(('p', 'first')), same(one));
|
||||
releaseFirst();
|
||||
expect(registry.cached(('p', 'first')), isNull);
|
||||
expect(registry.cached(('p', 'second')), same(two));
|
||||
expect(registry.cached(('p', 'third')), same(three));
|
||||
releaseFirst(); // Releases are idempotent.
|
||||
releaseSecond();
|
||||
releaseThird();
|
||||
await registry.invalidate(('p', 'second'));
|
||||
await registry.invalidate(('p', 'third'));
|
||||
expect(closed.toSet(), {'1', '2', '3'});
|
||||
} finally {
|
||||
registry.dispose();
|
||||
for (final id in ['1', '2', '3']) {
|
||||
messenger.setMockMethodCallHandler(
|
||||
MethodChannel('cutdex_runtime/sessions/$id'),
|
||||
null,
|
||||
);
|
||||
}
|
||||
messenger.setMockMethodCallHandler(channel, null);
|
||||
for (final fixture in [first, second, third]) {
|
||||
await fixture.workspace.close();
|
||||
await fixture.directory.delete(recursive: true);
|
||||
}
|
||||
}
|
||||
},
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,122 @@
|
||||
import 'dart:async';
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:cutdex/persistence/app_database.dart';
|
||||
import 'package:cutdex/persistence/app_settings_repositories.dart';
|
||||
import 'package:cutdex/workspace/persistence/recent_projects.dart';
|
||||
import 'package:cutdex/workspace/projects.dart';
|
||||
import 'package:cutdex/workspace/view_settings.dart';
|
||||
import 'package:drift/native.dart';
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
|
||||
import '../support/memory_app_settings.dart';
|
||||
|
||||
void main() {
|
||||
TestWidgetsFlutterBinding.ensureInitialized();
|
||||
for (final superseded in [false, true]) {
|
||||
test(
|
||||
'project layout is prepared before publication (superseded: $superseded)',
|
||||
() async {
|
||||
final root = await Directory.systemTemp.createTemp(
|
||||
'cutdex-project-layout-',
|
||||
);
|
||||
final database = AppDatabase(NativeDatabase.memory());
|
||||
final layouts = _DelayedLayouts();
|
||||
final container = ProviderContainer(
|
||||
overrides: [
|
||||
appDatabaseProvider.overrideWithValue(database),
|
||||
recentProjectsProvider.overrideWithValue(
|
||||
MemoryRecentProjectsRepository(),
|
||||
),
|
||||
resourceLocationSettingsRepositoryProvider.overrideWithValue(
|
||||
MemoryResourceLocationSettingsRepository(root.path),
|
||||
),
|
||||
projectViewSettingsRepositoryProvider.overrideWithValue(layouts),
|
||||
],
|
||||
);
|
||||
try {
|
||||
final projects = container.read(projectsProvider.notifier);
|
||||
expect(
|
||||
await projects.open('${root.path}/First.cutdex', name: 'First'),
|
||||
isTrue,
|
||||
);
|
||||
final initial = container.read(projectsProvider).requireValue;
|
||||
var current = true;
|
||||
final opening = projects.open(
|
||||
'${root.path}/Second.cutdex',
|
||||
name: 'Second',
|
||||
isCurrent: () => current,
|
||||
);
|
||||
final targetId = await layouts.requested.future;
|
||||
expect(
|
||||
container.read(projectsProvider).requireValue.activeProject,
|
||||
initial.activeProject,
|
||||
);
|
||||
expect(
|
||||
container.read(projectsProvider).requireValue.timeline,
|
||||
initial.timeline,
|
||||
);
|
||||
expect(
|
||||
container.read(projectsProvider).requireValue.projectBusy,
|
||||
isTrue,
|
||||
);
|
||||
expect(
|
||||
container.read(projectViewSettingsProvider(targetId)).isLoading,
|
||||
isTrue,
|
||||
);
|
||||
current = !superseded;
|
||||
layouts.prepared.complete(
|
||||
const ProjectViewSettingsData(
|
||||
propertiesOpen: true,
|
||||
timelineHeight: 320,
|
||||
),
|
||||
);
|
||||
expect(await opening, !superseded);
|
||||
final published = container.read(projectsProvider).requireValue;
|
||||
expect(
|
||||
published.activeProject?.id,
|
||||
superseded ? initial.activeProject!.id : targetId,
|
||||
);
|
||||
expect(published.projectBusy, isFalse);
|
||||
expect(published.error, isNull);
|
||||
expect(
|
||||
container
|
||||
.read(projectViewSettingsProvider(targetId))
|
||||
.requireValue
|
||||
.propertiesOpen,
|
||||
isTrue,
|
||||
);
|
||||
expect(
|
||||
container
|
||||
.read(projectViewSettingsProvider(targetId))
|
||||
.requireValue
|
||||
.timelineHeight,
|
||||
320,
|
||||
);
|
||||
} finally {
|
||||
await container.read(projectsProvider.notifier).prepareToQuit();
|
||||
container.dispose();
|
||||
await database.close();
|
||||
await root.delete(recursive: true);
|
||||
}
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class _DelayedLayouts implements ProjectViewSettingsRepository {
|
||||
String? _firstProjectId;
|
||||
final requested = Completer<String>();
|
||||
final prepared = Completer<ProjectViewSettingsData>();
|
||||
@override
|
||||
Future<ProjectViewSettingsData> load(String projectId) async {
|
||||
_firstProjectId ??= projectId;
|
||||
if (projectId == _firstProjectId) return const ProjectViewSettingsData();
|
||||
requested.complete(projectId);
|
||||
return prepared.future;
|
||||
}
|
||||
|
||||
@override
|
||||
Future<void> save(String projectId, ProjectViewSettingsData settings) async {}
|
||||
}
|
||||
@@ -0,0 +1,85 @@
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:cutdex/features/projects/project_tabs_controller.dart';
|
||||
import 'package:cutdex/integrations/platform/device_experience.dart';
|
||||
import 'package:cutdex/persistence/app_settings_repositories.dart';
|
||||
import 'package:cutdex/workspace/persistence/recent_projects.dart';
|
||||
import 'package:cutdex/workspace/projects.dart';
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
|
||||
import '../support/memory_app_settings.dart';
|
||||
|
||||
void main() {
|
||||
TestWidgetsFlutterBinding.ensureInitialized();
|
||||
test(
|
||||
'closing active project preserves files, history and a reusable session',
|
||||
() async {
|
||||
final root = await Directory.systemTemp.createTemp(
|
||||
'cutdex-project-tabs-',
|
||||
);
|
||||
final container = ProviderContainer(
|
||||
overrides: [
|
||||
deviceExperienceProvider.overrideWithValue(DeviceExperience.desktop),
|
||||
recentProjectsProvider.overrideWithValue(
|
||||
MemoryRecentProjectsRepository(),
|
||||
),
|
||||
resourceLocationSettingsRepositoryProvider.overrideWithValue(
|
||||
MemoryResourceLocationSettingsRepository(root.path),
|
||||
),
|
||||
],
|
||||
);
|
||||
final projects = container.read(projectsProvider.notifier);
|
||||
final tabs = container.read(projectTabsProvider.notifier);
|
||||
try {
|
||||
expect(
|
||||
await projects.open('${root.path}/One.cutdex', name: 'One'),
|
||||
isTrue,
|
||||
);
|
||||
final first = container.read(projectsProvider).requireValue;
|
||||
final session = await projects.openTimelineSession(
|
||||
first.activeProject!.id,
|
||||
first.timeline!.id,
|
||||
);
|
||||
final view = session.view(session.activeSequenceId!);
|
||||
view.seekTo(100);
|
||||
expect(
|
||||
await projects.open('${root.path}/Two.cutdex', name: 'Two'),
|
||||
isTrue,
|
||||
);
|
||||
final second = container
|
||||
.read(projectsProvider)
|
||||
.requireValue
|
||||
.activeProject!;
|
||||
expect(
|
||||
container.read(projectTabsProvider).map((project) => project.id),
|
||||
[first.activeProject!.id, second.id],
|
||||
);
|
||||
expect(await projects.closeActiveProject(), isTrue);
|
||||
tabs.remove(second.id);
|
||||
final closed = container.read(projectsProvider).requireValue;
|
||||
expect(closed.activeProject, isNull);
|
||||
expect(closed.timeline, isNull);
|
||||
expect(closed.assets, isEmpty);
|
||||
expect(closed.recent.length, 2);
|
||||
expect(await File('${second.path}/manifest.json').exists(), isTrue);
|
||||
expect(await projects.open(first.activeProject!.path), isTrue);
|
||||
final reopened = await projects.openTimelineSession(
|
||||
first.activeProject!.id,
|
||||
first.timeline!.id,
|
||||
);
|
||||
expect(reopened, same(session));
|
||||
expect(reopened.view(reopened.activeSequenceId!), same(view));
|
||||
expect(view.playheadTick, 100);
|
||||
expect(
|
||||
container.read(projectTabsProvider).map((project) => project.id),
|
||||
[first.activeProject!.id],
|
||||
);
|
||||
} finally {
|
||||
await projects.prepareToQuit();
|
||||
container.dispose();
|
||||
await root.delete(recursive: true);
|
||||
}
|
||||
},
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,178 @@
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:cutdex/errors/app_failure.dart';
|
||||
import 'package:cutdex/integrations/platform/device_experience.dart';
|
||||
import 'package:cutdex/persistence/app_settings_repositories.dart';
|
||||
import 'package:cutdex/workspace/persistence/recent_projects.dart';
|
||||
import 'package:cutdex/workspace/projects.dart';
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
|
||||
import '../support/memory_app_settings.dart';
|
||||
|
||||
void main() {
|
||||
TestWidgetsFlutterBinding.ensureInitialized();
|
||||
|
||||
group('project creation collisions', () {
|
||||
late Directory root;
|
||||
late ProviderContainer container;
|
||||
late Projects projects;
|
||||
|
||||
setUp(() async {
|
||||
root = await Directory.systemTemp.createTemp('cutdex-name-conflict-');
|
||||
container = ProviderContainer(
|
||||
overrides: [
|
||||
deviceExperienceProvider.overrideWithValue(DeviceExperience.desktop),
|
||||
recentProjectsProvider.overrideWithValue(
|
||||
MemoryRecentProjectsRepository(),
|
||||
),
|
||||
projectLocationSettingsRepositoryProvider.overrideWithValue(
|
||||
DefaultingProjectLocationSettingsRepository(
|
||||
MemoryProjectLocationSettingsRepository(root.path),
|
||||
),
|
||||
),
|
||||
resourceLocationSettingsRepositoryProvider.overrideWithValue(
|
||||
MemoryResourceLocationSettingsRepository(root.path),
|
||||
),
|
||||
],
|
||||
);
|
||||
projects = container.read(projectsProvider.notifier);
|
||||
});
|
||||
|
||||
tearDown(() async {
|
||||
await projects.prepareToQuit();
|
||||
container.dispose();
|
||||
await root.delete(recursive: true);
|
||||
});
|
||||
|
||||
test(
|
||||
'duplicate creation preserves the existing project and session',
|
||||
() async {
|
||||
expect(
|
||||
await projects.createProject('One', initialTimelineName: 'Timeline'),
|
||||
isTrue,
|
||||
);
|
||||
final before = container.read(projectsProvider).requireValue;
|
||||
final project = before.activeProject!;
|
||||
final session = await projects.openTimelineSession(
|
||||
project.id,
|
||||
before.timeline!.id,
|
||||
);
|
||||
final manifest = File('${project.path}/manifest.json');
|
||||
final contents = await manifest.readAsString();
|
||||
expect(
|
||||
(await projects.validateNewProjectName(' One '))?.code,
|
||||
AppErrorCode.projectAlreadyExists,
|
||||
);
|
||||
expect(container.read(projectsProvider).requireValue.error, isNull);
|
||||
|
||||
expect(
|
||||
await projects.createProject(
|
||||
' One ',
|
||||
initialTimelineName: 'Replacement',
|
||||
),
|
||||
isFalse,
|
||||
);
|
||||
final after = container.read(projectsProvider).requireValue;
|
||||
expect(after.error?.code, AppErrorCode.projectAlreadyExists);
|
||||
expect(after.activeProject?.id, project.id);
|
||||
expect(after.timeline?.id, before.timeline?.id);
|
||||
expect(after.recent, before.recent);
|
||||
expect(await manifest.readAsString(), contents);
|
||||
expect(
|
||||
await projects.openTimelineSession(project.id, before.timeline!.id),
|
||||
same(session),
|
||||
);
|
||||
|
||||
expect(await projects.validateNewProjectName('Two'), isNull);
|
||||
expect(
|
||||
await projects.createProject('Two', initialTimelineName: 'Timeline'),
|
||||
isTrue,
|
||||
);
|
||||
expect(container.read(projectsProvider).requireValue.error, isNull);
|
||||
expect(
|
||||
container.read(projectsProvider).requireValue.activeProject?.name,
|
||||
'Two',
|
||||
);
|
||||
expect(await manifest.readAsString(), contents);
|
||||
},
|
||||
);
|
||||
|
||||
test(
|
||||
'creation detects a destination occupied after name validation',
|
||||
() async {
|
||||
expect(await projects.validateNewProjectName('Racing'), isNull);
|
||||
final destination = File('${root.path}/Racing.cutdex');
|
||||
await destination.writeAsString('created by another operation');
|
||||
expect(
|
||||
await projects.createProject(
|
||||
'Racing',
|
||||
initialTimelineName: 'Timeline',
|
||||
),
|
||||
isFalse,
|
||||
);
|
||||
expect(
|
||||
container.read(projectsProvider).requireValue.error?.code,
|
||||
AppErrorCode.projectAlreadyExists,
|
||||
);
|
||||
expect(
|
||||
await destination.readAsString(),
|
||||
'created by another operation',
|
||||
);
|
||||
},
|
||||
);
|
||||
|
||||
for (final type in ['file', 'directory', 'broken link']) {
|
||||
test('occupied $type is reported without replacing it', () async {
|
||||
final destination = '${root.path}/Occupied.cutdex';
|
||||
switch (type) {
|
||||
case 'file':
|
||||
await File(destination).writeAsString('keep this file');
|
||||
case 'directory':
|
||||
await Directory(destination).create();
|
||||
await File('$destination/keep.txt')
|
||||
.writeAsString('keep this directory');
|
||||
case 'broken link':
|
||||
await Link(destination).create('${root.path}/missing-target');
|
||||
}
|
||||
final before = await FileSystemEntity.type(
|
||||
destination,
|
||||
followLinks: false,
|
||||
);
|
||||
expect(
|
||||
(await projects.validateNewProjectName('Occupied'))?.code,
|
||||
AppErrorCode.projectAlreadyExists,
|
||||
);
|
||||
expect(
|
||||
await projects.createProject(
|
||||
'Occupied',
|
||||
initialTimelineName: 'Timeline',
|
||||
),
|
||||
isFalse,
|
||||
);
|
||||
final state = container.read(projectsProvider).requireValue;
|
||||
expect(state.error?.code, AppErrorCode.projectAlreadyExists);
|
||||
expect(state.activeProject, isNull);
|
||||
expect(state.recent, isEmpty);
|
||||
expect(
|
||||
await FileSystemEntity.type(destination, followLinks: false),
|
||||
before,
|
||||
);
|
||||
switch (type) {
|
||||
case 'file':
|
||||
expect(await File(destination).readAsString(), 'keep this file');
|
||||
case 'directory':
|
||||
expect(
|
||||
await File('$destination/keep.txt').readAsString(),
|
||||
'keep this directory',
|
||||
);
|
||||
case 'broken link':
|
||||
expect(
|
||||
await Link(destination).target(),
|
||||
'${root.path}/missing-target',
|
||||
);
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -1,3 +1,5 @@
|
||||
import 'package:cutdex/workspace/timeline_session.dart';
|
||||
|
||||
import 'dart:async';
|
||||
import 'dart:io';
|
||||
|
||||
@@ -209,7 +211,13 @@ void main() {
|
||||
|
||||
testWidgets('pending tabs accept a newer real click', (tester) async {
|
||||
final widgetContainer = ProviderContainer(
|
||||
overrides: [projectsProvider.overrideWith(_PendingProjects.new)],
|
||||
overrides: [
|
||||
projectsProvider.overrideWith(_PendingProjects.new),
|
||||
editorTimelineProvider(
|
||||
'project',
|
||||
'a',
|
||||
).overrideWith((ref) => Completer<EditorTimelineSession>().future),
|
||||
],
|
||||
);
|
||||
addTearDown(widgetContainer.dispose);
|
||||
await tester.pumpWidget(
|
||||
@@ -226,7 +234,7 @@ void main() {
|
||||
if (state == null) return const SizedBox();
|
||||
return EditorWorkspace(
|
||||
projectId: 'project',
|
||||
timelineId: state.visibleTimelineId!,
|
||||
timelineId: state.timeline!.id,
|
||||
projectName: 'Project',
|
||||
integratedTitlebar: false,
|
||||
headerLeading: const SizedBox(),
|
||||
@@ -247,7 +255,7 @@ void main() {
|
||||
final panel = tester.widget<EditorTimelinePanel>(
|
||||
find.byType(EditorTimelinePanel),
|
||||
);
|
||||
expect(panel.timelineId, 'b');
|
||||
expect(panel.timelineId, 'a');
|
||||
await tester.tap(find.byKey(const ValueKey('timeline-tab-c')));
|
||||
await tester.pump();
|
||||
expect(
|
||||
@@ -258,7 +266,7 @@ void main() {
|
||||
tester
|
||||
.widget<EditorTimelinePanel>(find.byType(EditorTimelinePanel))
|
||||
.timelineId,
|
||||
'c',
|
||||
'a',
|
||||
);
|
||||
await tester.pumpWidget(const SizedBox());
|
||||
});
|
||||
|
||||
@@ -13,6 +13,7 @@ void main() {
|
||||
var showHandle = true;
|
||||
var taps = 0;
|
||||
var ends = 0;
|
||||
var starts = 0;
|
||||
var updates = 0;
|
||||
late StateSetter update;
|
||||
await tester.pumpWidget(
|
||||
@@ -47,7 +48,11 @@ void main() {
|
||||
key: const Key('handle'),
|
||||
axis: axis,
|
||||
initialValue: 100,
|
||||
onResize: (_) => updates++,
|
||||
onStart: () => starts++,
|
||||
onResize: (_) {
|
||||
expect(starts, 1);
|
||||
updates++;
|
||||
},
|
||||
onEnd: () => ends++,
|
||||
),
|
||||
),
|
||||
@@ -70,6 +75,7 @@ void main() {
|
||||
await mouse.moveTo(button);
|
||||
await tester.pump();
|
||||
expect(updates, greaterThan(0));
|
||||
expect(starts, 1);
|
||||
expect(
|
||||
RendererBinding.instance.mouseTracker.debugDeviceActiveCursor(1),
|
||||
axis == Axis.horizontal
|
||||
|
||||
Reference in new issue
Block a user