1
1
import 'package:checks/checks.dart' ;
2
2
import 'package:flutter/material.dart' ;
3
+ import 'package:flutter/services.dart' ;
3
4
import 'package:flutter_test/flutter_test.dart' ;
4
5
import 'package:zulip/api/model/model.dart' ;
5
6
import 'package:zulip/api/route/messages.dart' ;
@@ -16,6 +17,7 @@ import '../example_data.dart' as eg;
16
17
import '../flutter_checks.dart' ;
17
18
import '../model/binding.dart' ;
18
19
import '../model/test_store.dart' ;
20
+ import '../test_clipboard.dart' ;
19
21
import 'compose_box_checks.dart' ;
20
22
import 'dialog_checks.dart' ;
21
23
@@ -220,4 +222,48 @@ void main() {
220
222
check (findQuoteAndReplyButton (tester)).isNull ();
221
223
});
222
224
});
225
+
226
+ group ('CopyButton' , () {
227
+ setUp (() async {
228
+ TestZulipBinding .ensureInitialized ();
229
+ TestWidgetsFlutterBinding .ensureInitialized ();
230
+ TestDefaultBinaryMessengerBinding .instance.defaultBinaryMessenger.setMockMethodCallHandler (
231
+ SystemChannels .platform,
232
+ MockClipboard ().handleMethodCall,
233
+ );
234
+ });
235
+
236
+ tearDown (() async {
237
+ TestZulipBinding .instance.reset ();
238
+ });
239
+
240
+ testWidgets ('success' , (WidgetTester tester) async {
241
+ final message = eg.streamMessage ();
242
+ await setupToMessageActionSheet (tester, message: message, narrow: TopicNarrow .ofMessage (message));
243
+ final store = await TestZulipBinding .instance.globalStore.perAccount (eg.selfAccount.id);
244
+
245
+ await tester.ensureVisible (find.byIcon (Icons .copy, skipOffstage: false ));
246
+ prepareRawContentResponseSuccess (store, message: message, rawContent: 'Hello world' );
247
+ await tester.tap (find.byIcon (Icons .copy));
248
+ await tester.pump (Duration .zero);
249
+ check (await Clipboard .getData ('text/plain' )).isNotNull ().text.equals ('Hello world' );
250
+ });
251
+
252
+ testWidgets ('request has an error' , (WidgetTester tester) async {
253
+ final message = eg.streamMessage ();
254
+ await setupToMessageActionSheet (tester, message: message, narrow: TopicNarrow .ofMessage (message));
255
+ final store = await TestZulipBinding .instance.globalStore.perAccount (eg.selfAccount.id);
256
+
257
+ await tester.ensureVisible (find.byIcon (Icons .copy, skipOffstage: false ));
258
+ prepareRawContentResponseError (store);
259
+ await tester.tap (find.byIcon (Icons .copy));
260
+ await tester.pump (Duration .zero); // error arrives; error dialog shows
261
+
262
+ await tester.tap (find.byWidget (checkErrorDialog (tester,
263
+ expectedTitle: 'Copying failed' ,
264
+ expectedMessage: 'That message does not seem to exist.' ,
265
+ )));
266
+ check (await Clipboard .getData ('text/plain' )).isNull ();
267
+ });
268
+ });
223
269
}
0 commit comments