Refresh retained explorer when chat directory metadata arrives
This commit is contained in:
@@ -0,0 +1,96 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:shared_preferences/shared_preferences.dart';
|
||||
import 'package:pipelines_app/core/api_gateway.dart';
|
||||
import 'package:pipelines_app/features/chat/conversation/chat_thread_view.dart';
|
||||
import 'package:pipelines_app/features/chat/files/files_controller.dart';
|
||||
import 'package:pipelines_app/features/chat/files/files_preferences.dart';
|
||||
|
||||
import '../conversation/chat_thread_fixtures.dart';
|
||||
|
||||
class _Gateway extends FakeChatGateway {
|
||||
final directories = <String>[];
|
||||
|
||||
@override
|
||||
Future<JsonMap> call(String type, [JsonMap fields = const {}]) {
|
||||
if (type != 'list_directory') return super.call(type, fields);
|
||||
final path = (fields['list_directory'] as Map)['path'] as String;
|
||||
directories.add(path);
|
||||
return Future.value({
|
||||
'directory_listing': {
|
||||
'path': path,
|
||||
'home': '/home',
|
||||
'entries': [
|
||||
{'name': 'loaded.txt', 'path': '$path/loaded.txt'},
|
||||
],
|
||||
},
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
void main() {
|
||||
test('late directory starts an already-open explorer', () async {
|
||||
final gateway = _Gateway();
|
||||
addTearDown(gateway.close);
|
||||
final controller = FilesController(gateway: gateway, initialPath: '');
|
||||
addTearDown(controller.dispose);
|
||||
await controller.start();
|
||||
expect(gateway.directories, isEmpty);
|
||||
await controller.updateInitialPath('/home/project');
|
||||
expect(controller.missingDirectory, isFalse);
|
||||
expect(controller.listing?.path, '/home/project');
|
||||
expect(gateway.directories, ['/home/project']);
|
||||
await controller.updateInitialPath('/home/project');
|
||||
await controller.updateInitialPath('');
|
||||
expect(gateway.directories, hasLength(1));
|
||||
expect(controller.initialPath, '/home/project');
|
||||
});
|
||||
|
||||
test('late metadata remains lazy and preserves folder navigation', () async {
|
||||
final gateway = _Gateway();
|
||||
addTearDown(gateway.close);
|
||||
final controller = FilesController(gateway: gateway, initialPath: '');
|
||||
addTearDown(controller.dispose);
|
||||
await controller.updateInitialPath('/home/project');
|
||||
expect(gateway.directories, isEmpty);
|
||||
await controller.start();
|
||||
await controller.open('/home/project/assets');
|
||||
await controller.updateInitialPath('/home/updated');
|
||||
expect(controller.initialPath, '/home/updated');
|
||||
expect(controller.listing?.path, '/home/project/assets');
|
||||
expect(gateway.directories, hasLength(2));
|
||||
});
|
||||
|
||||
testWidgets('restored thread gains its directory without remounting', (
|
||||
tester,
|
||||
) async {
|
||||
SharedPreferences.setMockInitialValues({});
|
||||
await const FilesPreferences('').setVisible(true);
|
||||
tester.view.physicalSize = const Size(1280, 900);
|
||||
tester.view.devicePixelRatio = 1;
|
||||
addTearDown(tester.view.resetPhysicalSize);
|
||||
addTearDown(tester.view.resetDevicePixelRatio);
|
||||
final gateway = _Gateway()..history = (_) async => chatPage([]);
|
||||
addTearDown(gateway.close);
|
||||
Widget app(JsonMap? session) => MaterialApp(
|
||||
home: Scaffold(
|
||||
body: ChatThreadView(
|
||||
key: const ValueKey('retained-thread'),
|
||||
gateway: gateway,
|
||||
sessionId: 's',
|
||||
session: session,
|
||||
onBack: () {},
|
||||
),
|
||||
),
|
||||
);
|
||||
await tester.pumpWidget(app(null));
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.text('This chat has no working directory.'), findsOneWidget);
|
||||
await tester.pumpWidget(app({'id': 's', 'directory': '/home/project'}));
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.text('This chat has no working directory.'), findsNothing);
|
||||
expect(find.text('loaded.txt'), findsOneWidget);
|
||||
expect(gateway.directories, ['/home/project']);
|
||||
await tester.pumpWidget(const SizedBox());
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user