@@ -10,6 +10,7 @@ import 'package:zulip/api/model/model.dart';
10
10
import 'package:zulip/api/route/messages.dart' ;
11
11
import 'package:zulip/model/binding.dart' ;
12
12
import 'package:zulip/model/compose.dart' ;
13
+ import 'package:zulip/model/internal_link.dart' ;
13
14
import 'package:zulip/model/localizations.dart' ;
14
15
import 'package:zulip/model/narrow.dart' ;
15
16
import 'package:zulip/model/store.dart' ;
@@ -456,6 +457,54 @@ void main() {
456
457
});
457
458
});
458
459
460
+ group ('CopyMessageLinkButton' , () {
461
+ setUp (() async {
462
+ TestDefaultBinaryMessengerBinding .instance.defaultBinaryMessenger.setMockMethodCallHandler (
463
+ SystemChannels .platform,
464
+ MockClipboard ().handleMethodCall,
465
+ );
466
+ });
467
+
468
+ Future <void > tapCopyMessageLinkButton (WidgetTester tester) async {
469
+ await tester.ensureVisible (find.byIcon (Icons .link, skipOffstage: false ));
470
+ await tester.tap (find.byIcon (Icons .link));
471
+ await tester.pump (); // [MenuItemButton.onPressed] called in a post-frame callback: flutter/flutter@e4a39fa2e
472
+ }
473
+
474
+ testWidgets ('copies message link to clipboard' , (tester) async {
475
+ final message = eg.streamMessage ();
476
+ final narrow = TopicNarrow .ofMessage (message);
477
+ await setupToMessageActionSheet (tester, message: message, narrow: narrow);
478
+ final store = await testBinding.globalStore.perAccount (eg.selfAccount.id);
479
+
480
+ await tapCopyMessageLinkButton (tester);
481
+ await tester.pump (Duration .zero);
482
+ final expectedLink = narrowLink (store, narrow, nearMessageId: message.id).toString ();
483
+ check (await Clipboard .getData ('text/plain' )).isNotNull ().text.equals (expectedLink);
484
+ });
485
+
486
+ testWidgets ('copies message link to clipboard with a snackbar' , (tester) async {
487
+ testBinding.deviceInfoResult = IosDeviceInfo (systemVersion: '16.0' );
488
+
489
+ final message = eg.streamMessage ();
490
+ final narrow = TopicNarrow .ofMessage (message);
491
+ await setupToMessageActionSheet (tester, message: message, narrow: narrow);
492
+ final store = await testBinding.globalStore.perAccount (eg.selfAccount.id);
493
+
494
+ await tapCopyMessageLinkButton (tester);
495
+ await tester.pump (Duration .zero);
496
+ final expectedLink = narrowLink (store, narrow, nearMessageId: message.id).toString ();
497
+ check (await Clipboard .getData ('text/plain' )).isNotNull ().text.equals (expectedLink);
498
+
499
+ final snackbar = tester.widget <SnackBar >(find.byType (SnackBar ));
500
+ check (snackbar.behavior).equals (SnackBarBehavior .floating);
501
+ final zulipLocalizations = GlobalLocalizations .zulipLocalizations;
502
+ tester.widget (find.descendant (matchRoot: true ,
503
+ of: find.byWidget (snackbar.content),
504
+ matching: find.text (zulipLocalizations.successMessageLinkCopied)));
505
+ });
506
+ });
507
+
459
508
group ('ShareButton' , () {
460
509
// Tests should call this.
461
510
MockSharePlus setupMockSharePlus () {
0 commit comments