@@ -10,6 +10,7 @@ import 'package:zulip/api/model/model.dart';
1010import  'package:zulip/api/route/messages.dart' ;
1111import  'package:zulip/model/binding.dart' ;
1212import  'package:zulip/model/compose.dart' ;
13+ import  'package:zulip/model/internal_link.dart' ;
1314import  'package:zulip/model/localizations.dart' ;
1415import  'package:zulip/model/narrow.dart' ;
1516import  'package:zulip/model/store.dart' ;
@@ -439,6 +440,42 @@ void main() {
439440    });
440441  });
441442
443+   group ('CopyMessageLinkButton' , () {
444+     setUp (() async  {
445+       TestDefaultBinaryMessengerBinding .instance.defaultBinaryMessenger.setMockMethodCallHandler (
446+         SystemChannels .platform,
447+         MockClipboard ().handleMethodCall,
448+       );
449+     });
450+ 
451+     Future <void > tapCopyMessageLinkButton (WidgetTester  tester) async  {
452+       await  tester.ensureVisible (find.byIcon (Icons .link, skipOffstage:  false ));
453+       await  tester.tap (find.byIcon (Icons .link));
454+       await  tester.pump (); // [MenuItemButton.onPressed] called in a post-frame callback: flutter/flutter@e4a39fa2e 
455+     }
456+ 
457+     testWidgets ('copies message link to clipboard' , (tester) async  {
458+       testBinding.deviceInfoResult =  IosDeviceInfo (systemVersion:  '16.0' );
459+ 
460+       final  message =  eg.streamMessage ();
461+       final  narrow =  TopicNarrow .ofMessage (message);
462+       await  setupToMessageActionSheet (tester, message:  message, narrow:  narrow);
463+       final  store =  await  testBinding.globalStore.perAccount (eg.selfAccount.id);
464+ 
465+       await  tapCopyMessageLinkButton (tester);
466+       await  tester.pump (Duration .zero);
467+       final  expectedLink =  narrowLink (store, narrow, nearMessageId:  message.id).toString ();
468+       check (await  Clipboard .getData ('text/plain' )).isNotNull ().text.equals (expectedLink);
469+ 
470+       final  snackbar =  tester.widget <SnackBar >(find.byType (SnackBar ));
471+       check (snackbar.behavior).equals (SnackBarBehavior .floating);
472+       final  zulipLocalizations =  GlobalLocalizations .zulipLocalizations;
473+       tester.widget (find.descendant (matchRoot:  true ,
474+         of:  find.byWidget (snackbar.content),
475+         matching:  find.text (zulipLocalizations.successMessageLinkCopied)));
476+     });
477+   });
478+ 
442479  group ('ShareButton' , () {
443480    // Tests should call this. 
444481    MockSharePlus  setupMockSharePlus () {
@@ -481,7 +518,7 @@ void main() {
481518      check (mockSharePlus.sharedString).equals ('Hello world' );
482519      await  tester.pump ();
483520      await  tester.tap (find.byWidget (checkErrorDialog (tester,
484-         expectedTitle:  'Sharing failed' )));
521+            expectedTitle:  'Sharing failed' )));
485522    });
486523
487524    testWidgets ('request has an error' , (WidgetTester  tester) async  {
0 commit comments