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