feat(workspace): 桌面工作区、主题与交互更新,发布 0.1.2
Gitea CI / Check code and tests (push) Successful in 6m37s
Gitea CI / Build Windows x64 app (push) Successful in 3m18s
Gitea CI / Build Android APK (push) Successful in 3m47s
Gitea CI / Audit and package Windows x64 (push) Successful in 1m7s
Gitea CI / Assemble and validate CI artifacts (push) Successful in 50s
Gitea CI / Gitea CI passed (push) Successful in 2s
Gitea Release / Prepare draft Release (push) Successful in 9s
Gitea Release / Upload Android to draft Release (push) Successful in 16s
Gitea Release / Upload Windows to draft Release (push) Successful in 22s
Gitea Release / Verify and publish Release (push) Successful in 14s
Gitea CI / Check code and tests (push) Successful in 6m37s
Gitea CI / Build Windows x64 app (push) Successful in 3m18s
Gitea CI / Build Android APK (push) Successful in 3m47s
Gitea CI / Audit and package Windows x64 (push) Successful in 1m7s
Gitea CI / Assemble and validate CI artifacts (push) Successful in 50s
Gitea CI / Gitea CI passed (push) Successful in 2s
Gitea Release / Prepare draft Release (push) Successful in 9s
Gitea Release / Upload Android to draft Release (push) Successful in 16s
Gitea Release / Upload Windows to draft Release (push) Successful in 22s
Gitea Release / Verify and publish Release (push) Successful in 14s
This commit was merged in pull request #13.
This commit is contained in:
1 parent
aa5255d1e4
commit
abc1868550
260 files changed
+43964
-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);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user