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
@@ -221,4 +223,48 @@ void main() {
221
223
check (findQuoteAndReplyButton (tester)).isNull ();
222
224
});
223
225
});
226
+
227
+ group ('CopyButton' , () {
228
+ setUp (() async {
229
+ TestZulipBinding .ensureInitialized ();
230
+ TestWidgetsFlutterBinding .ensureInitialized ();
231
+ TestDefaultBinaryMessengerBinding .instance.defaultBinaryMessenger.setMockMethodCallHandler (
232
+ SystemChannels .platform,
233
+ MockClipboard ().handleMethodCall,
234
+ );
235
+ });
236
+
237
+ tearDown (() async {
238
+ TestZulipBinding .instance.reset ();
239
+ });
240
+
241
+ testWidgets ('success' , (WidgetTester tester) async {
242
+ final message = eg.streamMessage ();
243
+ await setupToMessageActionSheet (tester, message: message, narrow: TopicNarrow .ofMessage (message));
244
+ final store = await TestZulipBinding .instance.globalStore.perAccount (eg.selfAccount.id);
245
+
246
+ await tester.ensureVisible (find.byIcon (Icons .copy, skipOffstage: false ));
247
+ prepareRawContentResponseSuccess (store, message: message, rawContent: 'Hello world' );
248
+ await tester.tap (find.byIcon (Icons .copy));
249
+ await tester.pump (Duration .zero);
250
+ check (await Clipboard .getData ('text/plain' )).isNotNull ().text.equals ('Hello world' );
251
+ });
252
+
253
+ testWidgets ('request has an error' , (WidgetTester tester) async {
254
+ final message = eg.streamMessage ();
255
+ await setupToMessageActionSheet (tester, message: message, narrow: TopicNarrow .ofMessage (message));
256
+ final store = await TestZulipBinding .instance.globalStore.perAccount (eg.selfAccount.id);
257
+
258
+ await tester.ensureVisible (find.byIcon (Icons .copy, skipOffstage: false ));
259
+ prepareRawContentResponseError (store);
260
+ await tester.tap (find.byIcon (Icons .copy));
261
+ await tester.pump (Duration .zero); // error arrives; error dialog shows
262
+
263
+ await tester.tap (find.byWidget (checkErrorDialog (tester,
264
+ expectedTitle: 'Copying failed' ,
265
+ expectedMessage: 'That message does not seem to exist.' ,
266
+ )));
267
+ check (await Clipboard .getData ('text/plain' )).isNull ();
268
+ });
269
+ });
224
270
}
0 commit comments