feat: an archive page, and the sidebar drops archived sessions
- 全部功能 gains an 归档 entry: the new page lists every archived session with a count, search over title / id / project, project chips (all plus each project with its count), and a row that opens the chat; each row restores the session or opens a menu to open, restore, copy the id or delete it - the sidebar's 显示已归档 button and archived list are gone; the sidebar now lists only active sessions, while the archive page owns the archived ones (matching OpenChamber's archive page) - version 0.6.0+600 - tests cover the archive list, project chips, search and restore
This commit is contained in:
1 parent
c6b5a870c6
commit
a7e4ed8dd7
8 files changed
+553
-103
No files matched your search
@@ -0,0 +1,125 @@
|
||||
import 'dart:convert';
|
||||
import 'dart:typed_data';
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:openchamber/api/client.dart';
|
||||
import 'package:openchamber/api/transport.dart';
|
||||
import 'package:openchamber/l10n.dart';
|
||||
import 'package:openchamber/screens/archived_sessions_screen.dart';
|
||||
import 'package:openchamber/state.dart';
|
||||
|
||||
class _FakeTransport implements Transport {
|
||||
final List<Map<String, dynamic>> archived;
|
||||
|
||||
_FakeTransport(this.archived);
|
||||
|
||||
@override
|
||||
Future<TransportResponse> send(TransportRequest r) async {
|
||||
Object? body;
|
||||
if (r.path == '/api/session') {
|
||||
body = {'data': archived};
|
||||
} else if (r.method == 'PATCH') {
|
||||
archived.removeWhere((s) => s['id'] == r.path.split('/').last);
|
||||
body = {'data': <String, dynamic>{}};
|
||||
} else if (r.method == 'DELETE') {
|
||||
archived.removeWhere((s) => s['id'] == r.path.split('/').last);
|
||||
body = <String, dynamic>{};
|
||||
} else {
|
||||
body = <String, dynamic>{};
|
||||
}
|
||||
return TransportResponse(
|
||||
200,
|
||||
const {'content-type': 'application/json'},
|
||||
Stream.value(Uint8List.fromList(utf8.encode(jsonEncode(body)))),
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
Future<TransportSocket> webSocket(String path,
|
||||
{String? rawQuery, Map<String, String> headers = const {}}) async =>
|
||||
throw UnimplementedError();
|
||||
|
||||
@override
|
||||
void setBearerToken(String? token) {}
|
||||
|
||||
@override
|
||||
void close() {}
|
||||
}
|
||||
|
||||
Map<String, dynamic> _session(
|
||||
String id, String title, String directory, int archived) =>
|
||||
{
|
||||
'id': id,
|
||||
'title': title,
|
||||
'time': {'created': archived - 1000, 'updated': archived - 500, 'archived': archived},
|
||||
'location': {'directory': directory},
|
||||
};
|
||||
|
||||
void main() {
|
||||
setUp(() => L10n.instance.apply(AppLanguage.en));
|
||||
tearDown(() => L10n.instance.apply(AppLanguage.zh));
|
||||
|
||||
testWidgets('archived sessions are listed, filtered and restored',
|
||||
(tester) async {
|
||||
final app = AppState();
|
||||
addTearDown(app.dispose);
|
||||
final transport = _FakeTransport([
|
||||
_session('a1', 'Old alpha', '/home/me/alpha', 1000),
|
||||
_session('b1', 'Old beta', '/home/me/beta', 2000),
|
||||
]);
|
||||
app.client = Client(Uri.parse('http://test'), transport: transport);
|
||||
|
||||
await tester.pumpWidget(MaterialApp(home: ArchivedSessionsScreen(app: app)));
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
expect(find.text('Archive'), findsOneWidget);
|
||||
expect(find.text('2 archived sessions'), findsOneWidget);
|
||||
expect(find.text('Old alpha'), findsOneWidget);
|
||||
expect(find.text('Old beta'), findsOneWidget);
|
||||
expect(find.text('All (2)'), findsOneWidget);
|
||||
expect(find.text('alpha (1)'), findsOneWidget);
|
||||
|
||||
// A project chip narrows the list; "All" brings both back.
|
||||
await tester.tap(find.text('alpha (1)'));
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.text('Old alpha'), findsOneWidget);
|
||||
expect(find.text('Old beta'), findsNothing);
|
||||
expect(find.text('1 archived session'), findsOneWidget);
|
||||
await tester.tap(find.text('All (2)'));
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.text('Old beta'), findsOneWidget);
|
||||
|
||||
// Search across projects.
|
||||
await tester.enterText(find.byType(TextField), 'beta');
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.text('Old alpha'), findsNothing);
|
||||
expect(find.text('Old beta'), findsOneWidget);
|
||||
expect(find.text('1 archived session'), findsOneWidget);
|
||||
|
||||
// Restoring removes the row from the archive and from the list.
|
||||
await tester.tap(find.byIcon(Icons.unarchive_outlined));
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.text('Old beta'), findsNothing);
|
||||
expect(find.text('Session restored'), findsOneWidget);
|
||||
expect(app.archivedSessions.map((s) => s.id), ['a1']);
|
||||
});
|
||||
|
||||
testWidgets('a project chip shows only that project', (tester) async {
|
||||
final app = AppState();
|
||||
addTearDown(app.dispose);
|
||||
final transport = _FakeTransport([
|
||||
_session('a1', 'Old alpha', '/home/me/alpha', 1000),
|
||||
_session('b1', 'Old beta', '/home/me/beta', 2000),
|
||||
]);
|
||||
app.client = Client(Uri.parse('http://test'), transport: transport);
|
||||
|
||||
await tester.pumpWidget(MaterialApp(home: ArchivedSessionsScreen(app: app)));
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
await tester.tap(find.text('beta (1)'));
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.text('Old beta'), findsOneWidget);
|
||||
expect(find.text('Old alpha'), findsNothing);
|
||||
});
|
||||
}
|
||||
Reference in new issue
Block a user