@@ -354,6 +354,8 @@ void main() {
354354
355355 setUpAll (() {
356356 registerFallbackValue (_FakeNewLabel ());
357+ registerFallbackValue (_bitcoinLocalWallet ());
358+ registerFallbackValue (BigInt .zero);
357359 });
358360
359361 setUp (() {
@@ -532,4 +534,60 @@ void main() {
532534 },
533535 );
534536 });
537+
538+ group ('SendCubit.onAmountConfirmed note handling' , () {
539+ /// A Lightning send whose invoice carries a description. The description is
540+ /// the only record of what the payment was for, and the note is what ends
541+ /// up as a label on the sender's own transaction — so an empty note takes
542+ /// the description rather than dropping it. A note the user typed always
543+ /// wins over the description.
544+ SendState lightningReadyState ({String label = '' }) => SendState (
545+ step: SendStep .confirm,
546+ sendType: SendType .lightning,
547+ selectedWallet: _bitcoinLocalWallet (),
548+ paymentRequest: const PaymentRequest .bolt11 (
549+ invoice: 'lnbc1-invoice' ,
550+ amountSat: 50000 ,
551+ paymentHash: 'hash' ,
552+ description: 'Order 123456' ,
553+ expiresAt: 0 ,
554+ isTestnet: false ,
555+ ),
556+ label: label,
557+ );
558+
559+ /// Stops `onAmountConfirmed` right after the emit under test: the quote
560+ /// lookup is the next call and returning an error makes it bail out.
561+ void stubQuoteFailure () {
562+ when (
563+ () => getSendSwapQuoteUsecase.execute (
564+ wallet: any (named: 'wallet' ),
565+ amountSat: any (named: 'amountSat' ),
566+ ),
567+ ).thenAnswer ((_) async => const Err (SendInvoiceExpiredFailure ()));
568+ }
569+
570+ test ('an empty note is seeded with the invoice description' , () async {
571+ final cubit = buildCubit ();
572+ addTearDown (cubit.close);
573+ stubQuoteFailure ();
574+ cubit.setStateForTest (lightningReadyState ());
575+
576+ await cubit.onAmountConfirmed ();
577+
578+ expect (cubit.state.lightningInvoice, isNotNull);
579+ expect (cubit.state.label, 'Order 123456' );
580+ });
581+
582+ test ('a note the user typed overrides the invoice description' , () async {
583+ final cubit = buildCubit ();
584+ addTearDown (cubit.close);
585+ stubQuoteFailure ();
586+ cubit.setStateForTest (lightningReadyState (label: 'coffee' ));
587+
588+ await cubit.onAmountConfirmed ();
589+
590+ expect (cubit.state.label, 'coffee' );
591+ });
592+ });
535593}
0 commit comments