|
1 | 1 | import 'package:checks/checks.dart';
|
| 2 | +import 'package:http/http.dart' as http; |
2 | 3 | import 'package:flutter/material.dart';
|
3 | 4 | import 'package:flutter_gen/gen_l10n/zulip_localizations.dart';
|
4 | 5 | import 'package:flutter_test/flutter_test.dart';
|
| 6 | +import 'package:zulip/api/route/messages.dart'; |
| 7 | +import 'package:zulip/model/localizations.dart'; |
5 | 8 | import 'package:zulip/model/narrow.dart';
|
| 9 | +import 'package:zulip/model/store.dart'; |
6 | 10 | import 'package:zulip/widgets/compose_box.dart';
|
7 | 11 | import 'package:zulip/widgets/store.dart';
|
8 | 12 |
|
| 13 | +import '../api/fake_api.dart'; |
9 | 14 | import '../example_data.dart' as eg;
|
10 | 15 | import '../flutter_checks.dart';
|
11 | 16 | import '../model/binding.dart';
|
| 17 | +import '../stdlib_checks.dart'; |
12 | 18 |
|
13 | 19 | void main() {
|
14 | 20 | TestZulipBinding.ensureInitialized();
|
15 | 21 |
|
| 22 | + late PerAccountStore store; |
| 23 | + late FakeApiConnection connection; |
| 24 | + |
16 | 25 | Future<GlobalKey<ComposeBoxController>> prepareComposeBox(WidgetTester tester, Narrow narrow) async {
|
17 | 26 | addTearDown(testBinding.reset);
|
18 | 27 | await testBinding.globalStore.add(eg.selfAccount, eg.initialSnapshot());
|
19 | 28 |
|
| 29 | + store = await testBinding.globalStore.perAccount(eg.selfAccount.id); |
| 30 | + connection = store.connection as FakeApiConnection; |
| 31 | + |
20 | 32 | final controllerKey = GlobalKey<ComposeBoxController>();
|
21 | 33 | await tester.pumpWidget(
|
22 | 34 | MaterialApp(
|
@@ -171,4 +183,40 @@ void main() {
|
171 | 183 | expectTopicTextField: false);
|
172 | 184 | });
|
173 | 185 | });
|
| 186 | + |
| 187 | + group('message-send request response', () { |
| 188 | + Future<void> setupAndTapSend(WidgetTester tester, { |
| 189 | + required void Function(int messageId) prepareResponse, |
| 190 | + }) async { |
| 191 | + final zulipLocalizations = GlobalLocalizations.zulipLocalizations; |
| 192 | + await prepareComposeBox(tester, const TopicNarrow(123, 'some topic')); |
| 193 | + |
| 194 | + final contentInputFinder = find.byWidgetPredicate( |
| 195 | + (widget) => widget is TextField && widget.controller is ComposeContentController); |
| 196 | + await tester.enterText(contentInputFinder, 'hello world'); |
| 197 | + |
| 198 | + prepareResponse(456); |
| 199 | + await tester.tap(find.byTooltip(zulipLocalizations.composeBoxSendTooltip)); |
| 200 | + await tester.pump(Duration.zero); |
| 201 | + |
| 202 | + check(connection.lastRequest).isA<http.Request>() |
| 203 | + ..method.equals('POST') |
| 204 | + ..url.path.equals('/api/v1/messages') |
| 205 | + ..bodyFields.deepEquals({ |
| 206 | + 'type': 'stream', |
| 207 | + 'to': '123', |
| 208 | + 'topic': 'some topic', |
| 209 | + 'content': 'hello world', |
| 210 | + 'read_by_sender': 'true', |
| 211 | + }); |
| 212 | + } |
| 213 | + |
| 214 | + testWidgets('success', (tester) async { |
| 215 | + await setupAndTapSend(tester, prepareResponse: (int messageId) { |
| 216 | + connection.prepare(json: SendMessageResult(id: messageId).toJson()); |
| 217 | + }); |
| 218 | + final errorDialogs = tester.widgetList(find.byType(AlertDialog)); |
| 219 | + check(errorDialogs).isEmpty(); |
| 220 | + }); |
| 221 | + }); |
174 | 222 | }
|
0 commit comments