Answer open-chat sync requests in chat re-tap tests
This commit is contained in:
@@ -222,6 +222,40 @@ Future<void> replyChatSessions(
|
||||
await tester.pump();
|
||||
}
|
||||
|
||||
/// Answers the `chat_open_workspace` requests the app sends around opening a
|
||||
/// chat (main's open-chat sync), so the chat can subscribe. A read gets an
|
||||
/// empty set; a write is stored at the next revision with its own entries.
|
||||
/// Each request is answered once.
|
||||
Future<void> answerOpenWorkspace(
|
||||
WidgetTester tester,
|
||||
FakeChannel channel,
|
||||
) async {
|
||||
final answered = <Object?>{};
|
||||
for (var attempt = 0; attempt < 20; attempt++) {
|
||||
for (final raw in channel.outgoing.toList()) {
|
||||
final message = jsonDecode(raw as String) as Map<String, dynamic>;
|
||||
if (message['type'] != 'chat_open_workspace' ||
|
||||
!answered.add(message['id'])) {
|
||||
continue;
|
||||
}
|
||||
final write = message['chat_open_workspace_request'] as Map?;
|
||||
channel.incoming.add(
|
||||
jsonEncode({
|
||||
'id': message['id'],
|
||||
'type': 'chat_open_workspace',
|
||||
'chat_open_workspace': write == null
|
||||
? {'revision': 0, 'entries': const []}
|
||||
: {
|
||||
'revision': (write['base_revision'] as num) + 1,
|
||||
'entries': write['entries'],
|
||||
},
|
||||
}),
|
||||
);
|
||||
}
|
||||
await tester.pump(const Duration(milliseconds: 5));
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> replyChatHistory(
|
||||
WidgetTester tester,
|
||||
FakeChannel channel, {
|
||||
@@ -677,10 +711,12 @@ void main() {
|
||||
);
|
||||
await tester.pump();
|
||||
await replyChatSessions(tester, channel, ['a']);
|
||||
await answerOpenWorkspace(tester, channel);
|
||||
await tester.pumpAndSettle();
|
||||
final chatTab = find.byKey(const ValueKey('shell.destination.chat'));
|
||||
await tester.tap(find.text('Chat a').first);
|
||||
await tester.pump();
|
||||
await answerOpenWorkspace(tester, channel);
|
||||
await replyChatHistory(
|
||||
tester,
|
||||
channel,
|
||||
@@ -824,51 +860,47 @@ void main() {
|
||||
expect(tester.takeException(), isNull);
|
||||
});
|
||||
|
||||
testWidgets(
|
||||
'phone Chat re-tap from the list opens the active chat',
|
||||
(tester) async {
|
||||
SharedPreferences.setMockInitialValues({});
|
||||
tester.view.physicalSize = const Size(560, 1000);
|
||||
tester.view.devicePixelRatio = 1;
|
||||
addTearDown(tester.view.reset);
|
||||
final channel = FakeChannel()..readyCompleter.complete();
|
||||
final client = PipelinesClient(channelFactory: (_) => channel);
|
||||
final provider = PlatformRouteInformationProvider(
|
||||
initialRouteInformation: RouteInformation(uri: Uri.parse('/chat')),
|
||||
);
|
||||
addTearDown(provider.dispose);
|
||||
addTearDown(client.dispose);
|
||||
await tester.pumpWidget(
|
||||
PipelinesApp(
|
||||
androidSupported: false,
|
||||
server: webServer(),
|
||||
client: client,
|
||||
routeInformationProvider: provider,
|
||||
),
|
||||
);
|
||||
await tester.pump();
|
||||
await replyChatSessions(tester, channel, ['a']);
|
||||
await tester.pumpAndSettle();
|
||||
await tester.tap(find.text('Chat a').first);
|
||||
await tester.pump();
|
||||
await replyChatHistory(
|
||||
tester,
|
||||
channel,
|
||||
subscribeIndex: 0,
|
||||
historyIndex: 0,
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
await tester.tap(find.byTooltip('Back').hitTestable());
|
||||
await tester.pumpAndSettle();
|
||||
expect(provider.value.uri.path, '/chat');
|
||||
expect(find.byType(ChatThreadView), findsNothing);
|
||||
testWidgets('phone Chat re-tap from the list opens the active chat', (
|
||||
tester,
|
||||
) async {
|
||||
SharedPreferences.setMockInitialValues({});
|
||||
tester.view.physicalSize = const Size(560, 1000);
|
||||
tester.view.devicePixelRatio = 1;
|
||||
addTearDown(tester.view.reset);
|
||||
final channel = FakeChannel()..readyCompleter.complete();
|
||||
final client = PipelinesClient(channelFactory: (_) => channel);
|
||||
final provider = PlatformRouteInformationProvider(
|
||||
initialRouteInformation: RouteInformation(uri: Uri.parse('/chat')),
|
||||
);
|
||||
addTearDown(provider.dispose);
|
||||
addTearDown(client.dispose);
|
||||
await tester.pumpWidget(
|
||||
PipelinesApp(
|
||||
androidSupported: false,
|
||||
server: webServer(),
|
||||
client: client,
|
||||
routeInformationProvider: provider,
|
||||
),
|
||||
);
|
||||
await tester.pump();
|
||||
await replyChatSessions(tester, channel, ['a']);
|
||||
await answerOpenWorkspace(tester, channel);
|
||||
await tester.pumpAndSettle();
|
||||
await tester.tap(find.text('Chat a').first);
|
||||
await tester.pump();
|
||||
await answerOpenWorkspace(tester, channel);
|
||||
await replyChatHistory(tester, channel, subscribeIndex: 0, historyIndex: 0);
|
||||
await tester.pumpAndSettle();
|
||||
await tester.tap(find.byTooltip('Back').hitTestable());
|
||||
await tester.pumpAndSettle();
|
||||
expect(provider.value.uri.path, '/chat');
|
||||
expect(find.byType(ChatThreadView), findsNothing);
|
||||
|
||||
final chatTab = find.byKey(const ValueKey('shell.destination.chat'));
|
||||
await tester.tap(chatTab);
|
||||
await tester.pumpAndSettle();
|
||||
expect(provider.value.uri.path, '/chat/a');
|
||||
expect(find.byType(ChatThreadView), findsOneWidget);
|
||||
expect(tester.takeException(), isNull);
|
||||
},
|
||||
);
|
||||
final chatTab = find.byKey(const ValueKey('shell.destination.chat'));
|
||||
await tester.tap(chatTab);
|
||||
await tester.pumpAndSettle();
|
||||
expect(provider.value.uri.path, '/chat/a');
|
||||
expect(find.byType(ChatThreadView), findsOneWidget);
|
||||
expect(tester.takeException(), isNull);
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user