feat(workspace): refresh desktop editing experience and prepare 0.1.2
Gitea CI / Build Android APK (pull_request) Canceled after 0s
Gitea CI / Build Windows x64 app (pull_request) Canceled after 0s
Gitea CI / Audit and package Windows x64 (pull_request) Canceled after 0s
Gitea CI / Assemble and validate CI artifacts (pull_request) Canceled after 0s
Gitea CI / Gitea CI passed (pull_request) Canceled after 0s
Gitea CI / Check code and tests (pull_request) Canceled after 6m29s
Gitea CI / Build Android APK (pull_request) Canceled after 0s
Gitea CI / Build Windows x64 app (pull_request) Canceled after 0s
Gitea CI / Audit and package Windows x64 (pull_request) Canceled after 0s
Gitea CI / Assemble and validate CI artifacts (pull_request) Canceled after 0s
Gitea CI / Gitea CI passed (pull_request) Canceled after 0s
Gitea CI / Check code and tests (pull_request) Canceled after 6m29s
This commit is contained in:
1 parent
aa5255d1e4
commit
2e0033ce2d
260 files changed
+43963
-5591
No files matched your search
@@ -0,0 +1,256 @@
|
||||
import 'package:cutdex/app/editor_theme.dart';
|
||||
import 'package:cutdex/features/projects/conversation_sidebar.dart';
|
||||
import 'package:cutdex/features/projects/project_sidebar.dart';
|
||||
import 'package:cutdex/integrations/agent/conversation_repository.dart';
|
||||
import 'package:cutdex/l10n/app_localizations.dart';
|
||||
import 'package:cutdex/workspace/project_state.dart';
|
||||
import 'package:cutdex/workspace/projects.dart';
|
||||
import 'package:cutdex/workspace/workspace_mode.dart';
|
||||
import 'package:cutdex_ui/icons.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
|
||||
import '../../support/empty_conversation_repository.dart';
|
||||
|
||||
void main() {
|
||||
testWidgets(
|
||||
'desktop header follows selection, rename, trash and project scope',
|
||||
(tester) async {
|
||||
const projects = [
|
||||
RecentProject(id: 'a', name: 'Project A', path: '/a'),
|
||||
RecentProject(id: 'b', name: 'Project B', path: '/b'),
|
||||
];
|
||||
final repository = _Conversations([
|
||||
_item('first', 'a', 'First chat'),
|
||||
_item('second', 'a', 'Second chat'),
|
||||
_item('other', 'b', 'Other project chat'),
|
||||
]);
|
||||
final workspace = _Projects(
|
||||
ProjectState(activeProject: projects.first, recent: projects),
|
||||
);
|
||||
final container = ProviderContainer(
|
||||
overrides: [
|
||||
projectsProvider.overrideWith(() => workspace),
|
||||
conversationRepositoryProvider.overrideWith((_) => repository),
|
||||
],
|
||||
);
|
||||
addTearDown(container.dispose);
|
||||
await container.read(projectsProvider.future);
|
||||
await container.read(conversationSidebarProvider.future);
|
||||
await tester.pumpWidget(
|
||||
UncontrolledProviderScope(
|
||||
container: container,
|
||||
child: MaterialApp(
|
||||
theme: EditorTheme.desktop(EditorTheme.penDark),
|
||||
locale: const Locale('zh'),
|
||||
localizationsDelegates: AppLocalizations.localizationsDelegates,
|
||||
supportedLocales: AppLocalizations.supportedLocales,
|
||||
home: Scaffold(
|
||||
body: SizedBox(
|
||||
width: 240,
|
||||
child: Consumer(
|
||||
builder: (context, ref, _) {
|
||||
final state = ref.watch(projectsProvider).requireValue;
|
||||
return ProjectSidebar(
|
||||
chatOnly: true,
|
||||
agent: const Text('Conversation content'),
|
||||
mode: WorkspaceMode.agent,
|
||||
onModeChanged: (_) {},
|
||||
navigationWidth: 240,
|
||||
navigationCollapsed: false,
|
||||
agentHeaderLeading: const SizedBox(),
|
||||
editorHidden: false,
|
||||
onExpandEditor: null,
|
||||
state: state,
|
||||
selectedProjectId: state.activeProject?.id,
|
||||
integratedTitlebar: false,
|
||||
onCreateProject: null,
|
||||
onSelectProject: null,
|
||||
onRenameProject: (_) async => false,
|
||||
headerControls: const SizedBox(),
|
||||
);
|
||||
},
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.text('First chat'), findsOneWidget);
|
||||
await tester.tap(find.byKey(const Key('project-chat-history')));
|
||||
await tester.pumpAndSettle();
|
||||
final menu = find.byKey(const Key('project-chat-history-menu'));
|
||||
Finder menuText(String text) =>
|
||||
find.descendant(of: menu, matching: find.text(text));
|
||||
final group = tester.getRect(find.byKey(const Key('project-chat-group')));
|
||||
expect(tester.getRect(menuText('First chat')).left, group.left);
|
||||
expect(tester.getRect(menuText('Second chat')).left, group.left);
|
||||
final searchIcon = find.descendant(
|
||||
of: find.byKey(const Key('project-chat-search')),
|
||||
matching: find.byIcon(AppIcons.search),
|
||||
);
|
||||
expect(tester.getCenter(searchIcon).dx, group.left + 7);
|
||||
final search = find.byKey(const Key('project-chat-search'));
|
||||
expect(tester.getSize(search).height, 28);
|
||||
expect(tester.widget<TextField>(search).style?.fontSize, 13);
|
||||
expect(tester.widget<TextField>(search).cursorHeight, 13);
|
||||
expect(
|
||||
find.byKey(const ValueKey('sidebar-conversation-other')),
|
||||
findsNothing,
|
||||
);
|
||||
await tester.enterText(
|
||||
find.byKey(const Key('project-chat-search')),
|
||||
'Second',
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
await tester.tap(
|
||||
find.byKey(const ValueKey('sidebar-conversation-second')),
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.byKey(const Key('project-chat-history-menu')), findsNothing);
|
||||
expect(find.text('Second chat'), findsOneWidget);
|
||||
expect(repository.selection['a'], 'second');
|
||||
|
||||
await tester.tap(find.byKey(const Key('project-chat-more')));
|
||||
await tester.pumpAndSettle();
|
||||
await tester.tap(
|
||||
find.text(lookupAppLocalizations(const Locale('zh')).rename),
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
await tester.enterText(find.byType(TextFormField), 'Renamed second');
|
||||
await tester.tap(
|
||||
find.text(lookupAppLocalizations(const Locale('zh')).save),
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.text('Renamed second'), findsOneWidget);
|
||||
expect(
|
||||
repository.items.firstWhere((item) => item.id == 'second').title,
|
||||
'Renamed second',
|
||||
);
|
||||
|
||||
await tester.tap(find.byKey(const Key('project-chat-more')));
|
||||
await tester.pumpAndSettle();
|
||||
await tester.tap(
|
||||
find.text(lookupAppLocalizations(const Locale('zh')).agentMoveToTrash),
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.text('新聊天'), findsOneWidget);
|
||||
expect(
|
||||
container.read(conversationSelectionProvider('a')).selectedId,
|
||||
isNull,
|
||||
);
|
||||
await tester.tap(find.byKey(const Key('project-chat-history')));
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.text('Renamed second'), findsOneWidget);
|
||||
final trashTitle = tester.getRect(
|
||||
find.byKey(const Key('project-chat-trash-title')),
|
||||
);
|
||||
expect(
|
||||
trashTitle.left,
|
||||
tester.getRect(find.byKey(const Key('project-chat-group'))).left,
|
||||
);
|
||||
expect(tester.getRect(menuText('Renamed second')).left, trashTitle.left);
|
||||
expect(
|
||||
find.byKey(const ValueKey('sidebar-conversation-second')),
|
||||
findsNothing,
|
||||
);
|
||||
await tester.tap(
|
||||
find.byTooltip(lookupAppLocalizations(const Locale('zh')).agentRestore),
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
expect(
|
||||
find.byKey(const ValueKey('sidebar-conversation-second')),
|
||||
findsOneWidget,
|
||||
);
|
||||
|
||||
workspace.switchTo(projects.last);
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.byKey(const Key('project-chat-history-menu')), findsNothing);
|
||||
expect(find.text('Other project chat'), findsOneWidget);
|
||||
await tester.tap(find.byKey(const Key('project-chat-history')));
|
||||
await tester.pumpAndSettle();
|
||||
expect(
|
||||
find.byKey(const ValueKey('sidebar-conversation-other')),
|
||||
findsOneWidget,
|
||||
);
|
||||
expect(
|
||||
find.byKey(const ValueKey('sidebar-conversation-first')),
|
||||
findsNothing,
|
||||
);
|
||||
expect(
|
||||
find.byKey(const ValueKey('sidebar-conversation-second')),
|
||||
findsNothing,
|
||||
);
|
||||
expect(tester.takeException(), isNull);
|
||||
await tester.pumpWidget(const SizedBox());
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
ConversationMetadata _item(String id, String projectId, String title) =>
|
||||
ConversationMetadata(
|
||||
id: id,
|
||||
projectId: projectId,
|
||||
title: title,
|
||||
createdAt: DateTime.utc(2026),
|
||||
updatedAt: DateTime.utc(2026),
|
||||
providerId: 'provider',
|
||||
modelId: 'model',
|
||||
timelineId: 'timeline',
|
||||
pending: false,
|
||||
responseDurationsMs: const [],
|
||||
);
|
||||
|
||||
class _Projects extends Projects {
|
||||
_Projects(this.initial);
|
||||
final ProjectState initial;
|
||||
@override
|
||||
Future<ProjectState> build() async => initial;
|
||||
void switchTo(RecentProject project) =>
|
||||
state = AsyncData(state.requireValue.copyWith(activeProject: project));
|
||||
}
|
||||
|
||||
class _Conversations extends EmptyConversationRepository {
|
||||
_Conversations(this.items);
|
||||
final List<ConversationMetadata> items;
|
||||
final trashed = <ConversationMetadata>[];
|
||||
final selection = <String, String?>{'a': 'first', 'b': 'other'};
|
||||
@override
|
||||
Future<List<ConversationMetadata>> list(
|
||||
String projectId, {
|
||||
bool trash = false,
|
||||
}) async => (trash ? trashed : items)
|
||||
.where((item) => item.projectId == projectId)
|
||||
.toList();
|
||||
@override
|
||||
Future<String?> selected(String projectId) async => selection[projectId];
|
||||
@override
|
||||
Future<void> select(String projectId, String? conversationId) async =>
|
||||
selection[projectId] = conversationId;
|
||||
@override
|
||||
Future<ConversationMetadata> update(ConversationMetadata item) async {
|
||||
items[items.indexWhere((entry) => entry.id == item.id)] = item;
|
||||
return item;
|
||||
}
|
||||
|
||||
@override
|
||||
Future<void> trash(String projectId, String id) async {
|
||||
final item = items.firstWhere(
|
||||
(entry) => entry.projectId == projectId && entry.id == id,
|
||||
);
|
||||
items.remove(item);
|
||||
trashed.add(item);
|
||||
if (selection[projectId] == id) selection[projectId] = null;
|
||||
}
|
||||
|
||||
@override
|
||||
Future<void> restore(String projectId, String id) async {
|
||||
final item = trashed.firstWhere(
|
||||
(entry) => entry.projectId == projectId && entry.id == id,
|
||||
);
|
||||
trashed.remove(item);
|
||||
items.add(item);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,334 @@
|
||||
import 'dart:async';
|
||||
|
||||
import 'package:cutdex/app/editor_theme.dart';
|
||||
import 'package:cutdex/features/projects/conversation_sidebar.dart';
|
||||
import 'package:cutdex/features/projects/project_sidebar.dart';
|
||||
import 'package:cutdex/integrations/agent/conversation_repository.dart';
|
||||
import 'package:cutdex/l10n/app_localizations.dart';
|
||||
import 'package:cutdex/workspace/project_state.dart';
|
||||
import 'package:cutdex/workspace/projects.dart';
|
||||
import 'package:cutdex/workspace/workspace_mode.dart';
|
||||
import 'package:cutdex_sdk/project.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
|
||||
void main() {
|
||||
testWidgets(
|
||||
'missing conversation timeline still allows the project default',
|
||||
(tester) async {
|
||||
final sidebar = _Sidebar();
|
||||
await sidebar.mount(tester);
|
||||
final operation = sidebar.select(tester);
|
||||
sidebar.conversations.remembered.complete();
|
||||
await tester.pump();
|
||||
sidebar.projects.opened.complete(false);
|
||||
await tester.pump();
|
||||
expect(sidebar.projects._openCalls, 2);
|
||||
sidebar.projects._publish(_recent[1], timelineId: 'default');
|
||||
expect(sidebar.projects._openGuards.last!(), isTrue);
|
||||
sidebar.projects._fallbackOpened.complete(true);
|
||||
await expectLater(operation, completes);
|
||||
expect(sidebar.conversations.activated, ['chat']);
|
||||
await tester.pumpWidget(const SizedBox());
|
||||
},
|
||||
);
|
||||
|
||||
testWidgets('project change invalidates a still mounted sidebar request', (
|
||||
tester,
|
||||
) async {
|
||||
final sidebar = _Sidebar();
|
||||
await sidebar.mount(tester);
|
||||
final operation = sidebar.select(tester);
|
||||
sidebar.projects._publish(_recent[2]);
|
||||
await tester.pump();
|
||||
sidebar.conversations.remembered.complete();
|
||||
await expectLater(operation, completes);
|
||||
expect(sidebar.projects._openCalls, 0);
|
||||
expect(sidebar.conversations.activated, isEmpty);
|
||||
expect(sidebar.modes, isEmpty);
|
||||
await tester.pumpWidget(const SizedBox());
|
||||
});
|
||||
|
||||
testWidgets(
|
||||
'returning to the source project does not revive old navigation',
|
||||
(tester) async {
|
||||
final sidebar = _Sidebar();
|
||||
await sidebar.mount(tester);
|
||||
final operation = sidebar.select(tester);
|
||||
sidebar.projects._publish(_recent[2]);
|
||||
sidebar.projects._publish(_recent[0]);
|
||||
await tester.pump();
|
||||
sidebar.conversations.remembered.complete();
|
||||
await expectLater(operation, completes);
|
||||
expect(sidebar.projects._openCalls, 0);
|
||||
expect(sidebar.conversations.activated, isEmpty);
|
||||
await tester.pumpWidget(const SizedBox());
|
||||
},
|
||||
);
|
||||
|
||||
testWidgets('timeline change invalidates a pending conversation selection', (
|
||||
tester,
|
||||
) async {
|
||||
final sidebar = _Sidebar(activeProject: _recent[1]);
|
||||
await sidebar.mount(tester);
|
||||
final operation = sidebar.select(tester);
|
||||
sidebar.projects._publish(_recent[1], timelineId: 'other');
|
||||
await tester.pump();
|
||||
sidebar.conversations.remembered.complete();
|
||||
await expectLater(operation, completes);
|
||||
expect(sidebar.conversations.activated, isEmpty);
|
||||
expect(sidebar.modes, isEmpty);
|
||||
await tester.pumpWidget(const SizedBox());
|
||||
});
|
||||
|
||||
testWidgets(
|
||||
'latest conversation wins when selection saves finish in reverse',
|
||||
(tester) async {
|
||||
final sidebar = _Sidebar(activeProject: _recent[1]);
|
||||
await sidebar.mount(tester);
|
||||
final first = sidebar.select(tester);
|
||||
final second = sidebar.select(tester, id: 'next');
|
||||
sidebar.conversations.nextRemembered.complete();
|
||||
await expectLater(second, completes);
|
||||
sidebar.conversations.remembered.complete();
|
||||
await expectLater(first, completes);
|
||||
expect(sidebar.conversations.activated, ['next']);
|
||||
expect(sidebar.navigationCompletions, 1);
|
||||
await tester.pumpWidget(const SizedBox());
|
||||
},
|
||||
);
|
||||
|
||||
testWidgets('navigation allows the project transition it requested', (
|
||||
tester,
|
||||
) async {
|
||||
final sidebar = _Sidebar();
|
||||
await sidebar.mount(tester);
|
||||
final operation = sidebar.select(tester);
|
||||
sidebar.conversations.remembered.complete();
|
||||
await tester.pump();
|
||||
expect(sidebar.projects._openCalls, 1);
|
||||
expect(sidebar.projects._openGuards.single!(), isTrue);
|
||||
sidebar.projects._publish(_recent[1], timelineId: 'timeline');
|
||||
sidebar.projects.opened.complete(true);
|
||||
await expectLater(operation, completes);
|
||||
expect(sidebar.conversations.activated, ['chat']);
|
||||
expect(sidebar.modes, [WorkspaceMode.agent]);
|
||||
await tester.pumpWidget(const SizedBox());
|
||||
});
|
||||
|
||||
testWidgets('removed sidebar stops navigation after remembering selection', (
|
||||
tester,
|
||||
) async {
|
||||
final sidebar = _Sidebar();
|
||||
await sidebar.mount(tester);
|
||||
final operation = sidebar.select(tester);
|
||||
await tester.pump();
|
||||
await tester.pumpWidget(sidebar.host(const SizedBox()));
|
||||
sidebar.conversations.remembered.complete();
|
||||
await expectLater(operation, completes);
|
||||
expect(sidebar.projects._openCalls, 0);
|
||||
expect(sidebar.conversations.activated, isEmpty);
|
||||
expect(sidebar.modes, isEmpty);
|
||||
expect(tester.takeException(), isNull);
|
||||
await tester.pumpWidget(const SizedBox());
|
||||
});
|
||||
|
||||
testWidgets('removed sidebar does not retry a failed project open', (
|
||||
tester,
|
||||
) async {
|
||||
final sidebar = _Sidebar();
|
||||
await sidebar.mount(tester);
|
||||
final operation = sidebar.select(tester);
|
||||
sidebar.conversations.remembered.complete();
|
||||
await tester.pump();
|
||||
expect(sidebar.projects._openCalls, 1);
|
||||
await tester.pumpWidget(sidebar.host(const SizedBox()));
|
||||
expect(sidebar.projects._openGuards.single!(), isFalse);
|
||||
sidebar.projects.opened.complete(false);
|
||||
await expectLater(operation, completes);
|
||||
expect(sidebar.projects._openCalls, 1);
|
||||
expect(sidebar.conversations.activated, isEmpty);
|
||||
expect(sidebar.modes, isEmpty);
|
||||
expect(tester.takeException(), isNull);
|
||||
await tester.pumpWidget(const SizedBox());
|
||||
});
|
||||
|
||||
testWidgets('mounted sidebar still activates the selected conversation', (
|
||||
tester,
|
||||
) async {
|
||||
final sidebar = _Sidebar(activeProject: _recent[1]);
|
||||
await sidebar.mount(tester);
|
||||
final operation = sidebar.select(tester);
|
||||
sidebar.conversations.remembered.complete();
|
||||
await expectLater(operation, completes);
|
||||
await tester.pump();
|
||||
expect(sidebar.projects._openCalls, 0);
|
||||
expect(sidebar.conversations.activated, ['chat']);
|
||||
expect(sidebar.modes, [WorkspaceMode.agent]);
|
||||
expect(sidebar.navigationCompletions, 1);
|
||||
expect(tester.takeException(), isNull);
|
||||
await tester.pumpWidget(const SizedBox());
|
||||
});
|
||||
}
|
||||
|
||||
const _recent = [
|
||||
RecentProject(id: 'a', name: 'A', path: '/a'),
|
||||
RecentProject(id: 'b', name: 'B', path: '/b'),
|
||||
RecentProject(id: 'c', name: 'C', path: '/c'),
|
||||
];
|
||||
|
||||
class _Sidebar {
|
||||
_Sidebar({
|
||||
RecentProject activeProject = const RecentProject(
|
||||
id: 'a',
|
||||
name: 'A',
|
||||
path: '/a',
|
||||
),
|
||||
}) {
|
||||
initial = ProjectState(activeProject: activeProject, recent: _recent);
|
||||
projects = _Projects(initial);
|
||||
conversations = _Conversations(item);
|
||||
container = ProviderContainer(
|
||||
overrides: [
|
||||
projectsProvider.overrideWith(() => projects),
|
||||
conversationSidebarProvider.overrideWith(() => conversations),
|
||||
conversationSelectionProvider.overrideWith2((_) => _Selected()),
|
||||
],
|
||||
);
|
||||
addTearDown(container.dispose);
|
||||
}
|
||||
|
||||
late final ProjectState initial;
|
||||
late final _Projects projects;
|
||||
late final _Conversations conversations;
|
||||
late final ProviderContainer container;
|
||||
final modes = <WorkspaceMode>[];
|
||||
int navigationCompletions = 0;
|
||||
final item = ConversationMetadata(
|
||||
id: 'chat',
|
||||
projectId: 'b',
|
||||
title: 'Chat',
|
||||
createdAt: DateTime.utc(2026),
|
||||
updatedAt: DateTime.utc(2026),
|
||||
providerId: 'provider',
|
||||
modelId: 'model',
|
||||
timelineId: 'timeline',
|
||||
pending: false,
|
||||
responseDurationsMs: const [],
|
||||
);
|
||||
|
||||
Future<void> select(WidgetTester tester, {String id = 'chat'}) {
|
||||
final row = tester.widget<InkWell>(
|
||||
find.byKey(ValueKey('sidebar-conversation-$id')),
|
||||
);
|
||||
// InkWell declares a void callback, but navigation returns a future.
|
||||
// Await that operation so async lifecycle exceptions fail this test.
|
||||
return Function.apply(row.onTap!, []) as Future<void>;
|
||||
}
|
||||
|
||||
Widget host(Widget child) => UncontrolledProviderScope(
|
||||
container: container,
|
||||
child: MaterialApp(
|
||||
theme: EditorTheme.desktop(EditorTheme.penLight),
|
||||
localizationsDelegates: AppLocalizations.localizationsDelegates,
|
||||
supportedLocales: AppLocalizations.supportedLocales,
|
||||
locale: const Locale('zh'),
|
||||
home: Scaffold(body: SizedBox(width: 350, child: child)),
|
||||
),
|
||||
);
|
||||
|
||||
Future<void> mount(WidgetTester tester) async {
|
||||
await container.read(projectsProvider.future);
|
||||
await container.read(conversationSidebarProvider.future);
|
||||
await tester.pumpWidget(
|
||||
host(
|
||||
ProjectSidebar(
|
||||
agent: const SizedBox(),
|
||||
navigationOnly: true,
|
||||
mode: WorkspaceMode.agent,
|
||||
onModeChanged: modes.add,
|
||||
onNavigationComplete: () => navigationCompletions++,
|
||||
navigationWidth: 350,
|
||||
navigationCollapsed: false,
|
||||
agentHeaderLeading: const SizedBox(),
|
||||
editorHidden: false,
|
||||
onExpandEditor: null,
|
||||
state: initial,
|
||||
selectedProjectId: initial.activeProject!.id,
|
||||
integratedTitlebar: false,
|
||||
onCreateProject: null,
|
||||
onSelectProject: null,
|
||||
onRenameProject: (_) async => false,
|
||||
headerControls: const SizedBox(),
|
||||
),
|
||||
),
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
}
|
||||
}
|
||||
|
||||
class _Projects extends Projects {
|
||||
_Projects(this.initial);
|
||||
final ProjectState initial;
|
||||
final opened = Completer<bool>();
|
||||
final _fallbackOpened = Completer<bool>();
|
||||
int _openCalls = 0;
|
||||
final _openGuards = <bool Function()?>[];
|
||||
|
||||
void _publish(RecentProject project, {String? timelineId}) {
|
||||
state = AsyncData(
|
||||
state.requireValue.copyWith(
|
||||
activeProject: project,
|
||||
timeline: timelineId == null
|
||||
? null
|
||||
: TimelineDocument(id: timelineId, name: timelineId, sequences: []),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
Future<ProjectState> build() async => initial;
|
||||
|
||||
@override
|
||||
Future<bool> open(
|
||||
String path, {
|
||||
String? name,
|
||||
String? expectedId,
|
||||
String? timelineId,
|
||||
String? initialTimelineName,
|
||||
bool Function()? isCurrent,
|
||||
}) {
|
||||
_openCalls++;
|
||||
_openGuards.add(isCurrent);
|
||||
return _openCalls == 1 ? opened.future : _fallbackOpened.future;
|
||||
}
|
||||
}
|
||||
|
||||
class _Selected extends ConversationSelection {
|
||||
@override
|
||||
ConversationSelectionState build(String? projectId) =>
|
||||
const ConversationSelectionState(draftKey: 'draft', initialized: true);
|
||||
}
|
||||
|
||||
class _Conversations extends ConversationSidebar {
|
||||
_Conversations(this.item);
|
||||
final ConversationMetadata item;
|
||||
final remembered = Completer<void>();
|
||||
final nextRemembered = Completer<void>();
|
||||
final activated = <String>[];
|
||||
|
||||
@override
|
||||
Future<ConversationSnapshot> build() async => ConversationSnapshot(
|
||||
groups: {
|
||||
'b': [item, item.copyWith(id: 'next')],
|
||||
},
|
||||
);
|
||||
|
||||
@override
|
||||
Future<void> rememberSelection(ConversationMetadata item) =>
|
||||
item.id == 'next' ? nextRemembered.future : remembered.future;
|
||||
|
||||
@override
|
||||
void activate(ConversationMetadata item) => activated.add(item.id);
|
||||
}
|
||||
@@ -0,0 +1,117 @@
|
||||
import 'package:cutdex/features/projects/project_tabs_controller.dart';
|
||||
import 'package:cutdex/workspace/project_state.dart';
|
||||
import 'package:cutdex/workspace/projects.dart';
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
|
||||
void main() {
|
||||
TestWidgetsFlutterBinding.ensureInitialized();
|
||||
const first = RecentProject(id: 'a', name: 'First', path: '/first');
|
||||
const second = RecentProject(id: 'b', name: 'Second', path: '/second');
|
||||
const third = RecentProject(id: 'c', name: 'Recent only', path: '/third');
|
||||
late _Projects projects;
|
||||
late ProviderContainer container;
|
||||
late ProjectTabsController tabs;
|
||||
|
||||
setUp(() async {
|
||||
projects = _Projects(
|
||||
const ProjectState(activeProject: first, recent: [first, second, third]),
|
||||
);
|
||||
container = ProviderContainer(
|
||||
overrides: [projectsProvider.overrideWith(() => projects)],
|
||||
);
|
||||
await container.read(projectsProvider.future);
|
||||
tabs = container.read(projectTabsProvider.notifier);
|
||||
});
|
||||
tearDown(() => container.dispose());
|
||||
List<RecentProject> opened() => container.read(projectTabsProvider);
|
||||
|
||||
test(
|
||||
'tabs follow successful opens, keep order and exclude recent-only files',
|
||||
() {
|
||||
expect(opened(), [first]);
|
||||
projects.publish(projects._current.copyWith(activeProject: second));
|
||||
expect(opened(), [first, second]);
|
||||
projects.publish(projects._current.copyWith(activeProject: first));
|
||||
expect(opened(), [first, second]);
|
||||
projects.publish(projects._current.copyWith(projectBusy: true));
|
||||
expect(opened(), [first, second]);
|
||||
},
|
||||
);
|
||||
|
||||
test(
|
||||
'history removal and truncation do not discard opened project metadata',
|
||||
() {
|
||||
projects.publish(projects._current.copyWith(activeProject: second));
|
||||
projects.publish(projects._current.copyWith(recent: const [third]));
|
||||
expect(opened(), [first, second]);
|
||||
projects.publish(projects._current.copyWith(activeProject: null));
|
||||
expect(opened(), [first, second]);
|
||||
tabs.remove(second.id);
|
||||
expect(opened(), [first]);
|
||||
projects.publish(projects._current.copyWith(activeProject: second));
|
||||
expect(opened(), [first, second]);
|
||||
},
|
||||
);
|
||||
|
||||
test('metadata changes update tabs without changing their order', () {
|
||||
projects.publish(projects._current.copyWith(activeProject: second));
|
||||
final renamed = first.copyWith(name: 'Renamed');
|
||||
final relocated = second.copyWith(path: '/new-second');
|
||||
projects.publish(
|
||||
projects._current.copyWith(
|
||||
recent: [renamed, relocated, third],
|
||||
activeProject: relocated,
|
||||
),
|
||||
);
|
||||
expect(opened(), [renamed, relocated]);
|
||||
projects.publish(projects._current.copyWith(recent: const []));
|
||||
final renamedAgain = renamed.copyWith(name: 'Renamed outside history');
|
||||
tabs.updateProject(renamedAgain);
|
||||
expect(opened(), [renamedAgain, relocated]);
|
||||
});
|
||||
|
||||
test('history updates do not reopen a closed inactive tab', () {
|
||||
projects.publish(projects._current.copyWith(activeProject: second));
|
||||
tabs.remove(first.id);
|
||||
projects.publish(
|
||||
projects._current.copyWith(
|
||||
recent: [
|
||||
first.copyWith(name: 'Updated'),
|
||||
second,
|
||||
],
|
||||
),
|
||||
);
|
||||
expect(opened(), [second]);
|
||||
expect(() => opened().clear(), throwsUnsupportedError);
|
||||
});
|
||||
|
||||
test('all opened projects remain available beyond the twenty-entry history limit', () {
|
||||
for (var index = 0; index < 25; index++) {
|
||||
final project = RecentProject(
|
||||
id: 'extra-$index',
|
||||
name: 'Project $index',
|
||||
path: '/extra-$index',
|
||||
);
|
||||
projects.publish(
|
||||
projects._current.copyWith(
|
||||
activeProject: project,
|
||||
recent: [project, ...projects._current.recent].take(20).toList(),
|
||||
),
|
||||
);
|
||||
}
|
||||
expect(projects._current.recent, hasLength(20));
|
||||
expect(opened(), hasLength(26));
|
||||
expect(opened().first, first);
|
||||
expect(opened().last.id, 'extra-24');
|
||||
});
|
||||
}
|
||||
|
||||
class _Projects extends Projects {
|
||||
_Projects(this.initial);
|
||||
final ProjectState initial;
|
||||
@override
|
||||
Future<ProjectState> build() async => initial;
|
||||
ProjectState get _current => state.requireValue;
|
||||
void publish(ProjectState value) => state = AsyncData(value);
|
||||
}
|
||||
Reference in new issue
Block a user