Files
pipelines/app/test/features/chat/chat_next_chat_test.dart
T

100 lines
3.4 KiB
Dart

import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:pipelines_app/core/api_gateway.dart';
import 'package:pipelines_app/features/chat/screen.dart';
import 'package:pipelines_app/shell/adaptive_shell.dart';
import 'package:pipelines_app/shell/destination.dart';
import 'package:shared_preferences/shared_preferences.dart';
import 'conversation/chat_thread_fixtures.dart';
/// Server recency order: the list shows Starred by name (apple, Zed), then
/// Chats by directory (Recent, Second in /w; Other in /v), then Closed folded.
const _rows = <JsonMap>[
{'id': 'r', 'title': 'Recent', 'directory': '/w'},
{'id': 'd', 'title': 'Other', 'directory': '/v'},
{'id': 'c', 'title': 'Done', 'directory': '/w', 'closed_at': 1},
{'id': 's', 'title': 'Second', 'directory': '/w'},
{'id': 'z', 'title': 'Zed', 'directory': '/w', 'starred': true},
{'id': 'a', 'title': 'apple', 'directory': '/v', 'starred': true},
];
class _Gateway extends FakeChatGateway {
_Gateway(this.rows);
final List<JsonMap> rows;
@override
Future<JsonMap> call(String type, [JsonMap fields = const {}]) {
if (type == 'chat_sessions') {
return Future.value({
'chat_sessions': [
for (final row in rows) {...row},
],
});
}
if (type == 'chat_shells') return Future.value({'chat_shells': []});
return super.call(type, fields);
}
}
/// The app's routing: the route names the open chat; selecting one replaces
/// the route, Back returns to the list.
Future<ValueNotifier<String?>> _pump(
WidgetTester tester,
Size size, {
List<JsonMap> rows = _rows,
}) async {
SharedPreferences.setMockInitialValues({});
tester.view.physicalSize = size;
tester.view.devicePixelRatio = 1;
addTearDown(tester.view.reset);
final gateway = _Gateway(rows)..history = (_) async => chatPage(const []);
addTearDown(gateway.close);
final route = ValueNotifier<String?>(null);
addTearDown(route.dispose);
await tester.pumpWidget(
MaterialApp(
home: AdaptiveShell(
destination: AppDestination.chat,
destinationBodies: {
AppDestination.chat: (_) => ValueListenableBuilder<String?>(
valueListenable: route,
builder: (context, id, _) => ChatScreen(
gateway: gateway,
initialSessionId: id,
onSessionSelected: (next) => route.value = next,
onBack: () => route.value = null,
),
),
},
),
),
);
await tester.pumpAndSettle();
return route;
}
Finder _thread(String id) => find.byKey(ValueKey('chat-thread-$id'));
final _next = find.byKey(const Key('chat-next'));
void main() {
for (final size in [const Size(1280, 800), const Size(390, 844)]) {
testWidgets('Next chat is absent from header and More at $size', (
tester,
) async {
await _pump(tester, size);
await tester.tap(find.byKey(const Key('chat-row-a')));
await tester.pumpAndSettle();
expect(_thread('a'), findsOneWidget);
expect(_next, findsNothing);
expect(find.byTooltip('Next chat'), findsNothing);
await tester.tap(find.byTooltip('More actions').hitTestable().first);
await tester.pumpAndSettle();
expect(find.text('Next chat'), findsNothing);
expect(find.text('Add chat pane'), findsOneWidget);
await tester.pumpWidget(const SizedBox.shrink());
});
}
}