Files
cutdex/test/adaptive_workspace_test.dart
T
lingjhf 06f1c26681
Gitea CI / Assemble and validate CI artifacts (push) Successful in 1m47s
Gitea CI / Check code and tests (push) Successful in 7m15s
Gitea CI / Build Android APK (push) Successful in 4m6s
Gitea CI / Build Windows x64 app (push) Successful in 3m34s
Gitea CI / Audit and package Windows x64 (push) Successful in 1m29s
Gitea CI / Gitea CI passed (push) Successful in 1s
Gitea Release / Prepare draft Release (push) Failing after 8s
Gitea Release / Upload Android to draft Release (push) Skipped
Gitea Release / Upload Windows to draft Release (push) Skipped
Gitea Release / Verify and publish Release (push) Skipped
Move editor UI into the app and release verified Core dependencies (#14)
2026-10-11 19:59:40 +00:00

2463 lines
93 KiB
Dart

import 'package:cutdex/errors/app_failure.dart';
import 'package:cutdex/features/settings/appearance_settings.dart';
import 'dart:async';
import 'package:cutdex/features/assistant/agent_composer_store.dart';
import 'package:cutdex/features/assistant/floating_agent_panel.dart';
import 'package:cutdex/features/assistant/chat_controller.dart';
import 'package:cutdex/features/projects/conversation_sidebar.dart';
import 'package:cutdex/integrations/platform/file_picker.dart';
import 'package:cutdex/workspace/external_media_import.dart';
import 'package:cutdex/workspace/media_import.dart';
import 'package:cutdex/app/adaptive/workspace_layout_policy.dart';
import 'package:cutdex/app/app.dart';
import 'package:cutdex/features/assistant/agent_chat_panel.dart';
import 'package:cutdex/features/editor/editor_page.dart';
import 'package:cutdex/features/media/media_browser_controller.dart';
import 'package:cutdex/features/media/media_browser_page.dart';
import 'package:cutdex/features/media/media_panel.dart';
import 'package:cutdex/features/media/media_browser_body.dart';
import 'package:cutdex/features/media/resource_navigation.dart';
import 'package:cutdex/features/properties/properties_editor_page.dart';
import 'package:cutdex/features/properties/properties_panel.dart';
import 'package:cutdex/features/preview/preview_panel.dart';
import 'package:cutdex/features/timeline/timeline_panel.dart';
import 'package:cutdex/integrations/agent/conversation_repository.dart';
import 'package:cutdex/integrations/platform/device_experience.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/workspace/media_availability.dart';
import 'package:cutdex/workspace/project_state.dart';
import 'package:cutdex/workspace/projects.dart';
import 'package:cutdex/workspace/preview_target.dart';
import 'package:cutdex/workspace/timeline_provider.dart';
import 'package:cutdex/workspace/timeline_session.dart';
import 'package:cutdex/workspace/view_settings.dart';
import 'package:cutdex/workspace/workspace_mode.dart';
import 'package:cutdex_core/project.dart';
import 'package:cutdex_core/timeline/model.dart';
import 'package:cutdex_core/timeline/engine.dart';
import 'package:cutdex_core/timeline/layout.dart';
import 'package:drift/native.dart';
import 'package:cutdex_ui/icons.dart';
import 'package:cutdex_ui/theme.dart';
import 'package:cutdex_ui/widgets.dart';
import 'package:flutter/material.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter/services.dart';
import 'package:flutter/gestures.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';
Future<void> floatOrDockChat(WidgetTester tester) async {
await tester.tap(find.byKey(const Key('agent-minimize-button')));
}
void main() {
test('space classes and two-pane decisions do not depend on workflow', () {
expect(WorkspaceLayoutPolicy.desktopNavigationFits(541), isFalse);
expect(WorkspaceLayoutPolicy.desktopNavigationFits(542), isTrue);
expect(WorkspaceLayoutPolicy.showAgentBesideEditor(839), isFalse);
expect(WorkspaceLayoutPolicy.showAgentBesideEditor(840), isTrue);
});
Future<
({
ProviderContainer container,
EditorTimelineSession session,
String projectId,
Future<void> Function() close,
})
>
mount(
WidgetTester tester,
Size size, {
DeviceExperience experience = DeviceExperience.desktop,
MediaFileResolver? delayedResolver,
AppFilePicker? picker,
ConversationRepository? conversations,
MediaImportResult? importResult,
PreviewTarget? previewTarget,
}) async {
tester.view.physicalSize = size;
tester.view.devicePixelRatio = 1;
addTearDown(tester.view.resetPhysicalSize);
addTearDown(tester.view.resetDevicePixelRatio);
final fixture = (await tester.runAsync(
() =>
createPreviewFixture(Uri.file('/test/photo.png'), mediaType: 'image'),
))!;
final database = AppDatabase(NativeDatabase.memory());
final projectId = fixture.workspace.project!.info.id;
final container = ProviderContainer(
overrides: [
deviceExperienceProvider.overrideWithValue(experience),
if (picker != null) filePickerProvider.overrideWithValue(picker),
if (delayedResolver != null)
mediaFileResolverProvider.overrideWithValue(delayedResolver),
appDatabaseProvider.overrideWithValue(database),
appearanceSettingsRepositoryProvider.overrideWithValue(
MemoryAppearanceSettingsRepository(),
),
paletteSettingsRepositoryProvider.overrideWithValue(
MemoryPaletteSettingsRepository(),
),
timelineViewSettingsRepositoryProvider.overrideWithValue(
_TimelineViewRepository(),
),
projectsProvider.overrideWith(
() => _FixtureProjects(projectId, fixture.timeline, importResult),
),
conversationRepositoryProvider.overrideWith(
(ref) async => conversations ?? EmptyConversationRepository(),
),
editorPreviewProvider.overrideWith((ref, ids) => null),
if (previewTarget != null)
previewTargetProvider.overrideWith((ref, ids) {
ref.onDispose(previewTarget.dispose);
return previewTarget;
}),
mediaAvailabilityProvider.overrideWith(
(ref, ids) async => MediaAvailability.missing,
),
],
);
var closed = false;
Future<void> close() async {
if (closed) return;
closed = true;
await tester.pump();
await tester.pumpWidget(const SizedBox());
container.dispose();
await tester.pump();
await tester.runAsync(() async {
await fixture.workspace.close();
await fixture.directory.delete(recursive: true);
await database.close();
});
}
addTearDown(close);
// The app owns the scope; this harness deliberately provides its container.
// ignore: riverpod_lint/provider_scope_placement
await tester.pumpWidget(
UncontrolledProviderScope(container: container, child: const CutdexApp()),
);
await tester.pumpAndSettle();
return (
container: container,
session: fixture.timeline,
projectId: projectId,
close: close,
);
}
Future<void> setMode(
WidgetTester tester,
ProviderContainer container,
WorkspaceMode mode,
) async {
container.read(workspaceViewSettingsProvider.notifier).setMode(mode);
await tester.pumpAndSettle();
}
testWidgets('desktop project hierarchy separates chat, media and timeline', (
tester,
) async {
final mounted = await mount(tester, const Size(1200, 800));
final header = tester.getRect(
find.byKey(const Key('desktop-window-header')),
);
final projectTab = find.byKey(ValueKey('project-tab-${mounted.projectId}'));
expect(header.contains(tester.getCenter(projectTab)), isTrue);
expect(find.byKey(const Key('sidebar-tab-chat')), findsNothing);
expect(find.byKey(const Key('sidebar-tab-resources')), findsNothing);
expect(find.byKey(const Key('desktop-navigation-rail')), findsOneWidget);
expect(find.byKey(const Key('media-project-button')), findsNothing);
expect(find.byKey(const Key('media-panel-close')), findsNothing);
final mediaHeader = find.byKey(const Key('media-panel-header'));
final l10n = AppLocalizations.of(tester.element(mediaHeader))!;
expect(
find.descendant(of: mediaHeader, matching: find.text(l10n.materials)),
findsNothing,
);
final chat = tester.element(find.byType(AgentChatPanel));
final editor = tester.element(find.byType(EditorWorkspace));
final input = find.descendant(
of: find.byType(AgentChatPanel),
matching: find.byType(TextField),
);
await tester.enterText(input, 'Keep project chat draft');
final media = tester.getRect(find.byKey(const Key('editor-media-card')));
final preview = tester.getRect(
find.byKey(const Key('editor-preview-card')),
);
final timeline = tester.getRect(
find.byKey(const Key('editor-timeline-card')),
);
final chatRect = tester.getRect(find.byKey(const Key('desktop-chat-card')));
expect(media.left - chatRect.right, 2);
expect(preview.left - media.right, 2);
expect(timeline.top - media.bottom, 2);
final content = tester.getRect(
find.byKey(const Key('desktop-content-container')),
);
expect(content.left, 46);
expect(content.right, 1198);
expect(content.bottom, 798);
expect(media.top, preview.top);
expect(timeline.left, media.left);
expect(timeline.right, preview.right);
final previewElement = tester.element(find.byType(EditorPreviewPanel));
await tester.drag(
find.byKey(const Key('editor-media-resize')),
const Offset(60, 0),
);
await tester.pumpAndSettle();
expect(
tester.getSize(find.byKey(const Key('editor-media-card'))).width,
media.width + 60,
);
await tester.drag(
find.byKey(const Key('editor-media-timeline-junction')),
const Offset(40, -30),
);
await tester.pumpAndSettle();
final resizedSettings = mounted.container
.read(projectViewSettingsProvider(mounted.projectId))
.requireValue;
expect(resizedSettings.mediaWidth, media.width + 100);
expect(resizedSettings.timelineHeight, closeTo(timeline.height + 30, .01));
expect(
tester.getSize(find.byKey(const Key('editor-timeline-card'))).height,
closeTo(timeline.height + 30, .01),
);
expect(
mounted.container
.read(projectViewSettingsProvider(mounted.projectId))
.requireValue
.mediaWidth,
media.width + 100,
);
await tester.tap(find.byKey(const Key('editor-media-button')));
await tester.pumpAndSettle();
expect(find.byType(MediaPanel), findsNothing);
expect(
tester.element(find.byType(EditorPreviewPanel)),
same(previewElement),
);
await tester.tap(find.byKey(const Key('editor-media-button')));
await tester.pumpAndSettle();
expect(find.byType(MediaPanel), findsOneWidget);
expect(
tester.getSize(find.byKey(const Key('editor-media-card'))).width,
media.width + 100,
);
expect(tester.element(find.byType(AgentChatPanel)), same(chat));
expect(tester.element(find.byType(EditorWorkspace)), same(editor));
expect(
tester.widget<TextField>(input).controller!.text,
'Keep project chat draft',
);
expect(tester.takeException(), isNull);
await mounted.close();
});
testWidgets(
'chat/timeline junction resizes both axes, persists and follows docking',
(tester) async {
final mounted = await mount(tester, const Size(1800, 800));
final junction = find.byKey(const Key('desktop-chat-timeline-junction'));
Rect card(String name) => tester.getRect(find.byKey(Key(name)));
final chat = card('desktop-chat-card');
final media = card('editor-media-card');
final timeline = card('editor-timeline-card');
final center = tester.getCenter(junction);
expect(center.dx, (chat.right + media.left) / 2);
expect(center.dy, (media.bottom + timeline.top) / 2);
final editorElement = tester.element(find.byType(EditorWorkspace));
final mediaElement = tester.element(find.byType(MediaPanel));
final input = find.descendant(
of: find.byType(AgentChatPanel),
matching: find.byType(TextField),
);
await tester.enterText(input, 'Keep draft while resizing the junction');
await tester.drag(junction, const Offset(60, -50));
await tester.pumpAndSettle();
expect(card('desktop-chat-card').width, chat.width + 60);
expect(
card('editor-timeline-card').height,
closeTo(timeline.height + 50, .01),
);
expect(card('editor-media-card').width, media.width);
expect(
mounted.container
.read(workspaceViewSettingsProvider)
.requireValue
.sidebarWidth,
chat.width + 60,
);
expect(
mounted.container
.read(projectViewSettingsProvider(mounted.projectId))
.requireValue
.timelineHeight,
closeTo(timeline.height + 50, .01),
);
final savedWorkspace = await tester.runAsync(
mounted.container.read(workspaceViewSettingsRepositoryProvider).load,
);
final savedProject = await tester.runAsync(
() => mounted.container
.read(projectViewSettingsRepositoryProvider)
.load(mounted.projectId),
);
expect(savedWorkspace!.sidebarWidth, chat.width + 60);
expect(savedProject!.timelineHeight, closeTo(timeline.height + 50, .01));
await tester.drag(junction, const Offset(-40, 30));
await tester.pumpAndSettle();
expect(card('desktop-chat-card').width, chat.width + 20);
expect(
card('editor-timeline-card').height,
closeTo(timeline.height + 20, .01),
);
await tester.drag(junction, const Offset(-100, -2000));
await tester.pumpAndSettle();
expect(card('desktop-chat-card').width, 220);
expect(card('editor-preview-card').height, 180);
await tester.drag(junction, const Offset(40, -60));
await tester.pumpAndSettle();
expect(card('desktop-chat-card').width, 260);
expect(card('editor-preview-card').height, 180);
await tester.drag(junction, const Offset(2000, 2000));
await tester.pumpAndSettle();
expect(card('desktop-chat-card').width, 320);
expect(card('editor-timeline-card').height, 220);
expect(tester.element(find.byType(EditorWorkspace)), same(editorElement));
expect(tester.element(find.byType(MediaPanel)), same(mediaElement));
expect(
tester.widget<TextField>(input).controller!.text,
'Keep draft while resizing the junction',
);
await tester.tap(find.byKey(const Key('project-sidebar-toggle')));
await tester.pumpAndSettle();
expect(junction, findsOneWidget);
await tester.tap(find.byKey(const Key('project-sidebar-toggle')));
await tester.pumpAndSettle();
expect(junction, findsOneWidget);
expect(card('desktop-chat-card').width, 320);
expect(card('editor-timeline-card').height, 220);
await floatOrDockChat(tester);
await tester.pumpAndSettle();
expect(junction, findsNothing);
await floatOrDockChat(tester);
await tester.pumpAndSettle();
expect(junction, findsOneWidget);
// The same T remains between chat, preview and timeline with media hidden.
await tester.tap(find.byKey(const Key('editor-media-button')));
await tester.pumpAndSettle();
expect(junction, findsOneWidget);
await tester.drag(junction, const Offset(-40, -30));
await tester.pumpAndSettle();
expect(card('desktop-chat-card').width, 280);
expect(card('editor-timeline-card').height, 250);
tester.view.physicalSize = const Size(600, 360);
await tester.pumpAndSettle();
final narrowCenter = tester.getCenter(junction);
expect(
narrowCenter.dy,
(card('editor-preview-card').bottom +
card('editor-timeline-card').top) /
2,
);
await tester.drag(junction, const Offset(2000, -2000));
await tester.pumpAndSettle();
expect(card('editor-preview-card').height, 180);
expect(card('desktop-editor-card').width, 320);
expect(tester.takeException(), isNull);
await mounted.close();
},
);
for (final junctionDrag in [false, true]) {
testWidgets(
'${junctionDrag ? 'junction' : 'sidebar'} persists resize only when the gesture ends',
(tester) async {
final mounted = await mount(tester, const Size(1800, 800));
final repository = mounted.container.read(
workspaceViewSettingsRepositoryProvider,
);
final savedBefore = (await tester.runAsync(repository.load))!;
final sidebar = find.byKey(const Key('desktop-chat-card'));
final initialWidth = tester.getSize(sidebar).width;
final handle = find.byKey(
Key(
junctionDrag
? 'desktop-chat-timeline-junction'
: 'project-sidebar-resize',
),
);
final drag = await tester.startGesture(
tester.getCenter(handle),
kind: PointerDeviceKind.mouse,
);
for (var i = 0; i < 5; i++) {
await drag.moveBy(Offset(10, junctionDrag ? -10 : 0));
await tester.pumpAndSettle();
}
expect(tester.getSize(sidebar).width, initialWidth + 50);
final savedDuring = (await tester.runAsync(repository.load))!;
expect(savedDuring.sidebarWidth, savedBefore.sidebarWidth);
// Cancellation also commits the last visible size.
if (junctionDrag) {
await drag.cancel();
} else {
await drag.up();
}
await tester.pumpAndSettle();
final savedAfter = (await tester.runAsync(repository.load))!;
expect(savedAfter.sidebarWidth, initialWidth + 50);
await mounted.close();
},
);
}
for (final junctionDrag in [false, true]) {
testWidgets(
'${junctionDrag ? 'junction' : 'sidebar'} drag snaps closed and can drag back open',
(tester) async {
final mounted = await mount(tester, const Size(1800, 800));
final sidebar = find.byKey(const Key('desktop-chat-card'));
final resize = find.byKey(const Key('project-sidebar-resize'));
final junction = find.byKey(
const Key('desktop-chat-timeline-junction'),
);
final initialWidth = tester.getSize(sidebar).width;
final initialTimeline = tester
.getSize(find.byKey(const Key('editor-timeline-card')))
.height;
final editor = tester.element(find.byType(EditorWorkspace));
final input = find.descendant(
of: find.byType(AgentChatPanel),
matching: find.byType(TextField),
);
await tester.enterText(input, 'Draft survives sidebar snapping');
final start = tester.getCenter(junctionDrag ? junction : resize);
final drag = await tester.startGesture(
start,
kind: PointerDeviceKind.mouse,
);
await drag.moveTo(
start + Offset(115 - initialWidth, junctionDrag ? -30 : 0),
);
await tester.pumpAndSettle();
expect(tester.getSize(sidebar).width, 220);
await drag.moveBy(Offset(-6, junctionDrag ? -20 : 0));
await tester.pumpAndSettle();
expect(sidebar, findsNothing);
expect(resize, findsOneWidget);
expect(
mounted.container
.read(workspaceViewSettingsProvider)
.requireValue
.sidebarCollapsed,
isTrue,
);
// Crossing back over the threshold within the same gesture restores it.
await drag.moveBy(const Offset(16, 0));
await tester.pumpAndSettle();
expect(tester.getSize(sidebar).width, 220);
await drag.moveBy(Offset(-16, junctionDrag ? -20 : 0));
await tester.pumpAndSettle();
expect(sidebar, findsNothing);
if (junctionDrag) {
expect(junction, findsOneWidget);
expect(
tester
.getSize(find.byKey(const Key('editor-timeline-card')))
.height,
closeTo(initialTimeline + 70, .01),
);
await drag.cancel();
} else {
await drag.up();
}
await tester.pumpAndSettle();
expect(junction, findsOneWidget);
final saved = await tester.runAsync(
mounted.container.read(workspaceViewSettingsRepositoryProvider).load,
);
expect(saved!.sidebarCollapsed, isTrue);
expect(saved.sidebarWidth, initialWidth);
if (junctionDrag) {
final savedProject = await tester.runAsync(
() => mounted.container
.read(projectViewSettingsRepositoryProvider)
.load(mounted.projectId),
);
expect(
savedProject!.timelineHeight,
closeTo(initialTimeline + 70, .01),
);
}
await tester.tap(find.byKey(const Key('project-sidebar-toggle')));
await tester.pumpAndSettle();
expect(tester.getSize(sidebar).width, initialWidth);
expect(tester.element(find.byType(EditorWorkspace)), same(editor));
expect(
tester.widget<TextField>(input).controller!.text,
'Draft survives sidebar snapping',
);
await tester.tap(find.byKey(const Key('project-sidebar-toggle')));
await tester.pumpAndSettle();
// A fresh edge or junction drag starts from the collapsed width of zero.
final edgeTimeline = tester
.getSize(find.byKey(const Key('editor-timeline-card')))
.height;
expect(junction, findsOneWidget);
final edge = await tester.startGesture(
tester.getCenter(junctionDrag ? junction : resize),
kind: PointerDeviceKind.mouse,
);
await edge.moveBy(Offset(109, junctionDrag ? -25 : 0));
await tester.pumpAndSettle();
expect(sidebar, findsNothing);
if (junctionDrag) {
expect(
tester
.getSize(find.byKey(const Key('editor-timeline-card')))
.height,
closeTo(edgeTimeline + 25, .01),
);
}
await edge.moveBy(const Offset(1, 0));
await tester.pumpAndSettle();
expect(tester.getSize(sidebar).width, 220);
await edge.moveBy(const Offset(140, 0));
await tester.pumpAndSettle();
expect(tester.getSize(sidebar).width, 250);
await edge.up();
await tester.pumpAndSettle();
expect(
mounted.container
.read(workspaceViewSettingsProvider)
.requireValue
.sidebarCollapsed,
isFalse,
);
final reopened = await tester.runAsync(
mounted.container.read(workspaceViewSettingsRepositoryProvider).load,
);
expect(reopened!.sidebarCollapsed, isFalse);
expect(reopened.sidebarWidth, 250);
if (junctionDrag) {
final reopenedProject = await tester.runAsync(
() => mounted.container
.read(projectViewSettingsRepositoryProvider)
.load(mounted.projectId),
);
expect(
reopenedProject!.timelineHeight,
closeTo(edgeTimeline + 25, .01),
);
}
expect(
tester.widget<TextField>(input).controller!.text,
'Draft survives sidebar snapping',
);
expect(tester.takeException(), isNull);
await mounted.close();
},
);
}
testWidgets('project tabs switch scoped drafts and preserve failed close', (
tester,
) async {
final mounted = await mount(tester, const Size(1800, 800));
final projects =
mounted.container.read(projectsProvider.notifier) as _FixtureProjects;
projects.addRecent();
await tester.pumpAndSettle();
expect(find.byKey(const ValueKey('project-tab-other')), findsNothing);
final input = find.descendant(
of: find.byKey(const Key('agent-composer')),
matching: find.byType(TextField),
);
await tester.enterText(input, 'Draft in first project');
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.pumpAndSettle();
expect(
mounted.container.read(projectsProvider).requireValue.activeProject?.id,
'other',
);
expect(find.byKey(const ValueKey('project-tab-other')), findsOneWidget);
expect(tester.widget<TextField>(input).controller!.text, isEmpty);
await tester.enterText(input, 'Draft in second project');
await tester.tap(find.byKey(ValueKey('project-tab-${mounted.projectId}')));
await tester.pumpAndSettle();
expect(
tester.widget<TextField>(input).controller!.text,
'Draft in first project',
);
await tester.tap(
find.byKey(ValueKey('project-tab-close-${mounted.projectId}')),
);
await tester.pumpAndSettle();
expect(
find.byKey(ValueKey('project-tab-${mounted.projectId}')),
findsNothing,
);
expect(
mounted.container.read(projectsProvider).requireValue.activeProject?.id,
'other',
);
expect(
tester.widget<TextField>(input).controller!.text,
'Draft in second project',
);
projects.closeSucceeds = false;
await tester.tap(find.byKey(const ValueKey('project-tab-close-other')));
await tester.pumpAndSettle();
expect(find.byKey(const ValueKey('project-tab-other')), findsOneWidget);
expect(
mounted.container.read(projectsProvider).requireValue.activeProject?.id,
'other',
);
projects.closeSucceeds = true;
await tester.tap(find.byKey(const ValueKey('project-tab-close-other')));
await tester.pumpAndSettle();
expect(
mounted.container.read(projectsProvider).requireValue.activeProject,
isNull,
);
expect(find.byKey(const ValueKey('project-tab-other')), findsNothing);
expect(
mounted.container.read(projectsProvider).requireValue.recent.length,
2,
);
await tester.tap(find.byKey(const Key('project-tabs-projects')));
await tester.pumpAndSettle();
await tester.tap(find.byKey(ValueKey('project-menu-${mounted.projectId}')));
await tester.pumpAndSettle();
expect(
find.byKey(ValueKey('project-tab-${mounted.projectId}')),
findsOneWidget,
);
expect(
tester.widget<TextField>(input).controller!.text,
'Draft in first project',
);
expect(tester.takeException(), isNull);
await mounted.close();
});
testWidgets(
'header tabs survive history removal and close to an opened neighbor',
(tester) async {
final mounted = await mount(tester, const Size(1800, 800));
final projects =
mounted.container.read(projectsProvider.notifier) as _FixtureProjects;
projects.addRecent();
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-other')));
await tester.pumpAndSettle();
projects.forgetRecent(mounted.projectId);
await tester.pumpAndSettle();
expect(
find.byKey(ValueKey('project-tab-${mounted.projectId}')),
findsOneWidget,
);
expect(find.byKey(const ValueKey('project-tab-other')), findsOneWidget);
expect(find.byKey(const Key('project-chat-sidebar')), findsOneWidget);
expect(
find.byKey(const Key('sidebar-projects-conversations')),
findsNothing,
);
await tester.tap(find.byKey(const Key('project-tabs-list')));
await tester.pumpAndSettle();
expect(
find.byKey(ValueKey('project-tabs-menu-${mounted.projectId}')),
findsOneWidget,
);
await tester.tap(
find.byKey(ValueKey('project-tabs-menu-${mounted.projectId}')),
);
await tester.pumpAndSettle();
expect(
mounted.container.read(projectsProvider).requireValue.activeProject?.id,
mounted.projectId,
);
projects.forgetRecent('other');
await tester.pumpAndSettle();
await tester.tap(
find.byKey(ValueKey('project-tab-close-${mounted.projectId}')),
);
await tester.pumpAndSettle();
expect(
mounted.container.read(projectsProvider).requireValue.activeProject?.id,
'other',
);
expect(
find.byKey(ValueKey('project-tab-${mounted.projectId}')),
findsNothing,
);
expect(find.byKey(const ValueKey('project-tab-other')), findsOneWidget);
expect(tester.takeException(), isNull);
await mounted.close();
},
);
testWidgets(
'header controls switch drawer and floating Agent at narrow widths',
(tester) async {
final mounted = await mount(tester, const Size(500, 800));
final sidebar = find.byKey(const Key('project-sidebar-toggle'));
final minimize = find.byKey(const Key('agent-minimize-button'));
await tester.tap(sidebar);
await tester.pumpAndSettle();
expect(find.byType(AgentChatPanel), findsOneWidget);
final input = find.descendant(
of: find.byKey(const Key('agent-composer')),
matching: find.byType(TextField),
);
await tester.enterText(input, 'Narrow header draft');
final controller = tester.widget<TextField>(input).controller;
await tester.tap(minimize);
await tester.pumpAndSettle();
expect(find.byKey(const Key('agent-floating-window')), findsOneWidget);
expect(find.byType(AgentChatPanel), findsNothing);
expect(
tester
.widget<TextField>(find.byKey(const Key('floating-agent-input')))
.controller,
same(controller),
);
await tester.tap(minimize);
await tester.pumpAndSettle();
expect(find.byKey(const Key('agent-floating-window')), findsNothing);
expect(find.byType(AgentChatPanel), findsOneWidget);
expect(
tester.widget<TextField>(input).controller!.text,
'Narrow header draft',
);
await tester.tap(sidebar);
await tester.pumpAndSettle();
expect(find.byType(AgentChatPanel), findsNothing);
await tester.tap(minimize);
await tester.pumpAndSettle();
expect(find.byKey(const Key('agent-floating-window')), findsOneWidget);
await tester.tap(sidebar);
await tester.pumpAndSettle();
expect(find.byKey(const Key('agent-floating-window')), findsNothing);
expect(find.byType(AgentChatPanel), findsOneWidget);
expect(
tester.widget<TextField>(input).controller!.text,
'Narrow header draft',
);
expect(tester.takeException(), isNull);
await mounted.close();
},
);
testWidgets('chat collapse retains draft and editing session', (
tester,
) async {
final mounted = await mount(tester, const Size(1800, 800));
final editor = tester.element(find.byType(EditorWorkspace));
final input = find.descendant(
of: find.byKey(const Key('agent-composer')),
matching: find.byType(TextField),
);
await tester.enterText(input, 'Keep this desktop draft');
final initialWidth = tester
.getSize(find.byKey(const Key('desktop-editor-card')))
.width;
await tester.tap(find.byKey(const Key('project-sidebar-toggle')));
await tester.pumpAndSettle();
expect(find.byKey(const Key('desktop-chat-card')), findsNothing);
expect(
tester.getSize(find.byKey(const Key('desktop-editor-card'))).width,
greaterThan(initialWidth),
);
await tester.tap(find.byKey(const Key('project-sidebar-toggle')));
await tester.pumpAndSettle();
expect(find.byKey(const Key('desktop-chat-card')), findsOneWidget);
expect(
tester.getSize(find.byKey(const Key('desktop-editor-card'))).width,
initialWidth,
);
expect(
tester.widget<TextField>(input).controller!.text,
'Keep this desktop draft',
);
tester.view.physicalSize = const Size(900, 800);
await tester.pumpAndSettle();
expect(find.byKey(const Key('agent-floating-window')), findsNothing);
expect(find.byType(EditorWorkspace), findsOneWidget);
expect(
tester.widget<TextField>(input).controller!.text,
'Keep this desktop draft',
);
tester.view.physicalSize = const Size(1800, 800);
await tester.pumpAndSettle();
expect(tester.element(find.byType(EditorWorkspace)), same(editor));
expect(
mounted.container
.read(editorTimelineProvider(mounted.projectId, 'project'))
.value,
same(mounted.session),
);
expect(tester.takeException(), isNull);
await mounted.close();
});
testWidgets(
'desktop workspace retains layout and playback controls in all six themes',
(tester) async {
final mounted = await mount(tester, const Size(1440, 900));
await setMode(tester, mounted.container, WorkspaceMode.cut);
await tester.tap(find.byKey(const Key('editor-properties-button')));
await tester.pumpAndSettle();
final editor = tester.element(find.byType(EditorWorkspace));
for (final palette in AppPalette.values) {
for (final appearance in [
AppAppearance.penLight,
AppAppearance.penDark,
]) {
await mounted.container
.read(paletteSettingsProvider.notifier)
.setPalette(palette);
await mounted.container
.read(appearanceSettingsProvider.notifier)
.setMode(appearance);
await tester.pumpAndSettle();
final preview = tester.getRect(
find.byKey(const Key('editor-preview-card')),
);
final properties = tester.getRect(
find.byKey(const Key('editor-properties-region')),
);
final playback = tester.getRect(
find.byKey(const Key('preview-toolbar')),
);
expect(preview.top, properties.top);
expect(preview.bottom, properties.bottom);
expect(properties.left - preview.right, 2);
expect(playback.bottom, preview.bottom - 1);
expect(playback.height, 32);
expect(
tester.getSize(find.byKey(const Key('timeline-tabs-bar'))).height,
32,
);
final tabBackground = tester
.widget<ColoredBox>(
find.byKey(const Key('timeline-tabs-background')),
)
.color;
expect(
tabBackground,
isNot(
Theme.of(
tester.element(find.byKey(const Key('timeline-toolbar'))),
).colorScheme.surface,
),
reason: 'Tabs and commands have distinct surfaces in every theme',
);
expect(
tester.getSize(find.byKey(const Key('timeline-toolbar'))).height,
32,
);
expect(tester.element(find.byType(EditorWorkspace)), same(editor));
expect(AppColors.of(Theme.of(editor)).family, palette);
expect(tester.takeException(), isNull);
}
}
await mounted.close();
},
);
testWidgets('header floats and docks Agent without losing its draft', (
tester,
) async {
tester.platformDispatcher.platformBrightnessTestValue = Brightness.dark;
addTearDown(tester.platformDispatcher.clearPlatformBrightnessTestValue);
final mounted = await mount(tester, const Size(1800, 800));
expect(
find.descendant(
of: find.byKey(const Key('desktop-window-header')),
matching: find.byKey(const Key('agent-minimize-button')),
),
findsOneWidget,
);
expect(find.byKey(const Key('agent-fullscreen-button')), findsNothing);
final editor = tester.element(find.byType(EditorWorkspace));
final selection = mounted.container.read(
conversationSelectionProvider(mounted.projectId),
);
final chatProvider = chatControllerProvider(
mounted.projectId,
conversationId: selection.selectedId,
draftKey: selection.selectedId == null ? selection.draftKey : null,
);
final chatController = mounted.container.read(chatProvider.notifier);
final input = find.descendant(
of: find.byKey(const Key('agent-composer')),
matching: find.byType(TextField),
);
await tester.enterText(input, 'Floating draft');
final draftController = tester.widget<TextField>(input).controller;
final initialWidth = tester
.getSize(find.byKey(const Key('desktop-editor-card')))
.width;
await floatOrDockChat(tester);
await tester.pumpAndSettle();
expect(find.byKey(const Key('agent-floating-window')), findsOneWidget);
expect(find.byKey(const Key('agent-floating-title')), findsNothing);
expect(find.byKey(const Key('agent-conversation')), findsNothing);
expect(
tester.getSize(find.byKey(const Key('agent-floating-window'))).height,
lessThan(70),
);
expect(
tester.getSize(find.byKey(const Key('agent-floating-window'))).width,
560,
);
expect(find.byKey(const Key('desktop-agent-slot')), findsNothing);
expect(
tester.getSize(find.byKey(const Key('desktop-editor-card'))).width,
greaterThan(initialWidth),
);
expect(tester.element(find.byType(EditorWorkspace)), same(editor));
expect(find.byType(AgentChatPanel), findsNothing);
expect(find.byType(FloatingAgentPanel), findsOneWidget);
expect(mounted.container.read(chatProvider.notifier), same(chatController));
final floatingInput = find.byKey(const Key('floating-agent-input'));
expect(tester.widget<TextField>(floatingInput).minLines, 1);
expect(tester.getSize(floatingInput).height, lessThanOrEqualTo(28));
expect(
tester.widget<TextField>(floatingInput).controller,
same(draftController),
);
final inputElement = tester.element(floatingInput);
final editable = find.descendant(
of: floatingInput,
matching: find.byType(EditableText),
);
final editableElement = tester.element(editable);
final retainedMessages = find.byKey(
const Key('floating-agent-messages'),
skipOffstage: false,
);
final retainedTitle = find.byKey(
const Key('agent-floating-title'),
skipOffstage: false,
);
final messagesElement = tester.element(retainedMessages);
final titleElement = tester.element(retainedTitle);
final conversationRegion = find.byKey(
const Key('floating-agent-conversation-region'),
);
expect(tester.getSize(conversationRegion).height, 0);
final inputRect = tester.getRect(floatingInput);
final composer = find.byKey(const Key('floating-agent-composer'));
final composerRect = tester.getRect(composer);
final collapsedHeight = tester
.getSize(find.byKey(const Key('agent-floating-window')))
.height;
final floatingDialog = find.byKey(const Key('floating-agent-dialog'));
final dialogShape = tester.widget<AppFloatingDialog>(floatingDialog).shape;
final maxInputLines = tester.widget<TextField>(floatingInput).maxLines;
await tester.tap(floatingInput);
final focus = tester.widget<TextField>(floatingInput).focusNode;
final editingValue = draftController!.value;
await tester.pump();
await tester.pump(const Duration(milliseconds: 80));
expect(
tester.getSize(find.byKey(const Key('agent-floating-window'))).height,
allOf(greaterThan(collapsedHeight), lessThan(640)),
);
expect(tester.getRect(floatingInput), inputRect);
expect(tester.getRect(composer), composerRect);
expect(tester.element(retainedMessages), same(messagesElement));
expect(tester.element(retainedTitle), same(titleElement));
expect(
tester.getSize(conversationRegion).height,
allOf(greaterThan(0), lessThan(596)),
);
expect(tester.element(floatingInput), same(inputElement));
expect(tester.element(editable), same(editableElement));
expect(draftController.value, editingValue);
await tester.pumpAndSettle();
expect(find.byKey(const Key('floating-agent-messages')), findsOneWidget);
expect(find.byKey(const Key('agent-floating-title')), findsOneWidget);
expect(tester.widget<TextField>(floatingInput).focusNode!.hasFocus, isTrue);
expect(tester.widget<TextField>(floatingInput).focusNode, same(focus));
expect(tester.element(floatingInput), same(inputElement));
expect(tester.element(editable), same(editableElement));
expect(tester.element(retainedMessages), same(messagesElement));
expect(tester.element(retainedTitle), same(titleElement));
expect(tester.widget<AppFloatingDialog>(floatingDialog).shape, dialogShape);
expect(tester.getRect(floatingInput), inputRect);
expect(tester.getRect(composer), composerRect);
expect(tester.widget<TextField>(floatingInput).maxLines, maxInputLines);
final dividerFinder = find.byKey(const Key('floating-agent-input-divider'));
final divider = tester.widget<Divider>(dividerFinder);
final floatingBackground = AppSurfaces.of(tester.element(floatingInput))
.composerBackground;
final dividerContrast =
(divider.color!.computeLuminance() + .05) /
(floatingBackground.computeLuminance() + .05);
expect(divider.thickness, 1);
expect(dividerContrast, greaterThan(1.5));
expect(tester.getSize(dividerFinder).width, 560);
expect(
tester.getRect(dividerFinder).bottom,
tester.getRect(conversationRegion).bottom,
);
expect(
tester.getRect(find.byKey(const Key('floating-agent-messages'))).bottom,
lessThan(tester.getRect(floatingInput).top),
);
expect(
tester.getSize(find.byKey(const Key('agent-floating-window'))).width,
560,
);
expect(
tester.getSize(find.byKey(const Key('agent-floating-window'))).height,
greaterThan(300),
);
// An unfinished IME composition must survive collapsing the conversation.
final composingValue = draftController.value.copyWith(
selection: const TextSelection.collapsed(offset: 8),
composing: const TextRange(start: 0, end: 8),
);
tester.testTextInput.updateEditingValue(composingValue);
await tester.pump();
await tester.tap(find.byKey(const Key('floating-agent-collapse')));
await tester.pump();
await tester.pump(const Duration(milliseconds: 80));
expect(tester.getRect(floatingInput), inputRect);
expect(tester.getRect(composer), composerRect);
await tester.pumpAndSettle();
expect(tester.element(editable), same(editableElement));
expect(tester.element(retainedMessages), same(messagesElement));
expect(tester.element(retainedTitle), same(titleElement));
expect(tester.getSize(conversationRegion).height, 0);
expect(draftController.value, composingValue);
expect(find.byKey(const Key('floating-agent-messages')), findsNothing);
expect(find.byKey(const Key('agent-floating-title')), findsNothing);
expect(find.byKey(const Key('agent-floating-window')), findsOneWidget);
expect(
tester.widget<TextField>(floatingInput).controller!.text,
'Floating draft',
);
final resizeHandle = find.byKey(const Key('floating-agent-resize-handle'));
final dragOpen = await tester.startGesture(tester.getCenter(resizeHandle));
await dragOpen.moveBy(const Offset(0, -240));
await tester.pump();
expect(tester.getSize(conversationRegion).height, closeTo(240, 1));
expect(tester.getRect(composer), composerRect);
expect(tester.element(editable), same(editableElement));
expect(tester.element(retainedMessages), same(messagesElement));
expect(draftController.value, composingValue);
await dragOpen.moveBy(const Offset(0, 40));
await tester.pump();
expect(tester.getSize(conversationRegion).height, closeTo(200, 1));
await dragOpen.moveBy(const Offset(0, -40));
await dragOpen.up();
await tester.pumpAndSettle();
expect(tester.getSize(conversationRegion).height, 596);
final dragClosed = await tester.startGesture(
tester.getCenter(resizeHandle),
);
await dragClosed.moveBy(const Offset(0, 500));
await tester.pump();
expect(tester.getSize(conversationRegion).height, closeTo(96, 1));
expect(tester.getRect(composer), composerRect);
await dragClosed.up();
await tester.pumpAndSettle();
expect(tester.getSize(conversationRegion).height, 0);
expect(tester.element(editable), same(editableElement));
final cancelledDrag = await tester.startGesture(
tester.getCenter(resizeHandle),
);
await cancelledDrag.moveBy(const Offset(0, -60));
await tester.pump();
await cancelledDrag.cancel();
await tester.pumpAndSettle();
expect(tester.getSize(conversationRegion).height, 0);
await floatOrDockChat(tester);
await tester.pumpAndSettle();
expect(find.byKey(const Key('agent-floating-window')), findsNothing);
expect(find.byKey(const Key('desktop-chat-card')), findsOneWidget);
expect(find.byKey(const Key('agent-conversation')), findsOneWidget);
expect(find.byType(AgentChatPanel), findsOneWidget);
expect(mounted.container.read(chatProvider.notifier), same(chatController));
await floatOrDockChat(tester);
await tester.pumpAndSettle();
expect(find.byKey(const Key('agent-floating-window')), findsOneWidget);
expect(find.byType(EditorWorkspace), findsOneWidget);
await tester.tap(floatingInput);
await tester.pumpAndSettle();
tester.view.physicalSize = const Size(600, 360);
await tester.pumpAndSettle();
final floatingRect = tester.getRect(
find.byKey(const Key('agent-floating-window')),
);
expect(floatingRect.left, greaterThanOrEqualTo(0));
expect(floatingRect.top, greaterThanOrEqualTo(40));
expect(floatingRect.right, lessThanOrEqualTo(600));
expect(floatingRect.bottom, lessThanOrEqualTo(360));
final boundedDrag = await tester.startGesture(
tester.getCenter(resizeHandle),
);
await boundedDrag.moveBy(const Offset(0, -900));
await tester.pump();
expect(
tester.getRect(find.byKey(const Key('agent-floating-window'))).top,
greaterThanOrEqualTo(40),
);
await boundedDrag.up();
await tester.pumpAndSettle();
expect(
tester.getRect(composer).bottom,
lessThanOrEqualTo(floatingRect.bottom),
);
await tester.enterText(
floatingInput,
'First line\nSecond line\nThird line',
);
await tester.pumpAndSettle();
expect(
tester.getRect(composer).bottom,
lessThanOrEqualTo(floatingRect.bottom),
);
await tester.enterText(floatingInput, 'Floating draft');
await tester.pumpAndSettle();
expect(
tester.widget<TextField>(floatingInput).controller,
same(draftController),
);
expect(tester.takeException(), isNull);
tester.view.physicalSize = const Size(1800, 800);
await tester.pumpAndSettle();
await tester.tap(find.byKey(const Key('floating-agent-dock')));
await tester.pumpAndSettle();
expect(find.byKey(const Key('agent-floating-window')), findsNothing);
expect(tester.widget<TextField>(input).controller!.text, 'Floating draft');
expect(tester.takeException(), isNull);
await mounted.close();
});
testWidgets('Windows caption space follows real workspace pane changes', (
tester,
) async {
debugDefaultTargetPlatformOverride = TargetPlatform.windows;
const channel = MethodChannel('cutdex_native/window');
const dropChannel = MethodChannel('cutdex_native/file_drop/timeline');
final messenger =
TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger;
messenger.setMockMethodCallHandler(
channel,
(call) async => call.method == 'configureChrome'
? (call.arguments as Map)['enabled']
: null,
);
messenger.setMockMethodCallHandler(dropChannel, (call) async => null);
addTearDown(() {
debugDefaultTargetPlatformOverride = null;
messenger.setMockMethodCallHandler(channel, null);
messenger.setMockMethodCallHandler(dropChannel, null);
});
final mounted = await mount(tester, const Size(1200, 800));
final contentRect = tester.getRect(
find.byKey(const Key('desktop-content-container')),
);
expect(
contentRect.top,
tester.getRect(find.byKey(const Key('desktop-window-header'))).bottom,
);
expect(contentRect.left, 46);
expect(contentRect.right, 1198);
expect(contentRect.bottom, 798);
expect(
tester.getRect(find.byKey(const Key('window-minimize'))).left -
tester
.getRect(find.byKey(const Key('background-tasks-button')))
.right,
12,
);
for (final mode in [WorkspaceMode.agent, WorkspaceMode.cut]) {
await setMode(tester, mounted.container, mode);
for (final width in [1200.0, 700.0, 400.0, 1200.0]) {
tester.view.physicalSize = Size(width, 800);
await tester.pumpAndSettle();
final captionRect = tester
.getRect(find.byKey(const Key('window-minimize')))
.expandToInclude(
tester.getRect(find.byKey(const Key('window-close'))),
);
for (final key in [
'editor-media-button',
'editor-properties-button',
'project-tabs-projects',
'project-tabs-list',
'project-sidebar-toggle',
'agent-minimize-button',
'background-tasks-button',
'expand-editor-button',
]) {
final finder = find.byKey(Key(key));
for (final element in finder.evaluate()) {
var rect = tester.getRect(find.byWidget(element.widget));
// Narrow headers can scroll. Assert the visible control bounds,
// respecting each scroll viewport's clip.
element.visitAncestorElements((ancestor) {
if (ancestor.widget case SingleChildScrollView(
scrollDirection: Axis.horizontal,
)) {
rect = rect.intersect(
tester.getRect(find.byWidget(ancestor.widget)),
);
}
return true;
});
if (rect.isEmpty) continue;
expect(
rect.overlaps(captionRect),
isFalse,
reason: '$key at $width in $mode',
);
}
}
expect(tester.takeException(), isNull, reason: '$width in $mode');
}
}
await mounted.close();
debugDefaultTargetPlatformOverride = null;
});
testWidgets(
'desktop resizing retains desktop interactions, session, undo and composer',
(tester) async {
final mounted = await mount(tester, const Size(1200, 800));
final session = mounted.session;
final sequence = session.activeSequenceId!;
final view = session.view(sequence);
final input = find.descendant(
of: find.byKey(const Key('agent-composer')),
matching: find.byType(TextField),
);
await tester.enterText(input, 'Keep my draft');
await tester.drag(
find.byKey(const Key('project-sidebar-resize')),
const Offset(40, 0),
);
await tester.pumpAndSettle();
final agentWidth = tester.getSize(find.byType(AgentChatPanel)).width;
view.setSelection([
view.version.kernelVersion.query().elementById(ElementId('clip'))!,
]);
view.seekTo(TimelineClock.ticksPerSecond);
await tester.runAsync(() async {
view.cutSelectionAtPlayhead();
await session.flush();
});
final selected = view.selectedIdentities.toList();
final version = session.version;
expect(view.canUndo, isTrue);
for (final size in [
const Size(390, 844),
const Size(780, 1024),
const Size(900, 600),
const Size(1200, 800),
]) {
tester.view.physicalSize = size;
await tester.pumpAndSettle();
expect(
find.byKey(const Key('desktop-workspace-shell')),
findsOneWidget,
);
expect(find.byType(NavigationBar), findsNothing);
expect(find.byType(NavigationRail), findsNothing);
await setMode(tester, mounted.container, WorkspaceMode.cut);
expect(find.byType(EditorTimelinePanel), findsOneWidget);
expect(
await mounted.container.read(
editorTimelineProvider(mounted.projectId, 'project').future,
),
same(session),
);
expect(session.view(sequence), same(view));
expect(view.selectedIdentities, selected);
expect(view.playheadTick, TimelineClock.ticksPerSecond);
expect(session.version, version);
expect(view.canUndo, isTrue);
final rect = tester.getRect(find.byType(EditorTimelinePanel));
expect(rect.right, lessThanOrEqualTo(size.width));
expect(rect.bottom, lessThanOrEqualTo(size.height));
await setMode(tester, mounted.container, WorkspaceMode.agent);
if (input.evaluate().isNotEmpty) {
expect(
tester.widget<TextField>(input).controller!.text,
'Keep my draft',
);
}
expect(tester.takeException(), isNull);
}
expect(tester.getSize(find.byType(AgentChatPanel)).width, agentWidth);
await tester.runAsync(() async {
view.undo();
await session.flush();
});
expect(
view.version.kernelVersion.query().elementById(ElementId('clip')),
isNotNull,
);
expect(view.canRedo, isTrue);
await mounted.close();
},
);
testWidgets(
'desktop preview header centers the active name between media and properties',
(tester) async {
final target = PreviewTarget();
addTearDown(tester.platformDispatcher.clearTextScaleFactorTestValue);
final mounted = await mount(
tester,
const Size(1800, 800),
previewTarget: target,
);
final header = find.byKey(const Key('editor-content-header'));
final title = find.byKey(const Key('editor-preview-title'));
final mediaButton = find.byKey(const Key('editor-media-button'));
final propertiesButton = find.byKey(
const Key('editor-properties-button'),
);
final preview = tester.element(find.byType(EditorPreviewPanel));
expect(tester.widget<Text>(title).data, mounted.session.document.name);
await target.openSource(
AssetDocument(
id: 'long-source',
name: '这是一段名称很长的旅行素材文件用于检查预览头部不会挤压两侧按钮.mov',
storage: AssetStorage.external,
location: 'file:///test/travel.mov',
),
);
await tester.pumpAndSettle();
expect(tester.widget<Text>(title).data, target.asset!.name);
expect(tester.element(find.byType(EditorPreviewPanel)), same(preview));
for (final width in [1800.0, 1000.0, 700.0, 200.0]) {
tester.view.physicalSize = Size(width, 800);
tester.platformDispatcher.textScaleFactorTestValue = 1.5;
await tester.pumpAndSettle();
final headerRect = tester.getRect(header);
final left = tester.getRect(mediaButton);
final right = tester.getRect(propertiesButton);
final middle = tester.getRect(title);
expect(left.left - headerRect.left, AppSidebarMetrics.outerPadding);
expect(headerRect.right - right.right, AppSidebarMetrics.outerPadding);
expect(middle.center.dx, closeTo(headerRect.center.dx, 0.01));
expect(
middle.left - left.right,
greaterThanOrEqualTo(AppSpacing.small),
);
expect(
right.left - middle.right,
greaterThanOrEqualTo(AppSpacing.small),
);
expect(left.center.dy, right.center.dy);
expect(tester.widget<Text>(title).overflow, TextOverflow.ellipsis);
expect(tester.takeException(), isNull);
}
tester.platformDispatcher.clearTextScaleFactorTestValue();
tester.view.physicalSize = const Size(1800, 800);
target.showTimeline();
await tester.pumpAndSettle();
expect(tester.widget<Text>(title).data, mounted.session.document.name);
await tester.tap(mediaButton);
await tester.pumpAndSettle();
expect(find.byType(MediaPanel), findsNothing);
await tester.tap(mediaButton);
await tester.pumpAndSettle();
expect(find.byType(MediaPanel), findsOneWidget);
await tester.tap(propertiesButton);
await tester.pumpAndSettle();
expect(find.byType(EditorPropertiesPanel), findsOneWidget);
expect(tester.takeException(), isNull);
await mounted.close();
},
);
testWidgets('timeline interaction clears media selection', (tester) async {
final target = PreviewTarget();
final mounted = await mount(
tester,
const Size(1800, 800),
previewTarget: target,
);
await setMode(tester, mounted.container, WorkspaceMode.cut);
final browser = mounted.container.read(
mediaBrowserProvider(mounted.projectId),
);
final otherBrowser = mounted.container.read(
mediaBrowserProvider('other-project'),
);
otherBrowser.selectedAssetId = 'other-media';
final view = mounted.session.view(mounted.session.activeSequenceId!);
final clip = view.version.kernelVersion.query().elementById(
ElementId('clip'),
)!;
final surface = tester.getRect(
find.byKey(const Key('editor-timeline-surface')),
);
final frame = view.project(
TimelineViewportRect(width: surface.width, height: surface.height),
);
final index = List.generate(frame.length, (i) => i).firstWhere(
(i) => switch (frame.identityAt(i)) {
ElementHandle h => h == clip,
LayoutBodyId body => body.owner == clip,
_ => false,
},
);
final clipPoint =
surface.topLeft +
Offset(frame.screenLeftAt(index) + 20, frame.screenTopAt(index) + 20);
bool mediaHighlighted() => tester
.widget<Semantics>(
find
.ancestor(
of: find.descendant(
of: find.byType(MediaPanel),
matching: find.text('Photo'),
),
matching: find.byWidgetPredicate(
(widget) =>
widget is Semantics && widget.properties.selected != null,
),
)
.first,
)
.properties
.selected!;
Future<void> selectMedia() async {
await tester.tap(
find.descendant(
of: find.byType(MediaPanel),
matching: find.text('Photo'),
),
);
await tester.pumpAndSettle();
expect(browser.selectedAssetId, 'media');
expect(target.asset?.id, 'media');
expect(mediaHighlighted(), isTrue);
}
await selectMedia();
await tester.tapAt(clipPoint);
await tester.pumpAndSettle();
expect(view.selectedIdentities, isNotEmpty);
expect(browser.selectedAssetId, isNull);
expect(mediaHighlighted(), isFalse);
expect(target.asset, isNull);
expect(otherBrowser.selectedAssetId, 'other-media');
// Re-selecting the same clip still transfers focus from the media browser.
await selectMedia();
view.seekTo(TimelineClock.ticksPerSecond);
await tester.pumpAndSettle();
expect(browser.selectedAssetId, 'media');
await tester.tapAt(clipPoint);
await tester.pumpAndSettle();
expect(browser.selectedAssetId, isNull);
expect(target.asset, isNull);
// Selection commands also activate the timeline without a pointer event.
view.clearSelection();
await tester.pumpAndSettle();
await selectMedia();
view.setSelection([clip]);
await tester.pumpAndSettle();
expect(browser.selectedAssetId, isNull);
expect(target.asset, isNull);
expect(tester.takeException(), isNull);
await mounted.close();
});
testWidgets('desktop media retains browsing state while collapsed', (
tester,
) async {
final mounted = await mount(tester, const Size(1800, 800));
final mediaElement = tester.element(find.byType(MediaPanel));
final browser = mounted.container.read(
mediaBrowserProvider(mounted.projectId),
);
browser.filter = MediaFilter.image;
browser.query = 'photo';
browser.sort = MediaSort.nameAscending;
browser.grid = false;
browser.selectedAssetId = 'media';
browser.resourceSection = ResourceSection.effects;
await tester.pumpAndSettle();
final editor = tester.element(find.byType(EditorWorkspace));
for (var i = 0; i < 2; i++) {
await tester.tap(find.byKey(const Key('editor-media-button')));
await tester.pumpAndSettle();
expect(find.byType(MediaPanel), findsNothing);
expect(tester.element(find.byType(EditorWorkspace)), same(editor));
await tester.tap(find.byKey(const Key('editor-media-button')));
await tester.pumpAndSettle();
expect(tester.element(find.byType(MediaPanel)), same(mediaElement));
expect(browser.filter, MediaFilter.image);
expect(browser.selectedAssetId, 'media');
expect(browser.query, 'photo');
expect(browser.sort, MediaSort.nameAscending);
expect(browser.grid, isFalse);
expect(browser.resourceSection, ResourceSection.effects);
expect(find.byKey(const Key('media-search')), findsNothing);
}
await tester.tap(find.byKey(const Key('editor-properties-button')));
await tester.pumpAndSettle();
expect(find.byType(EditorPropertiesPanel), findsOneWidget);
expect(find.byKey(const Key('editor-media-region')), findsOneWidget);
expect(tester.takeException(), isNull);
await mounted.close();
});
testWidgets('desktop resource tabs retain imported media state', (
tester,
) async {
final mounted = await mount(tester, const Size(1800, 800));
final browser = mounted.container.read(
mediaBrowserProvider(mounted.projectId),
);
browser.query = 'photo';
browser.filter = MediaFilter.image;
browser.grid = false;
await tester.pumpAndSettle();
final mediaBody = tester.element(find.byType(MediaBrowserBody));
final audioTab = find.byKey(const ValueKey('resource-tab-audio'));
await tester.ensureVisible(audioTab);
await tester.tap(audioTab);
await tester.pumpAndSettle();
expect(browser.resourceSection, ResourceSection.audio);
expect(find.byType(ResourceLibraryEmpty), findsOneWidget);
expect(find.byKey(const Key('media-search')), findsNothing);
expect(find.byKey(const Key('media-import-button')), findsNothing);
final l10n = AppLocalizations.of(
tester.element(find.byType(ResourceLibraryEmpty)),
)!;
expect(find.text(l10n.resourceImportedAudioHint), findsOneWidget);
await tester.ensureVisible(
find.byKey(const ValueKey('resource-tab-imported')),
);
await tester.tap(find.byKey(const ValueKey('resource-tab-imported')));
await tester.pumpAndSettle();
expect(tester.element(find.byType(MediaBrowserBody)), same(mediaBody));
expect(browser.query, 'photo');
expect(browser.filter, MediaFilter.image);
expect(browser.grid, isFalse);
expect(find.byKey(const Key('media-search')), findsOneWidget);
expect(find.byKey(const Key('media-import-button')), findsOneWidget);
expect(tester.takeException(), isNull);
await mounted.close();
});
testWidgets(
'medium desktop keeps media docked while properties open in an overlay',
(tester) async {
final mounted = await mount(tester, const Size(1000, 800));
expect(find.byKey(const Key('editor-media-card')), findsOneWidget);
await tester.tap(find.byKey(const Key('editor-properties-button')));
await tester.pumpAndSettle();
expect(find.byType(EditorPropertiesPanel), findsOneWidget);
expect(find.byKey(const Key('editor-tool-surface')), findsOneWidget);
expect(find.byType(MediaPanel), findsOneWidget);
await tester.tap(find.byKey(const Key('editor-tool-close')));
await tester.pumpAndSettle();
expect(find.byType(EditorPropertiesPanel), findsNothing);
expect(find.byKey(const Key('editor-media-card')), findsOneWidget);
expect(tester.takeException(), isNull);
await mounted.close();
},
);
testWidgets(
'phone tools use independent pages without changing desktop preferences',
(tester) async {
final mounted = await mount(
tester,
const Size(390, 844),
experience: DeviceExperience.phone,
);
final container = mounted.container;
await tester.tap(find.byKey(const Key('workspace-cut-destination')));
await tester.pumpAndSettle();
expect(find.byType(EditorWorkspace), findsOneWidget);
final session = mounted.session;
final view = session.view(session.activeSequenceId!);
view.setSelection([
view.version.kernelVersion.query().elementById(ElementId('clip'))!,
]);
await tester.pumpAndSettle();
await tester.tap(find.byKey(const Key('editor-properties-button')));
await tester.pumpAndSettle();
expect(find.byType(PropertiesEditorPage), findsOneWidget);
expect(find.byKey(const Key('property-category-picker')), findsOneWidget);
expect(
container
.read(projectViewSettingsProvider(mounted.projectId))
.requireValue
.propertiesOpen,
isFalse,
);
final category = container.read(
propertyCategoryProvider((
mounted.projectId,
'project',
'${session.activeSequenceId!.value}/clip',
)),
);
category.value = PropertyCategory.animation;
await tester.pumpAndSettle();
await tester.tap(find.byKey(const Key('editor-tool-close')));
await tester.pumpAndSettle();
await tester.tap(find.byKey(const Key('editor-media-button')));
await tester.pumpAndSettle();
expect(find.byType(MediaBrowserPage), findsOneWidget);
expect(find.byKey(const Key('media-add-selected')), findsOneWidget);
container.read(mediaBrowserProvider(mounted.projectId)).filter =
MediaFilter.image;
await tester.pumpAndSettle();
await tester.tap(find.byKey(const Key('editor-tool-close')));
await tester.pumpAndSettle();
await tester.tap(find.byKey(const Key('workspace-agent-destination')));
await tester.pumpAndSettle();
expect(find.byType(EditorWorkspace), findsNothing);
await tester.tap(find.byKey(const Key('workspace-cut-destination')));
await tester.pumpAndSettle();
await tester.tap(find.byKey(const Key('editor-properties-button')));
await tester.pumpAndSettle();
expect(
tester
.widget<DropdownButton<PropertyCategory>>(
find.byKey(const Key('property-category-picker')),
)
.value,
PropertyCategory.animation,
);
tester.view.physicalSize = const Size(780, 1024);
await tester.pumpAndSettle();
expect(find.byType(PropertiesEditorPage), findsOneWidget);
expect(find.byType(PropertiesToolPanel), findsNothing);
expect(
tester
.widget<DropdownButton<PropertyCategory>>(
find.byKey(const Key('property-category-picker')),
)
.value,
PropertyCategory.animation,
);
tester.view.physicalSize = const Size(1200, 800);
await tester.pumpAndSettle();
expect(find.byType(PropertiesEditorPage), findsOneWidget);
expect(find.byKey(const Key('phone-workspace-shell')), findsOneWidget);
expect(find.byType(NavigationBar), findsOneWidget);
expect(find.byType(NavigationRail), findsNothing);
expect(
container.read(mediaBrowserProvider(mounted.projectId)).filter,
MediaFilter.image,
);
expect(tester.takeException(), isNull);
await mounted.close();
},
);
for (final experience in DeviceExperience.values) {
testWidgets(
'${experience.name} keeps its navigation and media interaction across widths',
(tester) async {
final mounted = await mount(
tester,
const Size(1200, 800),
experience: experience,
);
await setMode(tester, mounted.container, WorkspaceMode.cut);
if (experience != DeviceExperience.desktop) {
await tester.tap(find.byKey(const Key('editor-media-button')));
await tester.pumpAndSettle();
}
final browser = mounted.container.read(
mediaBrowserProvider(mounted.projectId),
);
browser.filter = MediaFilter.image;
browser.selectedAssetId = 'media';
for (final size in [
const Size(390, 844),
const Size(600, 800),
const Size(1200, 800),
]) {
tester.view.physicalSize = size;
await tester.pumpAndSettle();
if (experience == DeviceExperience.desktop &&
find.byType(MediaPanel).evaluate().isEmpty) {
await tester.tap(find.byKey(const Key('editor-media-button')));
await tester.pumpAndSettle();
}
expect(
find.byKey(
Key('${experience.name}-workspace-shell'),
skipOffstage: false,
),
findsOneWidget,
);
expect(
find.byType(NavigationBar),
experience == DeviceExperience.phone
? findsOneWidget
: findsNothing,
);
expect(
find.byType(NavigationRail),
experience == DeviceExperience.tablet
? findsOneWidget
: findsNothing,
);
final panel = find.byKey(const Key('media-panel-surface'));
expect(
find.byType(MediaPanel),
experience == DeviceExperience.desktop
? findsOneWidget
: findsNothing,
);
expect(
find.byType(MediaBrowserPage),
experience == DeviceExperience.phone
? findsOneWidget
: findsNothing,
);
expect(
find.byType(MediaBrowserDrawer),
experience == DeviceExperience.tablet
? findsOneWidget
: findsNothing,
);
expect(
find.byKey(const Key('media-add-selected')),
experience == DeviceExperience.desktop
? findsNothing
: findsOneWidget,
);
if (experience == DeviceExperience.desktop) {
expect(
find.byKey(
const Key('editor-timeline-resize'),
skipOffstage: false,
),
findsOneWidget,
);
}
final rect = tester.getRect(panel);
expect(rect.left, greaterThanOrEqualTo(0));
expect(rect.right, lessThanOrEqualTo(size.width));
expect(rect.bottom, lessThanOrEqualTo(size.height));
expect(browser.filter, MediaFilter.image);
expect(browser.selectedAssetId, 'media');
expect(tester.takeException(), isNull);
if (experience == DeviceExperience.desktop && size.width < 700) {
Scaffold.of(tester.element(find.byType(MediaPanel))).closeDrawer();
await tester.pumpAndSettle();
}
}
await mounted.close();
},
);
}
testWidgets(
'tablet split screen keeps rail and tool panel with mouse and keyboard',
(tester) async {
final mounted = await mount(
tester,
const Size(1200, 800),
experience: DeviceExperience.tablet,
);
final input = find.descendant(
of: find.byKey(const Key('agent-composer')),
matching: find.byType(TextField),
);
await tester.enterText(input, 'Tablet draft');
expect(find.byType(EditorTimelinePanel), findsOneWidget);
tester.view.physicalSize = const Size(390, 844);
tester.view.viewInsets = const FakeViewPadding(bottom: 300);
addTearDown(tester.view.resetViewInsets);
await tester.pumpAndSettle();
expect(find.byType(NavigationRail), findsOneWidget);
expect(find.byType(NavigationBar), findsNothing);
expect(
tester.getRect(find.byKey(const Key('agent-composer'))).bottom,
lessThanOrEqualTo(544),
);
expect(tester.widget<TextField>(input).controller!.text, 'Tablet draft');
tester.view.resetViewInsets();
await setMode(tester, mounted.container, WorkspaceMode.cut);
await tester.tap(find.byKey(const Key('editor-properties-button')));
await tester.pumpAndSettle();
expect(find.byType(PropertiesToolPanel), findsOneWidget);
expect(find.byType(PropertiesEditorPage), findsNothing);
final mouse = await tester.createGesture(kind: PointerDeviceKind.mouse);
await mouse.addPointer(location: const Offset(200, 24));
await mouse.moveTo(const Offset(250, 24));
await tester.pumpAndSettle();
expect(find.byKey(const Key('tablet-workspace-shell')), findsOneWidget);
expect(find.byType(PropertiesToolPanel), findsOneWidget);
await mouse.removePointer();
final prefs = mounted.container
.read(projectViewSettingsProvider(mounted.projectId))
.requireValue;
expect(prefs.propertiesOpen, isFalse);
expect(tester.takeException(), isNull);
await mounted.close();
},
);
testWidgets(
'phone navigation and landscape remain usable with keyboard and scaled text',
(tester) async {
final mounted = await mount(
tester,
const Size(390, 844),
experience: DeviceExperience.phone,
);
await tester.tap(find.byKey(const Key('workspace-navigation-button')));
await tester.pumpAndSettle();
expect(
find.byKey(ValueKey('sidebar-project-${mounted.projectId}')),
findsOneWidget,
);
await tester.tap(
find.byKey(ValueKey('sidebar-project-${mounted.projectId}')),
);
await tester.pumpAndSettle();
expect(
find.byKey(const Key('sidebar-projects-conversations')),
findsNothing,
);
expect(find.byType(AgentChatPanel), findsOneWidget);
tester.view.viewInsets = const FakeViewPadding(bottom: 300);
await tester.pumpAndSettle();
expect(find.byKey(const Key('phone-workspace-shell')), findsOneWidget);
expect(
tester.getRect(find.byKey(const Key('agent-composer'))).bottom,
lessThanOrEqualTo(544),
);
tester.view.resetViewInsets();
addTearDown(tester.view.resetViewInsets);
await setMode(tester, mounted.container, WorkspaceMode.cut);
tester.view.physicalSize = const Size(844, 390);
tester.platformDispatcher.textScaleFactorTestValue = 2;
addTearDown(tester.platformDispatcher.clearTextScaleFactorTestValue);
await tester.pumpAndSettle();
final timeline = tester.getRect(find.byType(EditorTimelinePanel));
expect(timeline.right, lessThanOrEqualTo(844));
expect(timeline.bottom, lessThanOrEqualTo(390));
expect(tester.takeException(), isNull);
await mounted.close();
},
);
for (final experience in [DeviceExperience.phone, DeviceExperience.tablet]) {
testWidgets(
'$experience navigation exposes touch actions and closes after new conversation',
(tester) async {
final mounted = await mount(
tester,
const Size(390, 844),
experience: experience,
);
final selection = conversationSelectionProvider(mounted.projectId);
final before = mounted.container.read(selection).draftKey;
await tester.tap(find.byKey(const Key('workspace-navigation-button')));
await tester.pumpAndSettle();
final create = find.byKey(const Key('create-project'));
expect(tester.getSize(create).height, greaterThanOrEqualTo(48));
final action = find.byKey(
ValueKey('new-agent-conversation-${mounted.projectId}'),
);
expect(tester.getSize(action).height, greaterThanOrEqualTo(48));
await tester.tap(action);
await tester.pumpAndSettle();
expect(mounted.container.read(selection).draftKey, isNot(before));
expect(
find.byKey(const Key('sidebar-projects-conversations')),
findsNothing,
);
expect(tester.takeException(), isNull);
},
);
}
for (final experience in [DeviceExperience.phone, DeviceExperience.tablet]) {
testWidgets(
'$experience system back closes both tool pages while keeping the editing session',
(tester) async {
final mounted = await mount(
tester,
const Size(390, 844),
experience: experience,
);
await setMode(tester, mounted.container, WorkspaceMode.cut);
for (final button in [
'editor-media-button',
'editor-properties-button',
]) {
await tester.tap(find.byKey(Key(button)));
await tester.pumpAndSettle();
expect(find.byKey(const Key('editor-tool-surface')), findsOneWidget);
await tester.binding.handlePopRoute();
await tester.pumpAndSettle();
expect(find.byKey(const Key('editor-tool-surface')), findsNothing);
expect(find.byType(EditorTimelinePanel), findsOneWidget);
expect(
await mounted.container.read(
editorTimelineProvider(mounted.projectId, 'project').future,
),
same(mounted.session),
);
}
},
);
testWidgets(
'$experience back closes the navigation drawer before the tool page',
(tester) async {
final mounted = await mount(
tester,
const Size(390, 844),
experience: experience,
);
await setMode(tester, mounted.container, WorkspaceMode.cut);
await tester.tap(find.byKey(const Key('editor-media-button')));
await tester.pumpAndSettle();
await tester.tap(find.byKey(const Key('workspace-navigation-button')));
await tester.pumpAndSettle();
await tester.binding.handlePopRoute();
await tester.pumpAndSettle();
expect(
find.byKey(const Key('sidebar-projects-conversations')),
findsNothing,
);
expect(find.byKey(const Key('editor-tool-surface')), findsOneWidget);
await tester.binding.handlePopRoute();
await tester.pumpAndSettle();
expect(find.byKey(const Key('editor-tool-surface')), findsNothing);
},
);
}
testWidgets('phone new conversation from a tool drawer returns to Agent', (
tester,
) async {
final mounted = await mount(
tester,
const Size(390, 844),
experience: DeviceExperience.phone,
);
await setMode(tester, mounted.container, WorkspaceMode.cut);
await tester.tap(find.byKey(const Key('editor-media-button')));
await tester.pumpAndSettle();
await tester.tap(find.byKey(const Key('workspace-navigation-button')));
await tester.pumpAndSettle();
await tester.tap(
find.byKey(ValueKey('new-agent-conversation-${mounted.projectId}')),
);
await tester.pumpAndSettle();
expect(
find.byKey(const Key('sidebar-projects-conversations')),
findsNothing,
);
expect(find.byType(AgentChatPanel), findsOneWidget);
expect(tester.takeException(), isNull);
});
testWidgets(
'phone property category survives closing and remounting the inspector',
(tester) async {
final mounted = await mount(
tester,
const Size(390, 844),
experience: DeviceExperience.phone,
);
final sequence = mounted.session.activeSequenceId!;
final view = mounted.session.view(sequence);
view.setSelection([
view.version.kernelVersion.query().elementById(ElementId('clip'))!,
]);
await setMode(tester, mounted.container, WorkspaceMode.cut);
await tester.tap(find.byKey(const Key('editor-properties-button')));
await tester.pumpAndSettle();
final picker = find.byKey(const Key('property-category-picker'));
final dropdown = tester.widget<DropdownButton<PropertyCategory>>(picker);
dropdown.onChanged!(PropertyCategory.animation);
await tester.pumpAndSettle();
expect(
tester.widget<DropdownButton<PropertyCategory>>(picker).value,
PropertyCategory.animation,
);
await tester.binding.handlePopRoute();
await tester.pumpAndSettle();
await setMode(tester, mounted.container, WorkspaceMode.agent);
await setMode(tester, mounted.container, WorkspaceMode.cut);
await tester.tap(find.byKey(const Key('editor-properties-button')));
await tester.pumpAndSettle();
expect(
tester.widget<DropdownButton<PropertyCategory>>(picker).value,
PropertyCategory.animation,
);
expect(tester.takeException(), isNull);
},
);
testWidgets(
'phone attachment import completes while the composer is hidden',
(tester) async {
final resolver = _DelayedResolver();
final mounted = await mount(
tester,
const Size(390, 844),
experience: DeviceExperience.phone,
delayedResolver: resolver,
picker: const _PhotoPicker(),
);
final selection = mounted.container.read(
conversationSelectionProvider(mounted.projectId),
);
final composer = mounted.container
.read(agentComposerStoreProvider)
.composer(mounted.projectId, selection.draftKey);
final add = find.descendant(
of: find.byKey(const Key('agent-composer')),
matching: find.byIcon(AppIcons.add),
);
await tester.tap(add);
await tester.pump();
expect(resolver.started, isTrue);
await setMode(tester, mounted.container, WorkspaceMode.cut);
expect(find.byType(AgentChatPanel), findsNothing);
resolver.gate.complete();
await tester.pumpAndSettle();
expect(composer.attachments.single.id, 'media');
await setMode(tester, mounted.container, WorkspaceMode.agent);
expect(find.byKey(const Key('agent-attachment-media')), findsOneWidget);
expect(tester.takeException(), isNull);
},
);
testWidgets(
'phone media import updates browser selection after the tool is closed',
(tester) async {
final resolver = _DelayedResolver();
final mounted = await mount(
tester,
const Size(390, 844),
experience: DeviceExperience.phone,
delayedResolver: resolver,
picker: const _PhotoPicker(),
);
await setMode(tester, mounted.container, WorkspaceMode.cut);
await tester.tap(find.byKey(const Key('editor-media-button')));
await tester.pumpAndSettle();
await tester.tap(find.byKey(const Key('media-import-button')));
await tester.pump();
expect(resolver.started, isTrue);
await tester.binding.handlePopRoute();
await tester.pumpAndSettle();
resolver.gate.complete();
await tester.pumpAndSettle();
expect(
mounted.container
.read(mediaBrowserProvider(mounted.projectId))
.selectedAssetId,
'media',
);
expect(tester.takeException(), isNull);
},
);
testWidgets(
'created conversation preserves follow-up text and pending imports',
(tester) async {
final resolver = _DelayedResolver();
final mounted = await mount(
tester,
const Size(390, 844),
experience: DeviceExperience.phone,
delayedResolver: resolver,
picker: const _PhotoPicker(),
conversations: _WorkspaceConversationRepository(),
);
final selectionProvider = conversationSelectionProvider(
mounted.projectId,
);
final draftKey = mounted.container.read(selectionProvider).draftKey;
final store = mounted.container.read(agentComposerStoreProvider);
final input = find.descendant(
of: find.byKey(const Key('agent-composer')),
matching: find.byType(TextField),
);
await tester.enterText(
input,
'Follow-up while the first message is saved',
);
final draftInput = store.input(mounted.projectId, null);
final composer = store.composer(mounted.projectId, draftKey);
await tester.tap(
find.descendant(
of: find.byKey(const Key('agent-composer')),
matching: find.byIcon(AppIcons.add),
),
);
await tester.pump();
expect(resolver.started, isTrue);
final now = DateTime.utc(2026);
final created = ConversationMetadata(
id: 'created-chat',
pending: false,
responseDurationsMs: const [],
projectId: mounted.projectId,
title: 'Created',
createdAt: now,
updatedAt: now,
providerId: 'provider',
modelId: 'model',
timelineId: 'project',
);
await mounted.container
.read(conversationSidebarProvider.notifier)
.updateListing(created, selectIfDraftKey: draftKey);
await tester.pumpAndSettle();
expect(mounted.container.read(selectionProvider).selectedId, created.id);
expect(store.input(mounted.projectId, created.id), same(draftInput));
expect(store.composer(mounted.projectId, created.id), same(composer));
expect(
tester.widget<TextField>(input).controller!.text,
'Follow-up while the first message is saved',
);
resolver.gate.complete();
await tester.pumpAndSettle();
expect(find.byKey(const Key('agent-attachment-media')), findsOneWidget);
expect(composer.busy, isFalse);
mounted.container
.read(conversationSidebarProvider.notifier)
.newConversation();
await tester.pumpAndSettle();
expect(tester.widget<TextField>(input).controller!.text, isEmpty);
expect(find.byKey(const Key('agent-attachment-media')), findsNothing);
expect(
store.input(mounted.projectId, created.id).text,
'Follow-up while the first message is saved',
);
expect(tester.takeException(), isNull);
},
);
for (final target in ['composer', 'media']) {
testWidgets('hidden $target import failure is shown once on return', (
tester,
) async {
final resolver = _DelayedResolver();
final mounted = await mount(
tester,
const Size(390, 844),
experience: DeviceExperience.phone,
delayedResolver: resolver,
picker: const _BadPicker(),
importResult: const MediaImportResult(
assets: [],
added: 0,
duplicates: 0,
failures: [
MediaImportFailure(
name: 'bad.mov',
failure: AppFailure(
AppErrorCode.diagnostic,
diagnostic: 'File cannot be read',
),
),
],
),
);
if (target == 'media') {
await setMode(tester, mounted.container, WorkspaceMode.cut);
await tester.tap(find.byKey(const Key('editor-media-button')));
await tester.pumpAndSettle();
await tester.tap(find.byKey(const Key('media-import-button')));
} else {
await tester.tap(
find.descendant(
of: find.byKey(const Key('agent-composer')),
matching: find.byIcon(AppIcons.add),
),
);
}
await tester.pump();
expect(resolver.started, isTrue);
if (target == 'media') {
await tester.binding.handlePopRoute();
await tester.pumpAndSettle();
} else {
await setMode(tester, mounted.container, WorkspaceMode.cut);
}
resolver.gate.complete();
await tester.pumpAndSettle();
expect(find.byKey(const Key('global-error-notification')), findsNothing);
if (target == 'media') {
await tester.tap(find.byKey(const Key('editor-media-button')));
await tester.pumpAndSettle();
} else {
await setMode(tester, mounted.container, WorkspaceMode.agent);
}
expect(
find.byKey(const Key('global-error-notification')),
findsOneWidget,
);
expect(find.textContaining('bad.mov:'), findsOneWidget);
final feedback = target == 'media'
? mounted.container
.read(mediaBrowserProvider(mounted.projectId))
.feedback
: mounted.container
.read(agentComposerStoreProvider)
.composer(
mounted.projectId,
mounted.container
.read(conversationSelectionProvider(mounted.projectId))
.draftKey,
)
.feedback;
expect(feedback.hasPending, isFalse);
await tester.tap(find.byKey(const Key('close-error-button')));
await tester.pumpAndSettle();
await setMode(tester, mounted.container, WorkspaceMode.cut);
await setMode(tester, mounted.container, WorkspaceMode.agent);
if (target == 'media') {
await setMode(tester, mounted.container, WorkspaceMode.cut);
await tester.tap(find.byKey(const Key('editor-media-button')));
await tester.pumpAndSettle();
}
expect(find.byKey(const Key('global-error-notification')), findsNothing);
expect(tester.takeException(), isNull);
});
}
testWidgets(
'extremely narrow desktop keeps safe layout and splitter bounds',
(tester) async {
final mounted = await mount(tester, const Size(200, 800));
expect(find.byKey(const Key('desktop-workspace-shell')), findsOneWidget);
expect(find.byKey(const Key('project-sidebar-resize')), findsNothing);
expect(tester.takeException(), isNull);
tester.view.physicalSize = const Size(308, 800);
await tester.pumpAndSettle();
expect(find.byKey(const Key('project-sidebar-resize')), findsNothing);
expect(tester.takeException(), isNull);
tester.view.physicalSize = const Size(200, 800);
await tester.pumpAndSettle();
expect(find.byKey(const Key('project-sidebar-resize')), findsNothing);
expect(tester.takeException(), isNull);
tester.view.physicalSize = const Size(1200, 800);
await tester.pumpAndSettle();
expect(find.byKey(const Key('project-sidebar-resize')), findsOneWidget);
await tester.drag(
find.byKey(const Key('project-sidebar-resize')),
const Offset(-20, 0),
);
await tester.pumpAndSettle();
expect(find.byKey(const Key('desktop-workspace-shell')), findsOneWidget);
expect(tester.takeException(), isNull);
await mounted.close();
},
);
}
class _FixtureProjects extends Projects {
_FixtureProjects(this.projectId, this.session, this.importResult);
final MediaImportResult? importResult;
final String projectId;
final EditorTimelineSession session;
final _knownProjects = <String, RecentProject>{};
@override
Future<ProjectState> build() async {
final project = RecentProject(
id: projectId,
name: 'Adaptive test',
path: '/test/Adaptive.cutdex',
);
_knownProjects[project.path] = project;
return ProjectState(
activeProject: project,
recent: [project],
timeline: session.document,
timelines: const [
TimelineSummary(id: 'project', name: 'Timeline', revision: 1),
],
assets: [
AssetDocument(
id: 'media',
name: 'Photo',
storage: AssetStorage.external,
location: const ExternalMediaFile(path: '/test/photo.png').sourceUri
.toString(),
metadata: {'kind': 'image'},
),
],
);
}
@visibleForTesting
bool closeSucceeds = true;
void forgetRecent(String id) => state = AsyncData(
state.requireValue.copyWith(
recent: state.requireValue.recent
.where((project) => project.id != id)
.toList(),
),
);
void addRecent() {
const other = RecentProject(
id: 'other',
name: 'Other project',
path: '/test/Other.cutdex',
);
_knownProjects[other.path] = other;
state = AsyncData(
state.requireValue.copyWith(
recent: [...state.requireValue.recent, other],
),
);
}
@override
Future<bool> open(
String path, {
String? name,
String? expectedId,
String? timelineId,
String? initialTimelineName,
bool Function()? isCurrent,
}) async {
final next = _knownProjects[path];
if (next == null || isCurrent?.call() == false) return false;
state = AsyncData(
state.requireValue.copyWith(
activeProject: next,
recent:
state.requireValue.recent.any((project) => project.id == next.id)
? state.requireValue.recent
: [next, ...state.requireValue.recent],
timeline: session.document,
),
);
return true;
}
@override
Future<bool> closeActiveProject() async {
if (!closeSucceeds) return false;
state = AsyncData(
state.requireValue.copyWith(
activeProject: null,
timeline: null,
timelines: const [],
assets: const [],
),
);
return true;
}
@override
Future<MediaImportResult?> importExternalMedia(
String projectId,
List<ExternalMediaFile> files, {
bool Function()? isCancelled,
}) async =>
importResult ??
await super.importExternalMedia(
projectId,
files,
isCancelled: isCancelled,
);
@override
EditorTimelineSession? cachedTimelineSession(
String projectId,
String timelineId,
) => session;
}
class _TimelineViewRepository implements TimelineViewSettingsRepository {
@override
Future<TimelineViewState> load(String projectId, String timelineId) async =>
const TimelineViewState();
@override
Future<void> save(
String projectId,
String timelineId,
SequenceId sequenceId,
TimelineSequenceViewState state,
) async {}
}
class _PhotoPicker extends AppFilePicker {
const _PhotoPicker();
@override
Future<List<ExternalMediaFile>> pickFiles({
required List<String> allowedExtensions,
}) async => [const ExternalMediaFile(path: '/test/photo.png')];
}
class _DelayedResolver extends MediaFileResolver {
final gate = Completer<void>();
bool started = false;
@override
Future<Map<ExternalMediaFile, Set<String>>> resolve(
List<ExternalMediaFile> files,
List<AssetDocument> assets,
) async {
started = true;
await gate.future;
return super.resolve(files, assets);
}
}
class _BadPicker extends AppFilePicker {
const _BadPicker();
@override
Future<List<ExternalMediaFile>> pickFiles({
required List<String> allowedExtensions,
}) async => [const ExternalMediaFile(path: '/test/bad.mov')];
}
class _WorkspaceConversationRepository extends EmptyConversationRepository {
@override
Future<void> select(String projectId, String? conversationId) async {}
}