2347 lines
84 KiB
Dart
2347 lines
84 KiB
Dart
import 'package:cutdex/workspace/workspace_mode.dart';
|
|
import 'package:cutdex/workspace/view_settings.dart';
|
|
import 'package:cutdex/app/editor_theme.dart';
|
|
import 'package:cutdex/integrations/platform/device_experience.dart';
|
|
|
|
import 'support/empty_conversation_repository.dart';
|
|
|
|
import 'package:cutdex/persistence/app_settings_repositories.dart';
|
|
|
|
import 'dart:async';
|
|
import 'dart:io';
|
|
|
|
import 'package:cutdex/features/timeline/timeline_panel.dart';
|
|
import 'package:cutdex/features/preview/preview_panel.dart';
|
|
import 'package:cutdex/features/properties/properties_panel.dart';
|
|
import 'package:cutdex/features/media/media_panel.dart';
|
|
import 'package:cutdex/features/assistant/agent_chat_panel.dart';
|
|
import 'package:cutdex/features/editor/editor_page.dart';
|
|
import 'package:cutdex/features/settings/settings_content.dart';
|
|
import 'package:cutdex/features/settings/appearance_settings.dart';
|
|
|
|
import 'support/memory_app_settings.dart';
|
|
|
|
import 'package:cutdex_ui/theme.dart';
|
|
import 'package:flutter/foundation.dart';
|
|
import 'package:flutter/gestures.dart';
|
|
import 'package:flutter/services.dart';
|
|
import 'package:cutdex/workspace/projects.dart';
|
|
import 'package:cutdex/workspace/project_state.dart';
|
|
import 'package:cutdex_sdk/project.dart';
|
|
import 'package:cutdex/app/app.dart';
|
|
import 'package:cutdex/app/router/app_router.dart';
|
|
import 'package:cutdex/integrations/agent/conversation_repository.dart';
|
|
import 'package:flutter/material.dart';
|
|
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
|
import 'package:flutter_test/flutter_test.dart';
|
|
|
|
Future<void> _hoverProjectHeader(WidgetTester tester) async {
|
|
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.pumpAndSettle();
|
|
addTearDown(mouse.removePointer);
|
|
}
|
|
|
|
void main() {
|
|
testWidgets(
|
|
'desktop content switches retain editor, settings, draft and split widths',
|
|
(tester) async {
|
|
tester.view.physicalSize = const Size(1400, 800);
|
|
tester.view.devicePixelRatio = 1;
|
|
addTearDown(tester.view.resetPhysicalSize);
|
|
addTearDown(tester.view.resetDevicePixelRatio);
|
|
await tester.pumpWidget(
|
|
ProviderScope(
|
|
overrides: [
|
|
deviceExperienceProvider.overrideWithValue(
|
|
DeviceExperience.desktop,
|
|
),
|
|
appearanceSettingsRepositoryProvider.overrideWithValue(
|
|
MemoryAppearanceSettingsRepository(),
|
|
),
|
|
conversationRepositoryProvider.overrideWith(
|
|
(ref) async => EmptyConversationRepository(),
|
|
),
|
|
projectsProvider.overrideWith(_TestProjects.new),
|
|
],
|
|
child: const CutdexApp(),
|
|
),
|
|
);
|
|
await tester.pumpAndSettle();
|
|
final editor = tester.element(find.byType(EditorWorkspace));
|
|
final agent = tester.element(find.byType(AgentChatPanel));
|
|
final timeline = tester.element(find.byType(EditorTimelinePanel));
|
|
final input = find.descendant(
|
|
of: find.byType(AgentChatPanel),
|
|
matching: find.byType(TextField),
|
|
);
|
|
await tester.enterText(input, 'Keep settings draft');
|
|
await tester.drag(
|
|
find.byKey(const Key('agent-panel-resize')),
|
|
const Offset(-80, 0),
|
|
);
|
|
await tester.pumpAndSettle();
|
|
final agentWidth = tester.getSize(find.byType(AgentChatPanel)).width;
|
|
final editorWidth = tester.getSize(find.byType(EditorWorkspace)).width;
|
|
final container = ProviderScope.containerOf(editor);
|
|
final header = tester.element(
|
|
find.byKey(const Key('desktop-window-header')),
|
|
);
|
|
final rail = tester.element(
|
|
find.byKey(const Key('desktop-navigation-rail')),
|
|
);
|
|
final route = container
|
|
.read(appRouterProvider)
|
|
.routeInformationProvider
|
|
.value
|
|
.uri;
|
|
await tester.tap(find.byKey(const Key('project-settings-button')));
|
|
await tester.pumpAndSettle();
|
|
expect(
|
|
find.byKey(const Key('desktop-settings-workspace')),
|
|
findsOneWidget,
|
|
);
|
|
expect(find.byType(SettingsContent), findsOneWidget);
|
|
final navigationCard = find.byKey(const Key('settings-navigation-card'));
|
|
final contentCard = find.byKey(const Key('settings-content-card'));
|
|
final navigationRect = tester.getRect(navigationCard);
|
|
final settingsRect = tester.getRect(contentCard);
|
|
expect(settingsRect.left - navigationRect.right, 1);
|
|
expect(settingsRect.top, navigationRect.top);
|
|
expect(settingsRect.bottom, navigationRect.bottom);
|
|
expect(find.byKey(const Key('settings-sidebar-divider')), findsNothing);
|
|
await tester.dragFrom(
|
|
tester.getCenter(find.byKey(const Key('settings-card-gap'))),
|
|
const Offset(60, 0),
|
|
);
|
|
await tester.pumpAndSettle();
|
|
expect(tester.getRect(navigationCard), navigationRect);
|
|
expect(tester.getRect(contentCard), settingsRect);
|
|
expect(
|
|
tester.element(find.byKey(const Key('desktop-window-header'))),
|
|
same(header),
|
|
);
|
|
expect(
|
|
tester.element(find.byKey(const Key('desktop-navigation-rail'))),
|
|
same(rail),
|
|
);
|
|
expect(
|
|
container.read(appRouterProvider).routeInformationProvider.value.uri,
|
|
route,
|
|
);
|
|
expect(find.byKey(const Key('app-dialog-frame')), findsNothing);
|
|
expect(find.byType(EditorWorkspace), findsNothing);
|
|
expect(
|
|
tester.element(find.byType(EditorWorkspace, skipOffstage: false)),
|
|
same(editor),
|
|
);
|
|
await container
|
|
.read(appearanceSettingsProvider.notifier)
|
|
.setMode(AppAppearance.penDark);
|
|
await tester.pumpAndSettle();
|
|
await tester.tap(find.byKey(const ValueKey('settings-navigation-1')));
|
|
await tester.pumpAndSettle();
|
|
final settings = tester.element(find.byType(SettingsContent));
|
|
await tester.tap(find.byKey(const Key('desktop-rail-library')));
|
|
await tester.pumpAndSettle();
|
|
expect(find.byType(SettingsContent), findsNothing);
|
|
expect(find.byKey(const Key('desktop-library-workspace')), findsNothing);
|
|
await tester.tap(find.byKey(const Key('project-settings-button')));
|
|
await tester.pumpAndSettle();
|
|
expect(tester.element(find.byType(SettingsContent)), same(settings));
|
|
expect(find.byKey(const Key('agent-settings-scroll')), findsOneWidget);
|
|
expect(find.byKey(const Key('desktop-rail-cut')), findsOneWidget);
|
|
await tester.tap(find.byKey(const Key('desktop-rail-cut')));
|
|
await tester.pumpAndSettle();
|
|
expect(find.byKey(const Key('desktop-settings-workspace')), findsNothing);
|
|
expect(tester.element(find.byType(EditorWorkspace)), same(editor));
|
|
expect(tester.element(find.byType(AgentChatPanel)), same(agent));
|
|
expect(tester.element(find.byType(EditorTimelinePanel)), same(timeline));
|
|
expect(tester.getSize(find.byType(AgentChatPanel)).width, agentWidth);
|
|
expect(tester.getSize(find.byType(EditorWorkspace)).width, editorWidth);
|
|
expect(
|
|
tester.widget<TextField>(input).controller!.text,
|
|
'Keep settings draft',
|
|
);
|
|
expect(tester.takeException(), isNull);
|
|
},
|
|
);
|
|
testWidgets('workspace stays hidden while startup data loads', (
|
|
tester,
|
|
) async {
|
|
tester.view.physicalSize = const Size(1200, 800);
|
|
tester.view.devicePixelRatio = 1;
|
|
addTearDown(tester.view.resetPhysicalSize);
|
|
addTearDown(tester.view.resetDevicePixelRatio);
|
|
await tester.pumpWidget(
|
|
ProviderScope(
|
|
overrides: [
|
|
deviceExperienceProvider.overrideWithValue(DeviceExperience.desktop),
|
|
conversationRepositoryProvider.overrideWith(
|
|
(ref) async => EmptyConversationRepository(),
|
|
),
|
|
projectsProvider.overrideWith(_LoadingProjects.new),
|
|
],
|
|
child: const CutdexApp(),
|
|
),
|
|
);
|
|
await tester.pump();
|
|
expect(find.byKey(const Key('projects-window-header')), findsNothing);
|
|
expect(find.byKey(const Key('project-sidebar-separator')), findsNothing);
|
|
expect(find.byType(EditorWorkspace), findsNothing);
|
|
expect(find.text('CUTDEX'), findsOneWidget);
|
|
expect(find.text('Opening workspace…'), findsOneWidget);
|
|
expect(find.byType(CircularProgressIndicator), findsNothing);
|
|
expect(find.byType(FadeTransition), findsWidgets);
|
|
expect(find.text('No projects yet'), findsNothing);
|
|
});
|
|
|
|
testWidgets(
|
|
'composer is available before selecting a project and keeps the draft',
|
|
(tester) async {
|
|
tester.view.physicalSize = const Size(1200, 800);
|
|
tester.view.devicePixelRatio = 1;
|
|
addTearDown(tester.view.resetPhysicalSize);
|
|
addTearDown(tester.view.resetDevicePixelRatio);
|
|
await tester.pumpWidget(
|
|
ProviderScope(
|
|
overrides: [
|
|
deviceExperienceProvider.overrideWithValue(
|
|
DeviceExperience.desktop,
|
|
),
|
|
projectsProvider.overrideWith(_UnselectedProjects.new),
|
|
conversationRepositoryProvider.overrideWith(
|
|
(ref) async => _GroupedConversationRepository({}),
|
|
),
|
|
],
|
|
child: const CutdexApp(),
|
|
),
|
|
);
|
|
await tester.pumpAndSettle();
|
|
final input = find.descendant(
|
|
of: find.byKey(const Key('agent-composer')),
|
|
matching: find.byType(TextField),
|
|
);
|
|
expect(input, findsOneWidget);
|
|
final projectBar = find.byKey(const Key('composer-project-bar'));
|
|
final composer = find.byKey(const Key('agent-composer'));
|
|
expect(tester.getSize(projectBar).height, 60);
|
|
expect(
|
|
tester.getRect(projectBar).left,
|
|
tester.getRect(composer).left + 13,
|
|
);
|
|
expect(
|
|
tester.getRect(projectBar).right,
|
|
tester.getRect(composer).right - 13,
|
|
);
|
|
expect(tester.getRect(projectBar).top + 38, tester.getRect(composer).top);
|
|
expect(find.text('Select project'), findsOneWidget);
|
|
await tester.enterText(input, 'Keep this before selecting');
|
|
await tester.tap(find.byKey(const Key('composer-project-trigger')));
|
|
await tester.pumpAndSettle();
|
|
final search = find.byKey(const Key('composer-project-search'));
|
|
void expectProjectMenuAbove() {
|
|
final menu = find.ancestor(
|
|
of: search,
|
|
matching: find.byWidgetPredicate(
|
|
(widget) => widget.runtimeType.toString() == '_MenuPanel',
|
|
),
|
|
);
|
|
expect(
|
|
tester.getRect(menu).bottom + 4,
|
|
closeTo(
|
|
tester
|
|
.getRect(find.byKey(const Key('composer-project-trigger')))
|
|
.top,
|
|
1,
|
|
),
|
|
);
|
|
}
|
|
|
|
expectProjectMenuAbove();
|
|
await tester.enterText(search, 'unmatched');
|
|
await tester.pumpAndSettle();
|
|
expectProjectMenuAbove();
|
|
expect(find.text('No matching projects'), findsOneWidget);
|
|
expect(find.byKey(const Key('composer-new-project')), findsOneWidget);
|
|
await tester.enterText(search, '测试');
|
|
await tester.pumpAndSettle();
|
|
await tester.tap(find.byKey(const ValueKey('composer-project-project')));
|
|
await tester.pumpAndSettle();
|
|
expect(search, findsNothing);
|
|
expect(
|
|
tester.widget<TextField>(input).controller!.text,
|
|
'Keep this before selecting',
|
|
);
|
|
expect(find.text('Select project'), findsNothing);
|
|
await tester.tap(find.byKey(const Key('composer-project-trigger')));
|
|
await tester.pumpAndSettle();
|
|
await tester.tap(find.byKey(const Key('composer-new-project')));
|
|
await tester.pumpAndSettle();
|
|
expect(search, findsNothing);
|
|
expect(find.byKey(const Key('app-dialog-frame')), findsOneWidget);
|
|
await tester.tap(find.text('Cancel'));
|
|
await tester.pumpAndSettle();
|
|
expect(
|
|
tester.widget<TextField>(input).controller!.text,
|
|
'Keep this before selecting',
|
|
);
|
|
},
|
|
);
|
|
|
|
testWidgets('project selection coalesces clicks and ignores stale loads', (
|
|
tester,
|
|
) async {
|
|
tester.view.physicalSize = const Size(1200, 800);
|
|
tester.view.devicePixelRatio = 1;
|
|
addTearDown(tester.view.resetPhysicalSize);
|
|
addTearDown(tester.view.resetDevicePixelRatio);
|
|
final projects = _DelayedProjects();
|
|
final chat = ConversationMetadata(
|
|
id: 'retained-chat',
|
|
projectId: 'project',
|
|
title: 'Retained conversation',
|
|
createdAt: DateTime.utc(2026),
|
|
updatedAt: DateTime.utc(2026),
|
|
providerId: 'provider',
|
|
modelId: 'model',
|
|
timelineId: 'project',
|
|
pending: false,
|
|
responseDurationsMs: const [],
|
|
);
|
|
final repository = _GroupedConversationRepository({
|
|
'project': [chat],
|
|
});
|
|
await tester.pumpWidget(
|
|
ProviderScope(
|
|
overrides: [
|
|
deviceExperienceProvider.overrideWithValue(DeviceExperience.desktop),
|
|
projectsProvider.overrideWith(() => projects),
|
|
conversationRepositoryProvider.overrideWith(
|
|
(ref) async => repository,
|
|
),
|
|
],
|
|
child: const CutdexApp(),
|
|
),
|
|
);
|
|
await tester.pumpAndSettle();
|
|
final chatRow = find.byKey(
|
|
const ValueKey('sidebar-conversation-retained-chat'),
|
|
);
|
|
final retainedRow = tester.element(chatRow);
|
|
final untouchedProjectRow = tester.widget<ListTile>(
|
|
find.byKey(const ValueKey('sidebar-project-third')),
|
|
);
|
|
bool selected(String id) => tester
|
|
.widget<ListTile>(find.byKey(ValueKey('sidebar-project-$id')))
|
|
.selected;
|
|
Future<void> click(String id) async {
|
|
await tester.tap(find.byKey(ValueKey('sidebar-project-$id')));
|
|
await tester.pump();
|
|
}
|
|
|
|
await click('other');
|
|
expect(
|
|
tester.widget<ListTile>(
|
|
find.byKey(const ValueKey('sidebar-project-third')),
|
|
),
|
|
same(untouchedProjectRow),
|
|
);
|
|
expect(selected('other'), isTrue);
|
|
expect(projects.requests, isEmpty);
|
|
expect(find.byKey(const Key('editor-preview-card')), findsOneWidget);
|
|
expect(find.byKey(const Key('editor-timeline-card')), findsOneWidget);
|
|
expect(find.byKey(const Key('preview-default-frame')), findsNothing);
|
|
expect(find.byKey(const Key('timeline-default-tracks')), findsNothing);
|
|
expect(
|
|
tester.widget<EditorWorkspace>(find.byType(EditorWorkspace)).projectName,
|
|
'测试项目',
|
|
);
|
|
final previewCard = tester.element(
|
|
find.byKey(const Key('editor-preview-card')),
|
|
);
|
|
final timelineCard = tester.element(
|
|
find.byKey(const Key('editor-timeline-card')),
|
|
);
|
|
expect(find.byKey(const Key('editor-project-loading')), findsNothing);
|
|
await tester.pump(const Duration(milliseconds: 40));
|
|
await click('third');
|
|
await click('third');
|
|
await tester.pump(const Duration(milliseconds: 100));
|
|
expect(projects.requests.map((r) => r.$1), ['third']);
|
|
expect(selected('third'), isTrue);
|
|
expect(find.byKey(const Key('editor-project-loading')), findsNothing);
|
|
await tester.pump(const Duration(milliseconds: 70));
|
|
expect(find.byKey(const Key('preview-default-frame')), findsOneWidget);
|
|
expect(find.byKey(const Key('timeline-default-tracks')), findsOneWidget);
|
|
expect(find.byKey(const Key('editor-project-loading')), findsNothing);
|
|
expect(find.byType(CircularProgressIndicator), findsNothing);
|
|
expect(
|
|
tester.element(find.byKey(const Key('editor-preview-card'))),
|
|
same(previewCard),
|
|
);
|
|
expect(
|
|
tester.element(find.byKey(const Key('editor-timeline-card'))),
|
|
same(timelineCard),
|
|
);
|
|
expect(
|
|
tester.widget<EditorWorkspace>(find.byType(EditorWorkspace)).projectName,
|
|
'Third Project',
|
|
);
|
|
await click('other');
|
|
expect(selected('other'), isTrue);
|
|
projects.requests.first.$2.complete(true);
|
|
await tester.pump();
|
|
expect(projects.state.requireValue.activeProject?.id, 'project');
|
|
await tester.pump(const Duration(milliseconds: 100));
|
|
expect(projects.requests.map((r) => r.$1), ['third', 'other']);
|
|
projects.requests.last.$2.complete(false);
|
|
await tester.pumpAndSettle();
|
|
expect(selected('project'), isTrue);
|
|
expect(find.byKey(const Key('preview-default-frame')), findsNothing);
|
|
expect(find.byKey(const Key('timeline-default-tracks')), findsNothing);
|
|
expect(find.byKey(const Key('editor-project-loading')), findsNothing);
|
|
await click('other');
|
|
await tester.pump(const Duration(milliseconds: 100));
|
|
projects.requests.last.$2.complete(true);
|
|
await tester.pump();
|
|
expect(tester.element(chatRow), same(retainedRow));
|
|
await tester.pumpAndSettle();
|
|
expect(tester.element(chatRow), same(retainedRow));
|
|
expect(selected('other'), isTrue);
|
|
expect(projects.requests.length, 3);
|
|
await click('other');
|
|
await tester.pumpAndSettle();
|
|
expect(projects.requests.length, 3);
|
|
});
|
|
|
|
testWidgets('busy operations keep sidebar and timeline controls visible', (
|
|
tester,
|
|
) async {
|
|
tester.view.physicalSize = const Size(1200, 800);
|
|
tester.view.devicePixelRatio = 1;
|
|
addTearDown(tester.view.resetPhysicalSize);
|
|
addTearDown(tester.view.resetDevicePixelRatio);
|
|
await tester.pumpWidget(
|
|
ProviderScope(
|
|
overrides: [
|
|
deviceExperienceProvider.overrideWithValue(DeviceExperience.desktop),
|
|
conversationRepositoryProvider.overrideWith(
|
|
(ref) async => EmptyConversationRepository(),
|
|
),
|
|
projectsProvider.overrideWith(_BusyProjects.new),
|
|
],
|
|
child: const CutdexApp(),
|
|
),
|
|
);
|
|
await tester.pumpAndSettle();
|
|
expect(
|
|
tester
|
|
.widget<IconButton>(find.byKey(const Key('create-project')))
|
|
.onPressed,
|
|
isNotNull,
|
|
);
|
|
expect(
|
|
tester
|
|
.widget<ListTile>(
|
|
find.byKey(const ValueKey('sidebar-project-project')),
|
|
)
|
|
.enabled,
|
|
isTrue,
|
|
);
|
|
expect(find.byKey(const Key('projects-heading')), findsOneWidget);
|
|
final addTimeline = find.byKey(const Key('timeline-add-button'));
|
|
expect(tester.widget<IconButton>(addTimeline).onPressed, isNotNull);
|
|
expect(
|
|
find.descendant(of: addTimeline, matching: find.byIcon(Icons.add)),
|
|
findsOneWidget,
|
|
);
|
|
expect(
|
|
tester
|
|
.widget<TextButton>(
|
|
find.byKey(const ValueKey('timeline-tab-project')),
|
|
)
|
|
.onPressed,
|
|
isNotNull,
|
|
);
|
|
});
|
|
|
|
testWidgets('new conversation remains an in-memory draft', (tester) async {
|
|
tester.view.physicalSize = const Size(1200, 800);
|
|
tester.view.devicePixelRatio = 1;
|
|
addTearDown(tester.view.resetPhysicalSize);
|
|
addTearDown(tester.view.resetDevicePixelRatio);
|
|
final root = (await tester.runAsync(
|
|
() => Directory.systemTemp.createTemp('cutdex-chat-ui-'),
|
|
))!;
|
|
addTearDown(() => root.delete(recursive: true));
|
|
final repository = _EmptyConversationRepository(
|
|
Directory('${root.path}/Conversations'),
|
|
);
|
|
final container = ProviderContainer(
|
|
overrides: [
|
|
deviceExperienceProvider.overrideWithValue(DeviceExperience.desktop),
|
|
projectsProvider.overrideWith(_TestProjects.new),
|
|
conversationRepositoryProvider.overrideWith((ref) async => repository),
|
|
],
|
|
// This project fixture has no persistence session to reopen on retry.
|
|
retry: (_, _) => null,
|
|
);
|
|
addTearDown(container.dispose);
|
|
await tester.pumpWidget(
|
|
UncontrolledProviderScope(container: container, child: const CutdexApp()),
|
|
);
|
|
await tester.pumpAndSettle();
|
|
await tester.tap(find.byKey(const Key('projects-heading')));
|
|
await tester.pumpAndSettle();
|
|
expect(find.byKey(const Key('project-popover')), findsNothing);
|
|
final mouse = await tester.createGesture(kind: PointerDeviceKind.mouse);
|
|
await mouse.addPointer(location: Offset.zero);
|
|
await mouse.moveTo(
|
|
tester.getCenter(find.byKey(const ValueKey('sidebar-project-project'))),
|
|
);
|
|
await tester.pumpAndSettle();
|
|
await tester.tap(
|
|
find.byKey(const ValueKey('new-agent-conversation-project')),
|
|
);
|
|
await mouse.removePointer();
|
|
await tester.pumpAndSettle();
|
|
expect(await tester.runAsync(repository.root.exists), isFalse);
|
|
});
|
|
|
|
testWidgets('sidebar mode is saved and restored after rebuilding the app', (
|
|
tester,
|
|
) async {
|
|
tester.view.physicalSize = const Size(1200, 800);
|
|
tester.view.devicePixelRatio = 1;
|
|
addTearDown(tester.view.resetPhysicalSize);
|
|
addTearDown(tester.view.resetDevicePixelRatio);
|
|
final settings = _MemoryWorkspaceViewSettings();
|
|
Future<void> launch() async {
|
|
await tester.pumpWidget(
|
|
ProviderScope(
|
|
key: UniqueKey(),
|
|
overrides: [
|
|
deviceExperienceProvider.overrideWithValue(
|
|
DeviceExperience.desktop,
|
|
),
|
|
projectsProvider.overrideWith(_TestProjects.new),
|
|
workspaceViewSettingsRepositoryProvider.overrideWithValue(settings),
|
|
conversationRepositoryProvider.overrideWith(
|
|
(ref) async => _GroupedConversationRepository({}),
|
|
),
|
|
],
|
|
child: const CutdexApp(),
|
|
),
|
|
);
|
|
await tester.pumpAndSettle();
|
|
}
|
|
|
|
Future<void> switchMode(String name) async {
|
|
ProviderScope.containerOf(tester.element(find.byType(CutdexApp)))
|
|
.read(workspaceViewSettingsProvider.notifier)
|
|
.setMode(WorkspaceMode.values.byName(name));
|
|
await ProviderScope.containerOf(tester.element(find.byType(CutdexApp)))
|
|
.read(workspaceViewSettingsProvider.notifier)
|
|
.save(activeProjectId: null);
|
|
await tester.pumpAndSettle();
|
|
}
|
|
|
|
await launch();
|
|
expect(find.byKey(const Key('desktop-agent-card')), findsOneWidget);
|
|
await switchMode('cut');
|
|
expect(settings.value.mode, WorkspaceMode.cut);
|
|
await tester.pumpWidget(const SizedBox());
|
|
await launch();
|
|
expect(find.byKey(const Key('desktop-project-card')), findsOneWidget);
|
|
await switchMode('agent');
|
|
expect(settings.value.mode, WorkspaceMode.agent);
|
|
await tester.pumpWidget(const SizedBox());
|
|
await launch();
|
|
expect(find.byKey(const Key('desktop-agent-card')), findsOneWidget);
|
|
});
|
|
|
|
testWidgets('sidebar mode defaults to Agent and can select Cut', (
|
|
tester,
|
|
) async {
|
|
tester.view.physicalSize = const Size(1200, 800);
|
|
tester.view.devicePixelRatio = 1;
|
|
addTearDown(tester.view.resetPhysicalSize);
|
|
addTearDown(tester.view.resetDevicePixelRatio);
|
|
await tester.pumpWidget(
|
|
ProviderScope(
|
|
overrides: [
|
|
deviceExperienceProvider.overrideWithValue(DeviceExperience.desktop),
|
|
conversationRepositoryProvider.overrideWith(
|
|
(ref) async => EmptyConversationRepository(),
|
|
),
|
|
projectsProvider.overrideWith(_TestProjects.new),
|
|
],
|
|
child: const CutdexApp(),
|
|
),
|
|
);
|
|
await tester.pumpAndSettle();
|
|
expect(find.byKey(const Key('desktop-agent-card')), findsOneWidget);
|
|
Color chatSurface() => tester
|
|
.element(find.byKey(const Key('agent-conversation')))
|
|
.findAncestorWidgetOfExactType<Material>()!
|
|
.color!;
|
|
ColorScheme chatColors() =>
|
|
Theme.of(tester.element(find.byKey(const Key('agent-conversation'))))
|
|
.colorScheme;
|
|
expect(
|
|
tester
|
|
.widget<SizedBox>(find.byKey(const Key('agent-conversation')))
|
|
.child,
|
|
isNot(isA<ColoredBox>()),
|
|
);
|
|
expect(chatSurface(), chatColors().surface);
|
|
final projectTitle = find.byKey(const Key('workspace-project-title'));
|
|
expect(
|
|
find.descendant(
|
|
of: find.byKey(const Key('agent-content-header')),
|
|
matching: projectTitle,
|
|
),
|
|
findsNothing,
|
|
);
|
|
final chatElement = tester.element(find.byType(AgentChatPanel));
|
|
final editorElement = tester.element(find.byType(EditorWorkspace));
|
|
final input = find.descendant(
|
|
of: find.byType(AgentChatPanel),
|
|
matching: find.byType(TextField),
|
|
);
|
|
await tester.enterText(input, 'Keep this draft');
|
|
expect(find.byKey(const Key('sidebar-mode-trigger')), findsNothing);
|
|
final container = ProviderScope.containerOf(
|
|
tester.element(find.byType(CutdexApp)),
|
|
);
|
|
container
|
|
.read(workspaceViewSettingsProvider.notifier)
|
|
.setMode(WorkspaceMode.cut);
|
|
await tester.pumpAndSettle();
|
|
expect(find.byKey(const Key('desktop-project-card')), findsOneWidget);
|
|
expect(chatSurface(), chatColors().surface);
|
|
expect(tester.element(find.byType(AgentChatPanel)), same(chatElement));
|
|
expect(tester.element(find.byType(EditorWorkspace)), same(editorElement));
|
|
expect(tester.widget<TextField>(input).controller!.text, 'Keep this draft');
|
|
container
|
|
.read(workspaceViewSettingsProvider.notifier)
|
|
.setMode(WorkspaceMode.agent);
|
|
await tester.pumpAndSettle();
|
|
expect(find.byKey(const Key('desktop-agent-card')), findsOneWidget);
|
|
expect(tester.element(find.byType(AgentChatPanel)), same(chatElement));
|
|
expect(tester.element(find.byType(EditorWorkspace)), same(editorElement));
|
|
expect(tester.widget<TextField>(input).controller!.text, 'Keep this draft');
|
|
});
|
|
|
|
testWidgets('Agent left gutter resizes independently and respects limits', (
|
|
tester,
|
|
) async {
|
|
tester.view.physicalSize = const Size(1200, 800);
|
|
tester.view.devicePixelRatio = 1;
|
|
addTearDown(tester.view.resetPhysicalSize);
|
|
addTearDown(tester.view.resetDevicePixelRatio);
|
|
await tester.pumpWidget(
|
|
ProviderScope(
|
|
overrides: [
|
|
deviceExperienceProvider.overrideWithValue(DeviceExperience.desktop),
|
|
conversationRepositoryProvider.overrideWith(
|
|
(ref) async => EmptyConversationRepository(),
|
|
),
|
|
projectsProvider.overrideWith(_TestProjects.new),
|
|
],
|
|
child: const CutdexApp(),
|
|
),
|
|
);
|
|
await tester.pumpAndSettle();
|
|
final navigation = find.byKey(const Key('sidebar-projects-conversations'));
|
|
final resize = find.byKey(const Key('agent-panel-resize'));
|
|
final navigationWidth = tester.getSize(navigation).width;
|
|
final chatWidth = tester.getSize(find.byType(AgentChatPanel)).width;
|
|
final chatElement = tester.element(find.byType(AgentChatPanel));
|
|
await tester.drag(resize, const Offset(-80, 0));
|
|
await tester.pumpAndSettle();
|
|
expect(tester.getSize(find.byType(AgentChatPanel)).width, chatWidth + 80);
|
|
expect(tester.getSize(navigation).width, navigationWidth);
|
|
expect(tester.element(find.byType(AgentChatPanel)), same(chatElement));
|
|
await tester.drag(resize, const Offset(2000, 0));
|
|
await tester.pumpAndSettle();
|
|
expect(
|
|
tester.getSize(find.byType(AgentChatPanel)).width,
|
|
greaterThanOrEqualTo(218),
|
|
);
|
|
await tester.drag(resize, const Offset(-2000, 0));
|
|
await tester.pumpAndSettle();
|
|
expect(find.byType(EditorWorkspace), findsOneWidget);
|
|
expect(tester.getSize(find.byType(EditorWorkspace)).width, 480);
|
|
expect(tester.getSize(navigation).width, navigationWidth);
|
|
expect(tester.takeException(), isNull);
|
|
});
|
|
|
|
testWidgets('Agent fullscreen preserves sidebar, draft and editor state', (
|
|
tester,
|
|
) async {
|
|
tester.view.physicalSize = const Size(1400, 800);
|
|
tester.view.devicePixelRatio = 1;
|
|
addTearDown(tester.view.resetPhysicalSize);
|
|
addTearDown(tester.view.resetDevicePixelRatio);
|
|
await tester.pumpWidget(
|
|
ProviderScope(
|
|
overrides: [
|
|
deviceExperienceProvider.overrideWithValue(DeviceExperience.desktop),
|
|
conversationRepositoryProvider.overrideWith(
|
|
(ref) async => EmptyConversationRepository(),
|
|
),
|
|
projectsProvider.overrideWith(_TestProjects.new),
|
|
],
|
|
child: const CutdexApp(),
|
|
),
|
|
);
|
|
await tester.pumpAndSettle();
|
|
final editor = tester.element(find.byType(EditorWorkspace));
|
|
final agent = tester.element(find.byType(AgentChatPanel));
|
|
final sidebar = find.byKey(const Key('sidebar-projects-conversations'));
|
|
final sidebarWidth = tester.getSize(sidebar).width;
|
|
final previewHeaderRect = tester.getRect(
|
|
find.byKey(const Key('editor-content-header')),
|
|
);
|
|
final agentHeaderRect = tester.getRect(
|
|
find.byKey(const Key('agent-content-header')),
|
|
);
|
|
expect(previewHeaderRect.top, agentHeaderRect.top);
|
|
expect(previewHeaderRect.bottom, agentHeaderRect.bottom);
|
|
expect(previewHeaderRect.height, 40);
|
|
expect(find.byKey(const Key('sidebar-tab-projects')), findsNothing);
|
|
final fullscreenRect = tester.getRect(
|
|
find.byKey(const Key('agent-fullscreen-button')),
|
|
);
|
|
expect(fullscreenRect.size, const Size.square(28));
|
|
final previewHeader = tester.getRect(
|
|
find.byKey(const Key('editor-content-header')),
|
|
);
|
|
final previewButton = tester.getRect(
|
|
find.byKey(const Key('editor-properties-button')),
|
|
);
|
|
expect(
|
|
previewHeader.right - previewButton.right,
|
|
AppSidebarMetrics.outerPadding,
|
|
);
|
|
final agentHeader = tester.getRect(
|
|
find.byKey(const Key('agent-content-header')),
|
|
);
|
|
expect(find.byKey(const Key('sidebar-tab-projects')), findsNothing);
|
|
expect(agentHeader.right - fullscreenRect.right, AppSpacing.gap);
|
|
expect(
|
|
fullscreenRect.center.dy,
|
|
tester.getCenter(find.byKey(const Key('editor-properties-button'))).dy,
|
|
);
|
|
final input = find.descendant(
|
|
of: find.byType(AgentChatPanel),
|
|
matching: find.byType(TextField),
|
|
);
|
|
await tester.enterText(input, 'Keep fullscreen draft');
|
|
final resize = find.byKey(const Key('agent-panel-resize'));
|
|
await tester.drag(resize, const Offset(-2000, 0));
|
|
await tester.pumpAndSettle();
|
|
expect(tester.getSize(find.byType(EditorWorkspace)).width, 480);
|
|
final agentWidth = tester.getSize(find.byType(AgentChatPanel)).width;
|
|
final fullscreen = find.byKey(const Key('agent-fullscreen-button'));
|
|
expect(tester.widget<IconButton>(fullscreen).isSelected, isFalse);
|
|
expect(
|
|
find.descendant(
|
|
of: find.byKey(const Key('agent-content-header')),
|
|
matching: fullscreen,
|
|
),
|
|
findsOneWidget,
|
|
);
|
|
await tester.tap(fullscreen);
|
|
await tester.pumpAndSettle();
|
|
expect(tester.widget<IconButton>(fullscreen).isSelected, isTrue);
|
|
expect(find.byType(EditorWorkspace), findsNothing);
|
|
expect(
|
|
tester.element(find.byType(EditorWorkspace, skipOffstage: false)),
|
|
same(editor),
|
|
);
|
|
expect(tester.getSize(sidebar).width, sidebarWidth);
|
|
expect(tester.element(find.byType(AgentChatPanel)), same(agent));
|
|
expect(resize, findsNothing);
|
|
expect(
|
|
tester.widget<TextField>(input).controller!.text,
|
|
'Keep fullscreen draft',
|
|
);
|
|
await tester.tap(fullscreen);
|
|
await tester.pumpAndSettle();
|
|
expect(tester.widget<IconButton>(fullscreen).isSelected, isFalse);
|
|
expect(tester.element(find.byType(EditorWorkspace)), same(editor));
|
|
expect(tester.getSize(find.byType(AgentChatPanel)).width, agentWidth);
|
|
expect(tester.getSize(sidebar).width, sidebarWidth);
|
|
expect(
|
|
tester.widget<TextField>(input).controller!.text,
|
|
'Keep fullscreen draft',
|
|
);
|
|
expect(resize, findsOneWidget);
|
|
await tester.tap(find.byKey(const Key('desktop-rail-cut')));
|
|
await tester.pumpAndSettle();
|
|
await tester.tap(fullscreen);
|
|
await tester.pumpAndSettle();
|
|
expect(find.byType(EditorWorkspace), findsNothing);
|
|
expect(tester.getSize(sidebar).width, sidebarWidth);
|
|
expect(tester.element(find.byType(AgentChatPanel)), same(agent));
|
|
await tester.tap(fullscreen);
|
|
await tester.pumpAndSettle();
|
|
expect(tester.element(find.byType(EditorWorkspace)), same(editor));
|
|
expect(tester.getSize(find.byType(AgentChatPanel)).width, agentWidth);
|
|
expect(tester.takeException(), isNull);
|
|
});
|
|
testWidgets('sidebar groups conversations under projects', (tester) async {
|
|
tester.platformDispatcher.platformBrightnessTestValue = Brightness.dark;
|
|
addTearDown(tester.platformDispatcher.clearPlatformBrightnessTestValue);
|
|
tester.view.physicalSize = const Size(1200, 800);
|
|
tester.view.devicePixelRatio = 1;
|
|
addTearDown(tester.view.resetPhysicalSize);
|
|
addTearDown(tester.view.resetDevicePixelRatio);
|
|
ConversationMetadata conversation(String projectId, int index) =>
|
|
ConversationMetadata(
|
|
id: '$projectId-$index',
|
|
projectId: projectId,
|
|
title: 'Conversation $index',
|
|
createdAt: DateTime.utc(2026, 9, 24),
|
|
updatedAt: DateTime.utc(2026, 9, 24),
|
|
providerId: 'provider',
|
|
modelId: 'model',
|
|
timelineId: projectId,
|
|
pending: false,
|
|
responseDurationsMs: const [],
|
|
);
|
|
final repository = _GroupedConversationRepository({
|
|
'project': [for (var i = 1; i <= 7; i++) conversation('project', i)],
|
|
'other': [conversation('other', 1)],
|
|
});
|
|
await tester.pumpWidget(
|
|
ProviderScope(
|
|
overrides: [
|
|
deviceExperienceProvider.overrideWithValue(DeviceExperience.desktop),
|
|
projectsProvider.overrideWith(_GroupedProjects.new),
|
|
conversationRepositoryProvider.overrideWith(
|
|
(ref) async => repository,
|
|
),
|
|
],
|
|
child: const CutdexApp(),
|
|
),
|
|
);
|
|
await tester.pumpAndSettle();
|
|
expect(
|
|
find.byKey(const ValueKey('sidebar-project-project')),
|
|
findsOneWidget,
|
|
);
|
|
expect(find.byKey(const ValueKey('sidebar-project-other')), findsOneWidget);
|
|
expect(
|
|
find.byKey(const ValueKey('sidebar-conversation-project-1')),
|
|
findsOneWidget,
|
|
);
|
|
expect(
|
|
find.byKey(const ValueKey('sidebar-conversation-project-6')),
|
|
findsNothing,
|
|
);
|
|
expect(
|
|
find.byKey(const ValueKey('sidebar-conversation-other-1')),
|
|
findsOneWidget,
|
|
);
|
|
final projectRow = find.byKey(const ValueKey('sidebar-project-project'));
|
|
final chatRow = find.byKey(
|
|
const ValueKey('sidebar-conversation-project-1'),
|
|
);
|
|
expect(tester.getSize(projectRow).height, 30);
|
|
expect(tester.getSize(chatRow).height, 30);
|
|
final selectedProjectTile = tester.widget<ListTile>(projectRow);
|
|
expect(selectedProjectTile.selected, isTrue);
|
|
expect(
|
|
selectedProjectTile.hoverColor,
|
|
AppSidebarColors.of(tester.element(projectRow)).hover,
|
|
);
|
|
expect(
|
|
selectedProjectTile.focusColor,
|
|
AppSidebarColors.of(tester.element(projectRow)).hover,
|
|
);
|
|
expect(find.byKey(const Key('sidebar-mode-trigger')), findsNothing);
|
|
expect(
|
|
tester.getTopLeft(find.byKey(const Key('projects-heading'))).dy -
|
|
tester
|
|
.getBottomLeft(find.byKey(const Key('projects-window-header')))
|
|
.dy,
|
|
AppSpacing.gap,
|
|
);
|
|
final conversationText = tester.widget<Text>(
|
|
find.descendant(of: chatRow, matching: find.text('Conversation 1')),
|
|
);
|
|
expect(conversationText.style?.fontSize, 14);
|
|
expect(conversationText.style?.height, closeTo(20 / 14, 0.001));
|
|
expect(conversationText.style?.fontVariations, isNull);
|
|
expect(
|
|
conversationText.style?.color,
|
|
const Color(0xFFFCFCFC).withValues(alpha: 0.85),
|
|
);
|
|
expect(
|
|
tester
|
|
.getTopLeft(
|
|
find.byKey(const ValueKey('sidebar-conversation-project-2')),
|
|
)
|
|
.dy -
|
|
tester.getTopLeft(chatRow).dy,
|
|
31,
|
|
);
|
|
expect(tester.getRect(chatRow).left, tester.getRect(projectRow).left);
|
|
expect(tester.getRect(chatRow).right, tester.getRect(projectRow).right);
|
|
expect(
|
|
tester
|
|
.getTopLeft(
|
|
find.descendant(of: chatRow, matching: find.text('Conversation 1')),
|
|
)
|
|
.dx,
|
|
tester
|
|
.getTopLeft(
|
|
find.descendant(of: projectRow, matching: find.byType(Text)).first,
|
|
)
|
|
.dx,
|
|
);
|
|
await tester.tap(chatRow, buttons: kSecondaryMouseButton);
|
|
await tester.pumpAndSettle();
|
|
await tester.tap(find.text('Rename'));
|
|
await tester.pumpAndSettle();
|
|
expect(find.byKey(const Key('app-dialog-frame')), findsOneWidget);
|
|
expect(find.text('Rename chat'), findsOneWidget);
|
|
expect(find.text('Keep it short and easy to recognize.'), findsOneWidget);
|
|
await tester.enterText(find.byType(TextFormField), 'Updated chat');
|
|
await tester.tap(find.widgetWithText(FilledButton, 'Save'));
|
|
await tester.pumpAndSettle();
|
|
expect(repository.groups['project']!.first.title, 'Updated chat');
|
|
expect(find.text('Updated chat'), findsOneWidget);
|
|
await tester.tap(chatRow, buttons: kSecondaryMouseButton);
|
|
await tester.pumpAndSettle();
|
|
await tester.tap(find.text('Delete permanently…'));
|
|
await tester.pumpAndSettle();
|
|
expect(find.byKey(const Key('app-dialog-frame')), findsOneWidget);
|
|
expect(find.textContaining('This cannot be undone.'), findsOneWidget);
|
|
await tester.tap(find.text('Cancel'));
|
|
await tester.pumpAndSettle();
|
|
expect(chatRow, findsOneWidget);
|
|
await tester.tap(
|
|
find.byKey(const ValueKey('sidebar-project-toggle-project')),
|
|
);
|
|
await tester.pumpAndSettle();
|
|
expect(chatRow, findsNothing);
|
|
expect(
|
|
tester
|
|
.getTopLeft(find.byKey(const ValueKey('sidebar-project-other')))
|
|
.dy -
|
|
tester.getBottomLeft(projectRow).dy,
|
|
1,
|
|
);
|
|
await tester.tap(
|
|
find.byKey(const ValueKey('sidebar-project-toggle-project')),
|
|
);
|
|
await tester.pumpAndSettle();
|
|
await tester.tap(find.text('Show more'));
|
|
await tester.pumpAndSettle();
|
|
expect(
|
|
find.byKey(const ValueKey('sidebar-conversation-project-7')),
|
|
findsOneWidget,
|
|
);
|
|
});
|
|
|
|
testWidgets(
|
|
'empty project hint follows expansion and project menu offers removal',
|
|
(tester) async {
|
|
tester.view.physicalSize = const Size(1200, 800);
|
|
tester.view.devicePixelRatio = 1;
|
|
addTearDown(tester.view.resetPhysicalSize);
|
|
addTearDown(tester.view.resetDevicePixelRatio);
|
|
await tester.pumpWidget(
|
|
ProviderScope(
|
|
overrides: [
|
|
deviceExperienceProvider.overrideWithValue(
|
|
DeviceExperience.desktop,
|
|
),
|
|
projectsProvider.overrideWith(_GroupedProjects.new),
|
|
conversationRepositoryProvider.overrideWith(
|
|
(ref) async => _GroupedConversationRepository({}),
|
|
),
|
|
],
|
|
child: const CutdexApp(),
|
|
),
|
|
);
|
|
await tester.pumpAndSettle();
|
|
final hint = find.byKey(const ValueKey('sidebar-project-empty-other'));
|
|
expect(hint, findsOneWidget);
|
|
await tester.tap(
|
|
find.byKey(const ValueKey('sidebar-project-toggle-other')),
|
|
);
|
|
await tester.pumpAndSettle();
|
|
expect(hint, findsNothing);
|
|
await tester.tap(
|
|
find.byKey(const ValueKey('sidebar-project-other')),
|
|
buttons: kSecondaryMouseButton,
|
|
);
|
|
await tester.pumpAndSettle();
|
|
expect(find.text('Remove from sidebar'), findsOneWidget);
|
|
},
|
|
);
|
|
|
|
testWidgets('project header more is inert and project rows switch projects', (
|
|
tester,
|
|
) async {
|
|
tester.view.physicalSize = const Size(1200, 800);
|
|
tester.view.devicePixelRatio = 1;
|
|
addTearDown(tester.view.resetPhysicalSize);
|
|
addTearDown(tester.view.resetDevicePixelRatio);
|
|
await tester.pumpWidget(
|
|
ProviderScope(
|
|
overrides: [
|
|
deviceExperienceProvider.overrideWithValue(DeviceExperience.desktop),
|
|
conversationRepositoryProvider.overrideWith(
|
|
(ref) async => EmptyConversationRepository(),
|
|
),
|
|
projectsProvider.overrideWith(_GroupedProjects.new),
|
|
],
|
|
child: const CutdexApp(),
|
|
),
|
|
);
|
|
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.pumpAndSettle();
|
|
await tester.tap(find.byKey(const Key('projects-more')));
|
|
await tester.pumpAndSettle();
|
|
expect(find.byKey(const Key('project-popover')), findsNothing);
|
|
await tester.tap(find.byKey(const ValueKey('sidebar-project-other')));
|
|
await tester.pumpAndSettle();
|
|
expect(
|
|
tester
|
|
.widget<ListTile>(find.byKey(const ValueKey('sidebar-project-other')))
|
|
.selected,
|
|
isTrue,
|
|
);
|
|
await tester.tap(find.byKey(const ValueKey('sidebar-project-project')));
|
|
await tester.pumpAndSettle();
|
|
expect(
|
|
tester
|
|
.widget<ListTile>(
|
|
find.byKey(const ValueKey('sidebar-project-project')),
|
|
)
|
|
.selected,
|
|
isTrue,
|
|
);
|
|
await mouse.removePointer();
|
|
});
|
|
|
|
test('dark workspace uses the configured panel palette', () {
|
|
final theme = EditorTheme.penDark;
|
|
expect(theme.colorScheme.surface, const Color(0xFF111111));
|
|
expect(theme.colorScheme.surfaceContainerLow, const Color(0xFF151515));
|
|
expect(
|
|
theme.colorScheme.outlineVariant,
|
|
const Color(0xFFFCFCFC).withValues(alpha: 0.084),
|
|
);
|
|
expect(
|
|
theme.extension<AppSurfaces>()!.composerBackground,
|
|
const Color(0xFF2F2F2F),
|
|
);
|
|
expect(
|
|
theme.extension<AppSurfaces>()!.popoverBackground,
|
|
const Color(0xFF242424),
|
|
);
|
|
});
|
|
|
|
testWidgets('project context menu renames its item', (tester) async {
|
|
tester.platformDispatcher.localesTestValue = const [Locale('zh')];
|
|
addTearDown(tester.platformDispatcher.clearLocalesTestValue);
|
|
tester.view.physicalSize = const Size(1200, 800);
|
|
tester.view.devicePixelRatio = 1;
|
|
addTearDown(tester.view.resetPhysicalSize);
|
|
addTearDown(tester.view.resetDevicePixelRatio);
|
|
final container = ProviderContainer(
|
|
overrides: [
|
|
deviceExperienceProvider.overrideWithValue(DeviceExperience.desktop),
|
|
conversationRepositoryProvider.overrideWith(
|
|
(ref) async => EmptyConversationRepository(),
|
|
),
|
|
projectsProvider.overrideWith(_TestProjects.new),
|
|
],
|
|
);
|
|
addTearDown(container.dispose);
|
|
await tester.pumpWidget(
|
|
UncontrolledProviderScope(container: container, child: const CutdexApp()),
|
|
);
|
|
await tester.pumpAndSettle();
|
|
|
|
Future<void> rename(Finder target, String value) async {
|
|
await tester.tap(target, buttons: kSecondaryMouseButton);
|
|
await tester.pumpAndSettle();
|
|
await tester.tap(find.text('重命名').last);
|
|
await tester.pumpAndSettle();
|
|
await tester.enterText(find.byType(TextFormField), value);
|
|
await tester.tap(find.widgetWithText(FilledButton, '重命名'));
|
|
await tester.pumpAndSettle();
|
|
}
|
|
|
|
await rename(
|
|
find.byKey(const ValueKey('sidebar-project-project')),
|
|
'重命名项目',
|
|
);
|
|
expect(
|
|
find.descendant(
|
|
of: find.byKey(const ValueKey('sidebar-project-project')),
|
|
matching: find.text('重命名项目'),
|
|
),
|
|
findsOneWidget,
|
|
);
|
|
await tester.pumpWidget(const SizedBox());
|
|
container.dispose();
|
|
});
|
|
|
|
testWidgets(
|
|
'switching timelines preserves the project workspace and its layout',
|
|
(tester) async {
|
|
tester.platformDispatcher.localesTestValue = const [Locale('zh')];
|
|
addTearDown(tester.platformDispatcher.clearLocalesTestValue);
|
|
tester.view.physicalSize = const Size(1440, 800);
|
|
tester.view.devicePixelRatio = 1;
|
|
addTearDown(tester.view.resetPhysicalSize);
|
|
addTearDown(tester.view.resetDevicePixelRatio);
|
|
final container = ProviderContainer(
|
|
overrides: [
|
|
deviceExperienceProvider.overrideWithValue(DeviceExperience.desktop),
|
|
conversationRepositoryProvider.overrideWith(
|
|
(ref) async => EmptyConversationRepository(),
|
|
),
|
|
projectsProvider.overrideWith(_SwitchProjects.new),
|
|
],
|
|
);
|
|
await tester.pumpWidget(
|
|
UncontrolledProviderScope(
|
|
container: container,
|
|
child: const CutdexApp(),
|
|
),
|
|
);
|
|
await tester.pumpAndSettle();
|
|
expect(
|
|
find.byKey(const ValueKey('timeline-tab-project')),
|
|
findsOneWidget,
|
|
);
|
|
expect(
|
|
tester.getSize(find.byKey(const Key('timeline-tabs-bar'))).height,
|
|
26,
|
|
);
|
|
expect(
|
|
find.descendant(
|
|
of: find.byKey(const Key('timeline-tabs-bar')),
|
|
matching: find.byType(VerticalDivider),
|
|
),
|
|
findsNothing,
|
|
);
|
|
expect(
|
|
find.descendant(
|
|
of: find.byKey(const Key('timeline-tabs-bar')),
|
|
matching: find.byType(ShaderMask),
|
|
),
|
|
findsOneWidget,
|
|
);
|
|
expect(
|
|
tester
|
|
.widget<TextButton>(
|
|
find.byKey(const ValueKey('timeline-tab-project')),
|
|
)
|
|
.style!
|
|
.textStyle!
|
|
.resolve({})!
|
|
.fontSize,
|
|
12,
|
|
);
|
|
final projectTabFinder = find.byKey(
|
|
const ValueKey('timeline-tab-project'),
|
|
);
|
|
final selectedInk = Theme.of(tester.element(projectTabFinder))
|
|
.colorScheme
|
|
.onSurface;
|
|
expect(
|
|
tester
|
|
.widget<TextButton>(projectTabFinder)
|
|
.style!
|
|
.backgroundColor!
|
|
.resolve({}),
|
|
selectedInk.withValues(alpha: .05),
|
|
);
|
|
expect(find.byKey(const ValueKey('timeline-tab-second')), findsOneWidget);
|
|
final tabs = find.byKey(const Key('timeline-tabs-list'));
|
|
final tabsScrollable = tester.state<ScrollableState>(
|
|
find.descendant(of: tabs, matching: find.byType(Scrollable)),
|
|
);
|
|
expect(tabsScrollable.position.maxScrollExtent, greaterThan(0));
|
|
await tester.sendEventToBinding(
|
|
PointerScrollEvent(
|
|
position: tester.getCenter(tabs),
|
|
scrollDelta: const Offset(0, 120),
|
|
),
|
|
);
|
|
await tester.pump();
|
|
expect(tabsScrollable.position.pixels, greaterThan(0));
|
|
tabsScrollable.position.jumpTo(0);
|
|
await tester.pump();
|
|
await tester.tap(find.byKey(const Key('timeline-list-button')));
|
|
await tester.pumpAndSettle();
|
|
expect(
|
|
find.byKey(const ValueKey('timeline-menu-project')),
|
|
findsOneWidget,
|
|
);
|
|
expect(
|
|
find.byKey(const ValueKey('timeline-menu-timeline-20')),
|
|
findsOneWidget,
|
|
);
|
|
await tester.tap(find.byKey(const ValueKey('timeline-menu-timeline-3')));
|
|
await tester.pumpAndSettle();
|
|
expect(
|
|
tester
|
|
.widget<EditorTimelinePanel>(find.byType(EditorTimelinePanel))
|
|
.timelineId,
|
|
'timeline-3',
|
|
);
|
|
final navigation = tester.element(
|
|
find.byKey(const Key('projects-heading')),
|
|
);
|
|
final workspace = tester.element(find.byType(EditorWorkspace));
|
|
await tester.tap(find.byKey(const Key('desktop-rail-library')));
|
|
await tester.pumpAndSettle();
|
|
await tester.tap(find.byKey(const Key('editor-properties-button')));
|
|
await tester.pumpAndSettle();
|
|
final timelineListButton = find.byKey(const Key('timeline-list-button'));
|
|
await tester.tap(timelineListButton);
|
|
await tester.pumpAndSettle();
|
|
final timelineMenuPanel = find.byWidgetPredicate(
|
|
(widget) => widget.runtimeType.toString() == '_MenuPanel',
|
|
);
|
|
expect(timelineMenuPanel, findsOneWidget);
|
|
expect(
|
|
tester.getRect(timelineMenuPanel).right,
|
|
closeTo(tester.getRect(timelineListButton).right, 1),
|
|
);
|
|
final menuRect = tester.getRect(timelineMenuPanel);
|
|
final buttonRect = tester.getRect(timelineListButton);
|
|
expect(
|
|
(menuRect.top - buttonRect.bottom - 4).abs() < 1 ||
|
|
(menuRect.bottom - buttonRect.top + 4).abs() < 1,
|
|
isTrue,
|
|
);
|
|
await tester.tap(timelineListButton);
|
|
await tester.pumpAndSettle();
|
|
final editorHeader = tester.element(
|
|
find.byKey(const Key('editor-content-header')),
|
|
);
|
|
final mediaPanel = tester.element(
|
|
find.byType(MediaPanel, skipOffstage: false),
|
|
);
|
|
final propertiesPanel = tester.element(
|
|
find.byType(EditorPropertiesPanel),
|
|
);
|
|
await tester.drag(
|
|
find.byKey(const Key('editor-timeline-resize')),
|
|
const Offset(0, -60),
|
|
);
|
|
await tester.pumpAndSettle();
|
|
final timelineHeight = tester
|
|
.getSize(find.byType(EditorTimelinePanel))
|
|
.height;
|
|
final taskButtonFinder = find.byKey(
|
|
const ValueKey('background-tasks-button'),
|
|
);
|
|
final taskButton = tester.element(taskButtonFinder);
|
|
expect(tester.widget<IconButton>(taskButtonFinder).onPressed, isNotNull);
|
|
for (final id in ['second', 'project', 'second']) {
|
|
final previousPreview = tester.element(find.byType(EditorPreviewPanel));
|
|
final previousTimeline = tester.element(
|
|
find.byType(EditorTimelinePanel),
|
|
);
|
|
await container
|
|
.read(projectsProvider.notifier)
|
|
.openTimeline('project', id);
|
|
await tester.pumpAndSettle();
|
|
expect(
|
|
tester.element(find.byKey(const Key('projects-window-header'))),
|
|
isNotNull,
|
|
);
|
|
expect(
|
|
tester.element(
|
|
find.byKey(const Key('projects-heading'), skipOffstage: false),
|
|
),
|
|
same(navigation),
|
|
);
|
|
expect(tester.element(find.byType(EditorWorkspace)), same(workspace));
|
|
expect(
|
|
tester.element(find.byKey(const Key('editor-content-header'))),
|
|
same(editorHeader),
|
|
);
|
|
expect(
|
|
tester.element(find.byType(EditorPreviewPanel)),
|
|
same(previousPreview),
|
|
);
|
|
expect(
|
|
tester.element(find.byType(EditorTimelinePanel)),
|
|
same(previousTimeline),
|
|
);
|
|
expect(
|
|
tester.element(find.byType(MediaPanel, skipOffstage: false)),
|
|
same(mediaPanel),
|
|
);
|
|
expect(
|
|
tester.element(find.byType(EditorPropertiesPanel)),
|
|
same(propertiesPanel),
|
|
);
|
|
expect(tester.element(taskButtonFinder), same(taskButton));
|
|
expect(
|
|
tester.widget<IconButton>(taskButtonFinder).onPressed,
|
|
isNotNull,
|
|
);
|
|
expect(
|
|
find.byKey(const Key('media-panel-surface'), skipOffstage: false),
|
|
findsOneWidget,
|
|
);
|
|
expect(
|
|
find.byKey(const Key('editor-properties-region')),
|
|
findsOneWidget,
|
|
);
|
|
expect(
|
|
tester.getSize(find.byType(EditorTimelinePanel)).height,
|
|
timelineHeight,
|
|
);
|
|
expect(
|
|
tester
|
|
.widget<EditorTimelinePanel>(find.byType(EditorTimelinePanel))
|
|
.timelineId,
|
|
id,
|
|
);
|
|
expect(find.byKey(const Key('workspace-project-title')), findsNothing);
|
|
expect(
|
|
tester
|
|
.widget<TextButton>(find.byKey(ValueKey('timeline-tab-$id')))
|
|
.onPressed,
|
|
isNotNull,
|
|
);
|
|
expect(tester.takeException(), isNull);
|
|
}
|
|
await tester.tap(find.byKey(const Key('timeline-list-button')));
|
|
await tester.pumpAndSettle();
|
|
await tester.ensureVisible(
|
|
find.byKey(const ValueKey('timeline-menu-timeline-20')),
|
|
);
|
|
await tester.tap(find.byKey(const ValueKey('timeline-menu-timeline-20')));
|
|
await tester.pumpAndSettle();
|
|
final selectedTab = tester.getRect(
|
|
find.byKey(const ValueKey('timeline-tab-timeline-20')),
|
|
);
|
|
final tabsViewport = tester.getRect(tabs);
|
|
expect(selectedTab.left, greaterThanOrEqualTo(tabsViewport.left));
|
|
expect(selectedTab.right, lessThanOrEqualTo(tabsViewport.right));
|
|
expect(tabsScrollable.position.pixels, greaterThan(0));
|
|
await tester.tap(find.byKey(const Key('timeline-list-button')));
|
|
await tester.pumpAndSettle();
|
|
final selectedMenuItem = find.byKey(
|
|
const ValueKey('timeline-menu-timeline-20'),
|
|
);
|
|
final menuScrollView = find
|
|
.ancestor(
|
|
of: selectedMenuItem,
|
|
matching: find.byType(SingleChildScrollView),
|
|
)
|
|
.first;
|
|
expect(
|
|
tester.getRect(selectedMenuItem).bottom,
|
|
lessThanOrEqualTo(tester.getRect(menuScrollView).bottom),
|
|
);
|
|
expect(
|
|
tester
|
|
.state<ScrollableState>(
|
|
find.descendant(
|
|
of: menuScrollView,
|
|
matching: find.byType(Scrollable),
|
|
),
|
|
)
|
|
.position
|
|
.pixels,
|
|
greaterThan(0),
|
|
);
|
|
await tester.tap(find.byKey(const Key('timeline-list-button')));
|
|
await tester.pumpAndSettle();
|
|
final previousTabOffset = tabsScrollable.position.pixels;
|
|
await container
|
|
.read(projectsProvider.notifier)
|
|
.openTimeline('project', 'timeline-19');
|
|
await tester.pumpAndSettle();
|
|
expect(tabsScrollable.position.pixels, previousTabOffset);
|
|
final nearbyTab = tester.getRect(
|
|
find.byKey(const ValueKey('timeline-tab-timeline-19')),
|
|
);
|
|
expect(nearbyTab.left, greaterThanOrEqualTo(tabsViewport.left));
|
|
expect(nearbyTab.right, lessThanOrEqualTo(tabsViewport.right));
|
|
await tester.pumpWidget(const SizedBox());
|
|
container.dispose();
|
|
},
|
|
);
|
|
|
|
testWidgets('timeline tab context menu pins, renames, and deletes', (
|
|
tester,
|
|
) async {
|
|
tester.platformDispatcher.localesTestValue = const [Locale('zh')];
|
|
addTearDown(tester.platformDispatcher.clearLocalesTestValue);
|
|
tester.view.physicalSize = const Size(1200, 800);
|
|
tester.view.devicePixelRatio = 1;
|
|
addTearDown(tester.view.resetPhysicalSize);
|
|
addTearDown(tester.view.resetDevicePixelRatio);
|
|
final container = ProviderContainer(
|
|
overrides: [
|
|
deviceExperienceProvider.overrideWithValue(DeviceExperience.desktop),
|
|
conversationRepositoryProvider.overrideWith(
|
|
(ref) async => EmptyConversationRepository(),
|
|
),
|
|
projectsProvider.overrideWith(_SwitchProjects.new),
|
|
],
|
|
);
|
|
addTearDown(container.dispose);
|
|
await tester.pumpWidget(
|
|
UncontrolledProviderScope(container: container, child: const CutdexApp()),
|
|
);
|
|
await tester.pumpAndSettle();
|
|
|
|
Future<void> openMenu() async {
|
|
await tester.tap(
|
|
find.byKey(const ValueKey('timeline-tab-second')),
|
|
buttons: kSecondaryMouseButton,
|
|
);
|
|
await tester.pumpAndSettle();
|
|
}
|
|
|
|
await openMenu();
|
|
await tester.tap(find.byKey(const ValueKey('timeline-pin-second')));
|
|
await tester.pumpAndSettle();
|
|
expect(
|
|
container.read(projectsProvider).requireValue.timelines.first.id,
|
|
'second',
|
|
);
|
|
expect(
|
|
container.read(projectsProvider).requireValue.timelines.first.pinned,
|
|
isTrue,
|
|
);
|
|
|
|
await openMenu();
|
|
await tester.tap(find.byKey(const ValueKey('timeline-rename-second')));
|
|
await tester.pumpAndSettle();
|
|
await tester.enterText(find.byType(TextFormField), '已重命名时间线');
|
|
await tester.tap(find.widgetWithText(FilledButton, '重命名'));
|
|
await tester.pumpAndSettle();
|
|
expect(
|
|
container.read(projectsProvider).requireValue.timelines.first.name,
|
|
'已重命名时间线',
|
|
);
|
|
|
|
await openMenu();
|
|
await tester.tap(find.byKey(const ValueKey('timeline-delete-second')));
|
|
await tester.pumpAndSettle();
|
|
expect(find.textContaining('已重命名时间线'), findsWidgets);
|
|
await tester.tap(find.widgetWithText(FilledButton, '删除'));
|
|
await tester.pumpAndSettle();
|
|
expect(
|
|
container
|
|
.read(projectsProvider)
|
|
.requireValue
|
|
.timelines
|
|
.any((item) => item.id == 'second'),
|
|
isFalse,
|
|
);
|
|
await tester.pumpWidget(const SizedBox());
|
|
container.dispose();
|
|
});
|
|
|
|
testWidgets('timeline limit is enforced and explained on click', (
|
|
tester,
|
|
) async {
|
|
tester.platformDispatcher.localesTestValue = const [Locale('zh')];
|
|
addTearDown(tester.platformDispatcher.clearLocalesTestValue);
|
|
tester.view.physicalSize = const Size(1200, 800);
|
|
tester.view.devicePixelRatio = 1;
|
|
addTearDown(tester.view.resetPhysicalSize);
|
|
addTearDown(tester.view.resetDevicePixelRatio);
|
|
final container = ProviderContainer(
|
|
overrides: [
|
|
deviceExperienceProvider.overrideWithValue(DeviceExperience.desktop),
|
|
conversationRepositoryProvider.overrideWith(
|
|
(ref) async => EmptyConversationRepository(),
|
|
),
|
|
projectsProvider.overrideWith(_TimelineLimitProjects.new),
|
|
],
|
|
);
|
|
await tester.pumpWidget(
|
|
UncontrolledProviderScope(container: container, child: const CutdexApp()),
|
|
);
|
|
await tester.pumpAndSettle();
|
|
|
|
expect(
|
|
container.read(projectsProvider).requireValue.timelines,
|
|
hasLength(Projects.maxTimelineCount),
|
|
);
|
|
expect(
|
|
await container.read(projectsProvider.notifier).createTimeline(),
|
|
isFalse,
|
|
);
|
|
final addButton = find.byKey(const Key('timeline-add-button'));
|
|
expect(tester.widget<IconButton>(addButton).onPressed, isNotNull);
|
|
await tester.tap(addButton);
|
|
await tester.pump();
|
|
expect(find.text('每个项目最多可创建 50 条时间线。'), findsOneWidget);
|
|
|
|
await tester.pumpWidget(const SizedBox());
|
|
container.dispose();
|
|
});
|
|
|
|
testWidgets('macOS single editing surface integrates native controls', (
|
|
tester,
|
|
) async {
|
|
tester.platformDispatcher.localesTestValue = const [Locale('zh')];
|
|
addTearDown(tester.platformDispatcher.clearLocalesTestValue);
|
|
debugDefaultTargetPlatformOverride = TargetPlatform.macOS;
|
|
addTearDown(() => debugDefaultTargetPlatformOverride = null);
|
|
tester.view.physicalSize = const Size(1200, 800);
|
|
tester.view.devicePixelRatio = 1;
|
|
tester.view.padding = const FakeViewPadding(top: 28);
|
|
addTearDown(tester.view.resetPhysicalSize);
|
|
addTearDown(tester.view.resetDevicePixelRatio);
|
|
addTearDown(tester.view.resetPadding);
|
|
const channel = MethodChannel('cutdex_native/window');
|
|
final calls = <bool>[];
|
|
final closeModes = <bool>[];
|
|
const controlsChannel = MethodChannel('cutdex_native/window_controls');
|
|
final controlRegions = <String, Rect>{};
|
|
final messenger =
|
|
TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger;
|
|
messenger.setMockMethodCallHandler(channel, (call) async {
|
|
final enabled = (call.arguments as Map)['enabled'] as bool;
|
|
calls.add(enabled);
|
|
if (enabled) {
|
|
closeModes.add((call.arguments as Map)['interceptClose'] as bool);
|
|
}
|
|
return enabled;
|
|
});
|
|
addTearDown(() => messenger.setMockMethodCallHandler(channel, null));
|
|
messenger.setMockMethodCallHandler(controlsChannel, (call) async {
|
|
final arguments = call.arguments as Map;
|
|
final id = arguments['id'] as String;
|
|
final rect = arguments['rect'] as Map?;
|
|
if (rect == null) {
|
|
controlRegions.remove(id);
|
|
} else {
|
|
controlRegions[id] = Rect.fromLTWH(
|
|
(rect['x'] as num).toDouble(),
|
|
(rect['y'] as num).toDouble(),
|
|
(rect['width'] as num).toDouble(),
|
|
(rect['height'] as num).toDouble(),
|
|
);
|
|
}
|
|
return null;
|
|
});
|
|
addTearDown(
|
|
() => messenger.setMockMethodCallHandler(controlsChannel, null),
|
|
);
|
|
await tester.pumpWidget(
|
|
ProviderScope(
|
|
overrides: [
|
|
deviceExperienceProvider.overrideWithValue(DeviceExperience.desktop),
|
|
conversationRepositoryProvider.overrideWith(
|
|
(ref) async => EmptyConversationRepository(),
|
|
),
|
|
projectsProvider.overrideWith(_TestProjects.new),
|
|
],
|
|
child: const CutdexApp(),
|
|
),
|
|
);
|
|
await tester.pumpAndSettle();
|
|
expect(
|
|
tester.getTopLeft(find.byKey(const Key('projects-window-header'))).dy,
|
|
41.0,
|
|
);
|
|
expect(find.byKey(const Key('sidebar-mode-trigger')), findsNothing);
|
|
expect(
|
|
tester.getSize(find.byKey(const Key('native-window-controls-space'))),
|
|
const Size(88, 40),
|
|
);
|
|
expect(
|
|
tester.getSize(find.byKey(const Key('project-sidebar-divider'))).width,
|
|
1,
|
|
);
|
|
expect(
|
|
tester.getSize(find.byKey(const Key('project-sidebar-divider'))).height,
|
|
tester.getSize(find.byKey(const Key('desktop-editor-card'))).height,
|
|
);
|
|
final sidebarToggle = find.byKey(const Key('project-sidebar-toggle'));
|
|
expect(tester.getRect(sidebarToggle).center.dy, 20.0);
|
|
final projectSettings = find.byKey(const Key('project-settings-button'));
|
|
final backgroundTasks = find.byKey(
|
|
const ValueKey('background-tasks-button'),
|
|
);
|
|
expect(projectSettings, findsOneWidget);
|
|
expect(backgroundTasks, findsOneWidget);
|
|
expect(tester.getRect(projectSettings).center.dx, 22);
|
|
expect(
|
|
tester.getRect(projectSettings).bottom,
|
|
tester.getRect(find.byKey(const Key('desktop-navigation-rail'))).bottom -
|
|
10,
|
|
);
|
|
expect(tester.getTopLeft(sidebarToggle).dx, 96);
|
|
expect(tester.getSize(sidebarToggle), const Size.square(28));
|
|
expect(tester.getSize(backgroundTasks), const Size.square(28));
|
|
expect(
|
|
tester.getRect(sidebarToggle).center.dx - 88,
|
|
tester.getRect(find.byKey(const Key('desktop-rail-cut'))).center.dx,
|
|
);
|
|
await tester.tap(sidebarToggle);
|
|
await tester.pump();
|
|
expect(find.byKey(const ValueKey('open-project-project')), findsNothing);
|
|
expect(find.byTooltip('展开侧边栏'), findsOneWidget);
|
|
expect(find.byKey(const Key('desktop-workspace-mode')), findsNothing);
|
|
expect(projectSettings, findsOneWidget);
|
|
expect(backgroundTasks, findsOneWidget);
|
|
expect(find.byKey(const Key('workspace-project-title')), findsNothing);
|
|
expect(
|
|
tester.getTopLeft(find.byType(EditorPreviewPanel)).dx,
|
|
tester.getRect(find.byKey(const Key('desktop-editor-card'))).left + 1,
|
|
);
|
|
expect(sidebarToggle, findsOneWidget);
|
|
await tester.tap(sidebarToggle);
|
|
await tester.pump();
|
|
expect(find.byKey(const Key('projects-heading')), findsOneWidget);
|
|
expect(find.byTooltip('收起侧边栏'), findsOneWidget);
|
|
await _hoverProjectHeader(tester);
|
|
await tester.tap(find.byKey(const Key('projects-more')));
|
|
await tester.pumpAndSettle();
|
|
expect(find.byKey(const Key('project-popover')), findsNothing);
|
|
expect(
|
|
find.byKey(const ValueKey('sidebar-project-project')),
|
|
findsOneWidget,
|
|
);
|
|
expect(find.byKey(const ValueKey('open-timeline-project')), findsNothing);
|
|
expect(
|
|
tester
|
|
.getSize(find.byKey(const ValueKey('sidebar-project-project')))
|
|
.height,
|
|
30,
|
|
);
|
|
final projectTitle = tester.widget<Text>(
|
|
find.descendant(
|
|
of: find.byKey(const ValueKey('sidebar-project-project')),
|
|
matching: find.text('测试项目'),
|
|
),
|
|
);
|
|
expect(projectTitle.style?.fontSize, 14);
|
|
final projectRow = find.byKey(const ValueKey('sidebar-project-project'));
|
|
expect(
|
|
find.descendant(of: projectRow, matching: find.byIcon(Icons.add)),
|
|
findsNothing,
|
|
);
|
|
expect(find.byKey(const Key('projects-section-header')), findsNothing);
|
|
expect(find.byKey(const Key('projects-more')), findsOneWidget);
|
|
expect(
|
|
tester.getSize(find.byKey(const Key('create-project'))),
|
|
const Size.square(24),
|
|
);
|
|
expect(
|
|
tester.getRect(find.byKey(const Key('projects-heading'))).right +
|
|
AppSpacing.tiny,
|
|
tester.getRect(find.byKey(const Key('projects-more'))).left,
|
|
);
|
|
expect(
|
|
find.descendant(of: projectRow, matching: find.byIcon(Icons.add)),
|
|
findsNothing,
|
|
);
|
|
expect(
|
|
tester.getTopLeft(find.byKey(const Key('project-sidebar-resize'))).dx,
|
|
302,
|
|
);
|
|
expect(
|
|
tester.getTopLeft(find.byType(EditorPreviewPanel)).dy,
|
|
tester.getRect(find.byKey(const Key('editor-content-header'))).bottom,
|
|
);
|
|
expect(find.byKey(const Key('editor-content-header')), findsOneWidget);
|
|
tester.view.physicalSize = const Size(500, 450);
|
|
await tester.pumpAndSettle();
|
|
final navigationButton = find.byKey(const Key('project-sidebar-toggle'));
|
|
expect(
|
|
controlRegions.values.any(
|
|
(region) => region.contains(tester.getCenter(navigationButton)),
|
|
),
|
|
isTrue,
|
|
reason: 'AppKit must forward navigation clicks instead of dragging.',
|
|
);
|
|
await tester.tap(navigationButton);
|
|
await tester.pumpAndSettle();
|
|
expect(
|
|
find.byKey(const ValueKey('sidebar-project-project')),
|
|
findsOneWidget,
|
|
);
|
|
final closeNavigation = find.byTooltip('关闭');
|
|
expect(tester.getRect(closeNavigation).left, greaterThanOrEqualTo(44));
|
|
expect(
|
|
controlRegions.values.any(
|
|
(region) => region.contains(tester.getCenter(closeNavigation)),
|
|
),
|
|
isTrue,
|
|
);
|
|
await tester.tap(closeNavigation);
|
|
await tester.pumpAndSettle();
|
|
expect(
|
|
tester.getRect(find.byKey(const Key('agent-content-header'))).left,
|
|
45,
|
|
);
|
|
final reply = Completer<ByteData?>();
|
|
messenger.handlePlatformMessage(
|
|
channel.name,
|
|
const StandardMethodCodec().encodeMethodCall(
|
|
const MethodCall('requestClose'),
|
|
),
|
|
reply.complete,
|
|
);
|
|
expect(
|
|
const StandardMethodCodec().decodeEnvelope((await reply.future)!),
|
|
isFalse,
|
|
);
|
|
await tester.pumpAndSettle();
|
|
expect(find.textContaining('测试项目'), findsWidgets);
|
|
expect(calls, [true]);
|
|
expect(closeModes, [false]);
|
|
expect(
|
|
tester.getTopLeft(find.byKey(const Key('agent-content-header'))).dy,
|
|
41.0,
|
|
);
|
|
expect(tester.takeException(), isNull);
|
|
debugDefaultTargetPlatformOverride = null;
|
|
});
|
|
|
|
testWidgets('editing page keeps sidebar and editing workspace', (
|
|
tester,
|
|
) async {
|
|
tester.platformDispatcher.localesTestValue = const [Locale('zh')];
|
|
addTearDown(tester.platformDispatcher.clearLocalesTestValue);
|
|
tester.view.physicalSize = const Size(2000, 900);
|
|
tester.view.devicePixelRatio = 1;
|
|
addTearDown(tester.view.resetPhysicalSize);
|
|
addTearDown(tester.view.resetDevicePixelRatio);
|
|
await tester.pumpWidget(
|
|
ProviderScope(
|
|
overrides: [
|
|
deviceExperienceProvider.overrideWithValue(DeviceExperience.desktop),
|
|
conversationRepositoryProvider.overrideWith(
|
|
(ref) async => EmptyConversationRepository(),
|
|
),
|
|
projectsProvider.overrideWith(_TestProjects.new),
|
|
],
|
|
child: const CutdexApp(),
|
|
),
|
|
);
|
|
await tester.pumpAndSettle();
|
|
final projectHeading = find.byKey(const Key('projects-heading'));
|
|
final createProjectButton = find.byKey(const Key('create-project'));
|
|
expect(projectHeading, findsOneWidget);
|
|
expect(createProjectButton, findsOneWidget);
|
|
expect(
|
|
tester.getRect(projectHeading).right + AppSpacing.tiny,
|
|
tester.getRect(find.byKey(const Key('projects-more'))).left,
|
|
);
|
|
expect(find.byKey(const ValueKey('open-project-project')), findsNothing);
|
|
expect(find.byKey(const ValueKey('open-timeline-project')), findsNothing);
|
|
expect(find.byType(AgentChatPanel), findsOneWidget);
|
|
final upperSidebar = find.byKey(
|
|
const Key('sidebar-projects-conversations'),
|
|
);
|
|
final projectCard = tester.getRect(
|
|
find.byKey(const Key('desktop-project-card')),
|
|
);
|
|
final editorCard = tester.getRect(
|
|
find.byKey(const Key('desktop-editor-card')),
|
|
);
|
|
final agentCard = tester.getRect(
|
|
find.byKey(const Key('desktop-agent-card')),
|
|
);
|
|
expect(upperSidebar, findsOneWidget);
|
|
expect(editorCard.left - projectCard.right, 1);
|
|
expect(agentCard.left - editorCard.right, 1);
|
|
expect(
|
|
tester.getRect(find.byKey(const Key('agent-composer'))).bottom,
|
|
lessThanOrEqualTo(tester.getRect(find.byType(AgentChatPanel)).bottom),
|
|
);
|
|
expect(
|
|
tester.getRect(find.byType(EditorWorkspace)).right,
|
|
lessThanOrEqualTo(tester.getRect(find.byType(AgentChatPanel)).left),
|
|
);
|
|
await _hoverProjectHeader(tester);
|
|
await tester.tap(find.byKey(const Key('projects-more')));
|
|
await tester.pumpAndSettle();
|
|
expect(find.byKey(const Key('projects-section-header')), findsNothing);
|
|
expect(find.byKey(const Key('project-popover')), findsNothing);
|
|
expect(find.byKey(const ValueKey('open-timeline-project')), findsNothing);
|
|
expect(find.byKey(const Key('editor-content-header')), findsOneWidget);
|
|
expect(find.byKey(const Key('editor-media-button')), findsNothing);
|
|
expect(find.byKey(const Key('timeline-tabs-bar')), findsOneWidget);
|
|
expect(find.byKey(const Key('timeline-add-button')), findsOneWidget);
|
|
expect(find.byKey(const ValueKey('timeline-tab-project')), findsOneWidget);
|
|
await tester.tap(find.byKey(const Key('timeline-add-button')));
|
|
await tester.pumpAndSettle();
|
|
expect(find.text('时间线 1'), findsWidgets);
|
|
expect(
|
|
find.byKey(const ValueKey('timeline-tab-created-1')),
|
|
findsOneWidget,
|
|
);
|
|
expect(find.byKey(const Key('workspace-project-title')), findsNothing);
|
|
final sidebarDivider = find.byKey(const Key('project-sidebar-resize'));
|
|
final sidebarLeftBefore = tester.getTopLeft(sidebarDivider).dx;
|
|
await tester.drag(sidebarDivider, const Offset(80, 0));
|
|
await tester.pumpAndSettle();
|
|
expect(
|
|
tester.getTopLeft(sidebarDivider).dx,
|
|
greaterThan(sidebarLeftBefore),
|
|
);
|
|
final agentWidth = tester.getSize(find.byType(AgentChatPanel)).width;
|
|
await tester.drag(sidebarDivider, const Offset(2000, 0));
|
|
await tester.pumpAndSettle();
|
|
expect(
|
|
tester
|
|
.getSize(find.byKey(const Key('sidebar-projects-conversations')))
|
|
.width,
|
|
358,
|
|
);
|
|
expect(tester.getSize(find.byType(AgentChatPanel)).width, agentWidth);
|
|
final preview = tester.getTopLeft(find.byType(EditorPreviewPanel));
|
|
final timeline = tester.getTopLeft(find.byType(EditorTimelinePanel));
|
|
expect(
|
|
tester.getRect(find.byKey(const Key('editor-timeline-card'))).top -
|
|
tester.getRect(find.byKey(const Key('editor-preview-card'))).bottom,
|
|
1,
|
|
);
|
|
expect(timeline.dx, tester.getTopLeft(find.byType(EditorPreviewPanel)).dx);
|
|
expect(timeline.dy, greaterThan(preview.dy));
|
|
expect(find.byType(AgentChatPanel), findsOneWidget);
|
|
expect(find.byKey(const Key('agent-top-divider')), findsNothing);
|
|
expect(find.byType(EditorPropertiesPanel), findsNothing);
|
|
final editingPropertiesButton = find.byKey(
|
|
const Key('editor-properties-button'),
|
|
);
|
|
expect(editingPropertiesButton, findsOneWidget);
|
|
await tester.tap(editingPropertiesButton);
|
|
await tester.pumpAndSettle();
|
|
expect(find.byType(EditorPropertiesPanel), findsOneWidget);
|
|
await tester.tap(editingPropertiesButton);
|
|
await tester.pumpAndSettle();
|
|
expect(find.byType(EditorPropertiesPanel), findsNothing);
|
|
expect(tester.takeException(), isNull);
|
|
|
|
final timelineResize = find.byKey(const Key('editor-timeline-resize'));
|
|
final timelineHeightBefore = tester
|
|
.getSize(find.byType(EditorTimelinePanel))
|
|
.height;
|
|
await tester.drag(timelineResize, const Offset(0, -80));
|
|
await tester.pumpAndSettle();
|
|
expect(
|
|
tester.getSize(find.byType(EditorTimelinePanel)).height,
|
|
greaterThan(timelineHeightBefore),
|
|
);
|
|
|
|
expect(find.byKey(const Key('editor-media-button')), findsNothing);
|
|
expect(find.byKey(const Key('workspace-layout-menu')), findsNothing);
|
|
expect(find.byKey(const Key('editor-editing-toggle')), findsNothing);
|
|
expect(find.byKey(const Key('agent-editing-divider')), findsNothing);
|
|
expect(
|
|
tester.getTopLeft(find.byType(EditorTimelinePanel)).dy,
|
|
greaterThan(tester.getTopLeft(find.byType(EditorPreviewPanel)).dy),
|
|
);
|
|
|
|
final editorElement = tester.element(find.byType(EditorWorkspace));
|
|
await tester.tap(find.byKey(const Key('desktop-rail-library')));
|
|
await tester.pumpAndSettle();
|
|
expect(find.byType(MediaPanel), findsOneWidget);
|
|
expect(find.byType(EditorWorkspace), findsOneWidget);
|
|
expect(find.byType(Dialog), findsNothing);
|
|
final mediaRegion = find.byKey(const Key('media-panel-surface'));
|
|
expect(
|
|
tester
|
|
.getRect(find.byKey(const Key('desktop-project-card')))
|
|
.contains(tester.getRect(mediaRegion).center),
|
|
isTrue,
|
|
);
|
|
final mediaElement = tester.element(find.byType(MediaPanel));
|
|
await tester.tap(find.byKey(const Key('media-layout-toggle')));
|
|
await tester.pumpAndSettle();
|
|
expect(find.byTooltip('宫格布局'), findsOneWidget);
|
|
await tester.tap(find.byKey(const Key('desktop-rail-cut')));
|
|
await tester.pumpAndSettle();
|
|
expect(mediaRegion, findsNothing);
|
|
expect(tester.element(find.byType(EditorWorkspace)), same(editorElement));
|
|
await tester.tap(find.byKey(const Key('editor-properties-button')));
|
|
await tester.pumpAndSettle();
|
|
final propertiesRegion = find.byKey(const Key('editor-properties-region'));
|
|
expect(propertiesRegion, findsOneWidget);
|
|
await tester.tap(find.byKey(const Key('desktop-rail-library')));
|
|
await tester.pumpAndSettle();
|
|
expect(tester.element(find.byType(MediaPanel)), same(mediaElement));
|
|
expect(propertiesRegion, findsOneWidget);
|
|
expect(find.byTooltip('宫格布局'), findsOneWidget);
|
|
await tester.tap(find.byKey(const Key('desktop-rail-cut')));
|
|
await tester.pumpAndSettle();
|
|
expect(propertiesRegion, findsOneWidget);
|
|
expect(tester.element(find.byType(EditorWorkspace)), same(editorElement));
|
|
expect(tester.takeException(), isNull);
|
|
});
|
|
for (final locale in const [
|
|
Locale('en'),
|
|
Locale.fromSubtags(languageCode: 'zh', scriptCode: 'Hans'),
|
|
Locale.fromSubtags(languageCode: 'zh', scriptCode: 'Hant'),
|
|
Locale('ja'),
|
|
Locale('ko'),
|
|
Locale('fr'),
|
|
Locale('de'),
|
|
Locale('es'),
|
|
Locale('pt'),
|
|
Locale('it'),
|
|
Locale('ru'),
|
|
]) {
|
|
testWidgets('small editor viewport fits in $locale', (tester) async {
|
|
tester.platformDispatcher.localesTestValue = [locale];
|
|
addTearDown(tester.platformDispatcher.clearLocalesTestValue);
|
|
tester.view.physicalSize = const Size(600, 450);
|
|
tester.view.devicePixelRatio = 1;
|
|
addTearDown(tester.view.resetPhysicalSize);
|
|
addTearDown(tester.view.resetDevicePixelRatio);
|
|
await tester.pumpWidget(
|
|
ProviderScope(
|
|
overrides: [
|
|
deviceExperienceProvider.overrideWithValue(
|
|
DeviceExperience.desktop,
|
|
),
|
|
conversationRepositoryProvider.overrideWith(
|
|
(ref) async => EmptyConversationRepository(),
|
|
),
|
|
projectsProvider.overrideWith(_TestProjects.new),
|
|
],
|
|
child: const CutdexApp(),
|
|
),
|
|
);
|
|
await tester.pumpAndSettle();
|
|
await tester.tap(find.byKey(const Key('desktop-rail-cut')));
|
|
await tester.pumpAndSettle();
|
|
expect(
|
|
find.ancestor(
|
|
of: find.byType(EditorTimelinePanel),
|
|
matching: find.byType(SingleChildScrollView),
|
|
),
|
|
findsNothing,
|
|
);
|
|
expect(find.text('视频预览'), findsNothing);
|
|
expect(find.text('属性'), findsNothing);
|
|
final timeline = tester.getRect(find.byType(EditorTimelinePanel));
|
|
expect(timeline.right, lessThanOrEqualTo(600));
|
|
expect(timeline.bottom, lessThanOrEqualTo(450));
|
|
final shellContext = tester.element(find.byType(EditorTimelinePanel));
|
|
expect(Directionality.of(shellContext), TextDirection.ltr);
|
|
expect(tester.takeException(), isNull);
|
|
addTearDown(tester.platformDispatcher.clearTextScaleFactorTestValue);
|
|
for (final scale in [1.5, 2.0]) {
|
|
tester.platformDispatcher.textScaleFactorTestValue = scale;
|
|
await tester.pumpAndSettle();
|
|
final scaledTimeline = tester.getRect(find.byType(EditorTimelinePanel));
|
|
expect(scaledTimeline.right, lessThanOrEqualTo(600));
|
|
expect(scaledTimeline.bottom, lessThanOrEqualTo(450));
|
|
expect(tester.takeException(), isNull);
|
|
}
|
|
});
|
|
}
|
|
|
|
testWidgets('unknown project can return home without a navigation stack', (
|
|
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(_TestProjects.new),
|
|
],
|
|
);
|
|
addTearDown(container.dispose);
|
|
container.read(appRouterProvider).go('/projects/missing');
|
|
await tester.pumpWidget(
|
|
UncontrolledProviderScope(container: container, child: const CutdexApp()),
|
|
);
|
|
await tester.pumpAndSettle();
|
|
await tester.tap(find.text('返回剪辑'));
|
|
await tester.pumpAndSettle();
|
|
expect(find.textContaining('测试项目'), findsWidgets);
|
|
});
|
|
}
|
|
|
|
class _EmptyConversationRepository extends ConversationRepository {
|
|
_EmptyConversationRepository(super.root);
|
|
|
|
@override
|
|
Future<List<ConversationMetadata>> list(
|
|
String projectId, {
|
|
bool trash = false,
|
|
}) async => [];
|
|
|
|
@override
|
|
Future<String?> selected(String projectId) async => null;
|
|
}
|
|
|
|
class _GroupedConversationRepository extends ConversationRepository {
|
|
_GroupedConversationRepository(this.groups) : super(Directory('/unused'));
|
|
|
|
final Map<String, List<ConversationMetadata>> groups;
|
|
|
|
@override
|
|
Future<List<ConversationMetadata>> list(
|
|
String projectId, {
|
|
bool trash = false,
|
|
}) async => trash ? [] : groups[projectId] ?? [];
|
|
|
|
@override
|
|
Future<String?> selected(String projectId) async =>
|
|
groups[projectId]?.firstOrNull?.id;
|
|
|
|
@override
|
|
Future<ConversationMetadata> update(ConversationMetadata item) async {
|
|
final conversations = groups[item.projectId]!;
|
|
final index = conversations.indexWhere((entry) => entry.id == item.id);
|
|
conversations[index] = item;
|
|
return item;
|
|
}
|
|
}
|
|
|
|
class _GroupedProjects extends _TestProjects {
|
|
@override
|
|
Future<ProjectState> build() async {
|
|
final state = await super.build();
|
|
return state.copyWith(
|
|
recent: [
|
|
...state.recent,
|
|
const RecentProject(
|
|
id: 'other',
|
|
name: 'Other Project',
|
|
path: '/test/Other.cutdex',
|
|
),
|
|
],
|
|
);
|
|
}
|
|
|
|
@override
|
|
Future<bool> open(
|
|
String path, {
|
|
String? name,
|
|
String? expectedId,
|
|
String? timelineId,
|
|
String? initialTimelineName,
|
|
bool Function()? isCurrent,
|
|
}) async {
|
|
final current = state.requireValue;
|
|
final project = current.recent.firstWhere((item) => item.id == expectedId);
|
|
state = AsyncData(current.copyWith(activeProject: project));
|
|
return true;
|
|
}
|
|
}
|
|
|
|
class _SwitchProjects extends _TestProjects {
|
|
@override
|
|
Future<ProjectState> build() async => (await super.build()).copyWith(
|
|
timelines: [
|
|
const TimelineSummary(id: 'project', name: '测试项目', revision: 1),
|
|
const TimelineSummary(id: 'second', name: '第二条时间线', revision: 1),
|
|
for (var i = 3; i <= 20; i++)
|
|
TimelineSummary(id: 'timeline-$i', name: '时间线 $i', revision: 1),
|
|
],
|
|
assets: [
|
|
for (var i = 0; i < 30; i++)
|
|
AssetDocument(
|
|
id: 'image-$i',
|
|
name: 'Image $i.png',
|
|
storage: AssetStorage.external,
|
|
location: 'file:///image-$i.png',
|
|
metadata: const {'kind': 'image'},
|
|
),
|
|
],
|
|
);
|
|
|
|
@override
|
|
Future<bool> openTimeline(String projectId, String timelineId) async {
|
|
state = AsyncData(
|
|
state.requireValue.copyWith(
|
|
timeline: TimelineDocument(
|
|
id: timelineId,
|
|
name: timelineId,
|
|
sequences: [],
|
|
),
|
|
),
|
|
);
|
|
return true;
|
|
}
|
|
|
|
@override
|
|
Future<bool> setTimelinePinned(String timelineId, bool pinned) async {
|
|
final current = state.requireValue;
|
|
final updated = [
|
|
for (final item in current.timelines)
|
|
TimelineSummary(
|
|
id: item.id,
|
|
name: item.name,
|
|
revision: item.revision,
|
|
pinned: item.id == timelineId ? pinned : item.pinned,
|
|
),
|
|
];
|
|
state = AsyncData(
|
|
current.copyWith(
|
|
timelines: [
|
|
...updated.where((item) => item.pinned),
|
|
...updated.where((item) => !item.pinned),
|
|
],
|
|
),
|
|
);
|
|
return true;
|
|
}
|
|
|
|
@override
|
|
Future<bool> renameTimeline(
|
|
RecentProject project,
|
|
String timelineId,
|
|
String name,
|
|
) async {
|
|
final current = state.requireValue;
|
|
state = AsyncData(
|
|
current.copyWith(
|
|
timelines: [
|
|
for (final item in current.timelines)
|
|
TimelineSummary(
|
|
id: item.id,
|
|
name: item.id == timelineId ? name : item.name,
|
|
revision: item.revision,
|
|
pinned: item.pinned,
|
|
),
|
|
],
|
|
),
|
|
);
|
|
return true;
|
|
}
|
|
|
|
@override
|
|
Future<bool> deleteTimeline(String timelineId) async {
|
|
final current = state.requireValue;
|
|
final timelines = current.timelines
|
|
.where((item) => item.id != timelineId)
|
|
.toList();
|
|
state = AsyncData(
|
|
current.copyWith(
|
|
timelines: timelines,
|
|
timeline: current.timeline?.id == timelineId
|
|
? TimelineDocument(
|
|
id: timelines.first.id,
|
|
name: timelines.first.name,
|
|
sequences: [],
|
|
)
|
|
: current.timeline,
|
|
),
|
|
);
|
|
return true;
|
|
}
|
|
}
|
|
|
|
class _TimelineLimitProjects extends Projects {
|
|
@override
|
|
Future<ProjectState> build() async {
|
|
const project = RecentProject(
|
|
id: 'project',
|
|
name: '测试项目',
|
|
path: '/test/Project.cutdex',
|
|
);
|
|
return ProjectState(
|
|
activeProject: project,
|
|
recent: const [project],
|
|
timeline: TimelineDocument(id: 'project', name: '测试时间线', sequences: []),
|
|
timelines: [
|
|
const TimelineSummary(id: 'project', name: '测试时间线', revision: 1),
|
|
for (var i = 2; i <= Projects.maxTimelineCount; i++)
|
|
TimelineSummary(id: 'timeline-$i', name: '时间线 $i', revision: 1),
|
|
],
|
|
);
|
|
}
|
|
}
|
|
|
|
class _LoadingProjects extends Projects {
|
|
@override
|
|
Future<ProjectState> build() => Completer<ProjectState>().future;
|
|
}
|
|
|
|
class _BusyProjects extends _TestProjects {
|
|
@override
|
|
Future<ProjectState> build() async =>
|
|
(await super.build()).copyWith(projectBusy: true);
|
|
}
|
|
|
|
class _TestProjects extends Projects {
|
|
@override
|
|
Future<ProjectState> build() async {
|
|
const project = RecentProject(
|
|
id: 'project',
|
|
name: '测试项目',
|
|
path: '/test/Project.cutdex',
|
|
);
|
|
return ProjectState(
|
|
activeProject: project,
|
|
recent: [project],
|
|
timelines: [
|
|
const TimelineSummary(id: 'project', name: '测试时间线', revision: 1),
|
|
],
|
|
timeline: TimelineDocument(id: 'project', name: '测试时间线', sequences: []),
|
|
);
|
|
}
|
|
|
|
@override
|
|
Future<bool> open(
|
|
String path, {
|
|
String? name,
|
|
String? expectedId,
|
|
String? timelineId,
|
|
String? initialTimelineName,
|
|
bool Function()? isCurrent,
|
|
}) async => true;
|
|
|
|
@override
|
|
Future<bool> renameProject(RecentProject project, String name) async {
|
|
final current = state.requireValue;
|
|
final renamed = project.copyWith(name: name);
|
|
state = AsyncData(
|
|
current.copyWith(activeProject: renamed, recent: [renamed]),
|
|
);
|
|
return true;
|
|
}
|
|
|
|
@override
|
|
Future<bool> renameTimeline(
|
|
RecentProject project,
|
|
String timelineId,
|
|
String name,
|
|
) async {
|
|
final current = state.requireValue;
|
|
state = AsyncData(
|
|
current.copyWith(
|
|
timelines: [TimelineSummary(id: timelineId, name: name, revision: 1)],
|
|
timeline: TimelineDocument(id: timelineId, name: name, sequences: []),
|
|
),
|
|
);
|
|
return true;
|
|
}
|
|
|
|
@override
|
|
Future<bool> createTimeline({String? name}) async {
|
|
final current = state.requireValue;
|
|
final index = current.timelines.length;
|
|
final id = 'created-$index';
|
|
final created = TimelineSummary(
|
|
id: id,
|
|
name: name ?? 'Timeline $index',
|
|
revision: 1,
|
|
);
|
|
state = AsyncData(
|
|
current.copyWith(
|
|
timelines: [...current.timelines, created],
|
|
timeline: TimelineDocument(id: id, name: created.name, sequences: []),
|
|
),
|
|
);
|
|
return true;
|
|
}
|
|
}
|
|
|
|
class _MemoryWorkspaceViewSettings implements WorkspaceViewSettingsRepository {
|
|
WorkspaceViewSettingsData value = const WorkspaceViewSettingsData();
|
|
|
|
@override
|
|
Future<WorkspaceViewSettingsData> load() async => value;
|
|
|
|
@override
|
|
Future<void> save(WorkspaceViewSettingsData settings) async =>
|
|
value = settings;
|
|
}
|
|
|
|
class _UnselectedProjects extends _TestProjects {
|
|
@override
|
|
Future<ProjectState> build() async {
|
|
final initial = await super.build();
|
|
return ProjectState(recent: initial.recent);
|
|
}
|
|
|
|
@override
|
|
Future<bool> open(
|
|
String path, {
|
|
String? name,
|
|
String? expectedId,
|
|
String? timelineId,
|
|
String? initialTimelineName,
|
|
bool Function()? isCurrent,
|
|
}) async {
|
|
state = AsyncData(await super.build());
|
|
return true;
|
|
}
|
|
}
|
|
|
|
class _DelayedProjects extends _GroupedProjects {
|
|
final requests = <(String, Completer<bool>)>[];
|
|
|
|
@override
|
|
Future<ProjectState> build() async {
|
|
final initial = await super.build();
|
|
return initial.copyWith(
|
|
recent: [
|
|
...initial.recent,
|
|
const RecentProject(
|
|
id: 'third',
|
|
name: 'Third Project',
|
|
path: '/test/Third.cutdex',
|
|
),
|
|
],
|
|
);
|
|
}
|
|
|
|
@override
|
|
Future<bool> open(
|
|
String path, {
|
|
String? name,
|
|
String? expectedId,
|
|
String? timelineId,
|
|
String? initialTimelineName,
|
|
bool Function()? isCurrent,
|
|
}) async {
|
|
final completion = Completer<bool>();
|
|
requests.add((expectedId!, completion));
|
|
state = AsyncData(state.requireValue.copyWith(projectBusy: true));
|
|
final completed = await completion.future;
|
|
final success = completed && (isCurrent?.call() ?? true);
|
|
final current = state.requireValue;
|
|
state = AsyncData(
|
|
current.copyWith(
|
|
projectBusy: false,
|
|
activeProject: success
|
|
? current.recent.firstWhere((project) => project.id == expectedId)
|
|
: current.activeProject,
|
|
),
|
|
);
|
|
return success;
|
|
}
|
|
}
|