1+ import 'package:buzz/features/pairing/pairing_page.dart' ;
2+ import 'package:buzz/shared/theme/theme.dart' ;
3+ import 'package:flutter/material.dart' ;
14import 'package:buzz/shared/community/paired_community_landing.dart' ;
25import 'dart:async' ;
36import 'dart:convert' ;
@@ -294,10 +297,13 @@ void main() {
294297 expect (container.read (pairingProvider).status, PairingStatus .storing);
295298 }
296299
297- test (
298- 'desktop-only code is verified remotely before import approval' ,
299- () async {
300- await notifier.pair (pairingCode);
300+ testWidgets (
301+ 'delayed desktop responses retain one attempt and leave code entry' ,
302+ (tester) async {
303+ final pairing = notifier.pair (pairingCode);
304+ await tester.pump ();
305+ await tester.pump (const Duration (milliseconds: 500 ));
306+ await pairing;
301307 expect (socket.published.single['tags' ], hasLength (1 ));
302308 expect (
303309 socket
@@ -315,6 +321,17 @@ void main() {
315321 final first = socket.decryptedPublishedMessages (sourceSecret).last;
316322 expect (first['type' ], 'code-submit' );
317323 expect (first['code' ], '111111' );
324+ bool ? wrongResult;
325+ unawaited (wrong.then ((value) => wrongResult = value));
326+ await tester.pump (const Duration (seconds: 11 ));
327+ expect (wrongResult, isNull);
328+ expect (await notifier.verifyDesktopCode ('111111' ), isFalse);
329+ expect (
330+ socket
331+ .decryptedPublishedMessages (sourceSecret)
332+ .where ((m) => m['type' ] == 'code-submit' ),
333+ hasLength (1 ),
334+ );
318335 socket.sendSourceMessage (
319336 sourceSecret: sourceSecret,
320337 sessionSecretHex: sessionSecretHex,
@@ -326,46 +343,88 @@ void main() {
326343 );
327344 expect (await wrong, isFalse);
328345 expect (importAuth.lastCommunity, isNull);
329- final correct = notifier.verifyDesktopCode ('222222' );
346+ await tester.pumpWidget (
347+ UncontrolledProviderScope (
348+ container: container,
349+ child: MaterialApp (
350+ theme: AppTheme .light (),
351+ home: const PairingPage (),
352+ ),
353+ ),
354+ );
355+ await tester.enterText (
356+ find.byKey (const Key ('pairing-code-input' )),
357+ '222222' ,
358+ );
359+ await tester.pump (const Duration (seconds: 11 ));
360+ expect (find.text ('Enter pairing code' ), findsOneWidget);
361+ expect (
362+ find.text ('Couldn’t check the code. Try again.' ),
363+ findsNothing,
364+ );
365+ expect (
366+ socket
367+ .decryptedPublishedMessages (sourceSecret)
368+ .where ((m) => m['type' ] == 'code-submit' ),
369+ hasLength (2 ),
370+ );
330371 socket.sendSourceMessage (
331372 sourceSecret: sourceSecret,
332373 sessionSecretHex: sessionSecretHex,
333374 message: {'type' : 'sas-confirm' },
334375 includeTranscriptHash: true ,
335376 );
336- expect (await correct, isTrue);
377+ socket.sendSourceMessage (
378+ sourceSecret: sourceSecret,
379+ sessionSecretHex: sessionSecretHex,
380+ message: {
381+ 'type' : 'payload' ,
382+ 'payload_type' : 'credentials' ,
383+ 'payload' : jsonEncode ({
384+ 'relayUrl' : 'https://relay.test' ,
385+ 'pubkey' : nostr.Keys (sourceSecret).public,
386+ 'nsec' : nostr.Keys (sourceSecret).nsec,
387+ }),
388+ },
389+ );
390+ await tester.pump ();
391+ expect (find.text ('Enter pairing code' ), findsNothing);
392+ expect (find.text ('Protect your identity' ), findsOneWidget);
337393 expect (
338394 container.read (pairingProvider).status,
339395 PairingStatus .confirmingSas,
340396 );
341397 expect (importAuth.lastCommunity, isNull);
342398 notifier.setProtectSensitiveActions (false );
343399 notifier.confirmSas ();
344- await Future <void >.delayed (Duration .zero);
345- expect (
346- container.read (pairingProvider).status,
347- PairingStatus .transferring,
348- );
400+ await tester.pump ();
401+ expect (container.read (pairingProvider).status, PairingStatus .storing);
349402 expect (
350403 socket
351404 .decryptedPublishedMessages (sourceSecret)
352405 .where ((m) => m['type' ] == 'sas-confirm' ),
353406 isEmpty,
354407 );
408+ notifier.reset ();
409+ await tester.pumpWidget (const SizedBox .shrink ());
355410 },
356411 );
357412
358- test (
359- 'final rejected guess exits the session and reset cancels pending verification' ,
360- () async {
361- await notifier.pair (pairingCode);
413+ testWidgets (
414+ 'delayed final rejection exits the session and reset cancels pending verification' ,
415+ (tester) async {
416+ final pairing = notifier.pair (pairingCode);
417+ await tester.pump ();
418+ await tester.pump (const Duration (milliseconds: 500 ));
419+ await pairing;
362420 socket.sendSourceMessage (
363421 sourceSecret: sourceSecret,
364422 sessionSecretHex: sessionSecretHex,
365423 message: {'type' : 'desktop-code' },
366424 );
367425 final result = notifier.verifyDesktopCode ('111111' );
368426 final request = socket.decryptedPublishedMessages (sourceSecret).last;
427+ await tester.pump (const Duration (seconds: 11 ));
369428 socket.sendSourceMessage (
370429 sourceSecret: sourceSecret,
371430 sessionSecretHex: sessionSecretHex,
@@ -379,7 +438,10 @@ void main() {
379438 expect (container.read (pairingProvider).status, PairingStatus .error);
380439 expect (importAuth.lastCommunity, isNull);
381440 notifier.reset ();
382- await notifier.pair (pairingCode);
441+ final nextPairing = notifier.pair (pairingCode);
442+ await tester.pump ();
443+ await tester.pump (const Duration (milliseconds: 500 ));
444+ await nextPairing;
383445 socket.sendSourceMessage (
384446 sourceSecret: sourceSecret,
385447 sessionSecretHex: sessionSecretHex,
0 commit comments