diff --git a/gui/packages/ubuntupro/lib/pages/subscription_status/subscribe_now_page.dart b/gui/packages/ubuntupro/lib/pages/subscription_status/subscribe_now_page.dart index 9b2cec8ff..efaf8475c 100644 --- a/gui/packages/ubuntupro/lib/pages/subscription_status/subscribe_now_page.dart +++ b/gui/packages/ubuntupro/lib/pages/subscription_status/subscribe_now_page.dart @@ -9,8 +9,8 @@ import 'subscribe_now_widgets.dart'; import 'subscription_status_model.dart'; class SubscribeNowPage extends StatelessWidget { - const SubscribeNowPage({super.key, required this.onSubscribed}); - final void Function(SubscriptionInfo) onSubscribed; + const SubscribeNowPage({super.key, required this.onSubscriptionUpdate}); + final void Function(SubscriptionInfo) onSubscriptionUpdate; @override Widget build(BuildContext context) { @@ -51,7 +51,7 @@ class SubscribeNowPage extends StatelessWidget { ), ); }, - ifRight: onSubscribed, + ifRight: onSubscriptionUpdate, ); }, child: Text(lang.subscribeNow), @@ -78,7 +78,7 @@ class SubscribeNowPage extends StatelessWidget { ), ProTokenInputField( onApply: (token) { - model.applyProToken(token); + model.applyProToken(token).then(onSubscriptionUpdate); ScaffoldMessenger.of(context).showSnackBar( SnackBar( content: Text( diff --git a/gui/packages/ubuntupro/lib/pages/subscription_status/subscription_status_model.dart b/gui/packages/ubuntupro/lib/pages/subscription_status/subscription_status_model.dart index da38a43b8..4cd6c86dc 100644 --- a/gui/packages/ubuntupro/lib/pages/subscription_status/subscription_status_model.dart +++ b/gui/packages/ubuntupro/lib/pages/subscription_status/subscription_status_model.dart @@ -71,8 +71,9 @@ class SubscribeNowModel extends SubscriptionStatusModel { final AgentApiClient client; SubscribeNowModel(this.client) : super._(); - Future applyProToken(ProToken token) { - return client.applyProToken(token.value); + Future applyProToken(ProToken token) async { + await client.applyProToken(token.value); + return client.subscriptionInfo(); } void launchProWebPage() { diff --git a/gui/packages/ubuntupro/lib/pages/subscription_status/subscription_status_page.dart b/gui/packages/ubuntupro/lib/pages/subscription_status/subscription_status_page.dart index 39ca52dc2..8b347b04b 100644 --- a/gui/packages/ubuntupro/lib/pages/subscription_status/subscription_status_page.dart +++ b/gui/packages/ubuntupro/lib/pages/subscription_status/subscription_status_page.dart @@ -47,7 +47,7 @@ class SubscriptionStatusPage extends StatelessWidget { caption: lang.orgManaged, ), SubscribeNowModel() => SubscribeNowPage( - onSubscribed: (info) => + onSubscriptionUpdate: (info) => context.read>().value = info, ), }, diff --git a/gui/packages/ubuntupro/test/pages/subscription_status/subscribe_now_page_test.dart b/gui/packages/ubuntupro/test/pages/subscription_status/subscribe_now_page_test.dart index c58a96a4b..71e4bb3e0 100644 --- a/gui/packages/ubuntupro/test/pages/subscription_status/subscribe_now_page_test.dart +++ b/gui/packages/ubuntupro/test/pages/subscription_status/subscribe_now_page_test.dart @@ -80,7 +80,7 @@ void main() { testWidgets('feedback when applying token', (tester) async { final model = MockSubscribeNowModel(); when(model.applyProToken(any)).thenAnswer((_) async { - return; + return SubscriptionInfo()..ensureUser(); }); final app = buildApp(model, onSubscribeNoop); await tester.pumpWidget(app); @@ -119,7 +119,7 @@ Widget buildApp( body: Provider.value( value: model, child: SubscribeNowPage( - onSubscribed: onSubs, + onSubscriptionUpdate: onSubs, ), ), ), diff --git a/gui/packages/ubuntupro/test/pages/subscription_status/subscribe_now_page_test.mocks.dart b/gui/packages/ubuntupro/test/pages/subscription_status/subscribe_now_page_test.mocks.dart index c8a9248eb..42718b383 100644 --- a/gui/packages/ubuntupro/test/pages/subscription_status/subscribe_now_page_test.mocks.dart +++ b/gui/packages/ubuntupro/test/pages/subscription_status/subscribe_now_page_test.mocks.dart @@ -3,16 +3,16 @@ // Do not manually edit this file. // ignore_for_file: no_leading_underscores_for_library_prefixes -import 'dart:async' as _i5; +import 'dart:async' as _i6; -import 'package:agentapi/agentapi.dart' as _i8; -import 'package:dart_either/dart_either.dart' as _i3; +import 'package:agentapi/agentapi.dart' as _i3; +import 'package:dart_either/dart_either.dart' as _i4; import 'package:mockito/mockito.dart' as _i1; -import 'package:p4w_ms_store/p4w_ms_store.dart' as _i7; +import 'package:p4w_ms_store/p4w_ms_store.dart' as _i8; import 'package:ubuntupro/core/agent_api_client.dart' as _i2; -import 'package:ubuntupro/core/pro_token.dart' as _i6; +import 'package:ubuntupro/core/pro_token.dart' as _i7; import 'package:ubuntupro/pages/subscription_status/subscription_status_model.dart' - as _i4; + as _i5; // ignore_for_file: type=lint // ignore_for_file: avoid_redundant_argument_values @@ -36,8 +36,19 @@ class _FakeAgentApiClient_0 extends _i1.SmartFake ); } -class _FakeEither_1 extends _i1.SmartFake implements _i3.Either { - _FakeEither_1( +class _FakeSubscriptionInfo_1 extends _i1.SmartFake + implements _i3.SubscriptionInfo { + _FakeSubscriptionInfo_1( + Object parent, + Invocation parentInvocation, + ) : super( + parent, + parentInvocation, + ); +} + +class _FakeEither_2 extends _i1.SmartFake implements _i4.Either { + _FakeEither_2( Object parent, Invocation parentInvocation, ) : super( @@ -49,7 +60,7 @@ class _FakeEither_1 extends _i1.SmartFake implements _i3.Either { /// A class which mocks [SubscribeNowModel]. /// /// See the documentation for Mockito's code generation for more information. -class MockSubscribeNowModel extends _i1.Mock implements _i4.SubscribeNowModel { +class MockSubscribeNowModel extends _i1.Mock implements _i5.SubscribeNowModel { MockSubscribeNowModel() { _i1.throwOnMissingStub(this); } @@ -63,14 +74,21 @@ class MockSubscribeNowModel extends _i1.Mock implements _i4.SubscribeNowModel { ), ) as _i2.AgentApiClient); @override - _i5.Future applyProToken(_i6.ProToken? token) => (super.noSuchMethod( + _i6.Future<_i3.SubscriptionInfo> applyProToken(_i7.ProToken? token) => + (super.noSuchMethod( Invocation.method( #applyProToken, [token], ), - returnValue: _i5.Future.value(), - returnValueForMissingStub: _i5.Future.value(), - ) as _i5.Future); + returnValue: + _i6.Future<_i3.SubscriptionInfo>.value(_FakeSubscriptionInfo_1( + this, + Invocation.method( + #applyProToken, + [token], + ), + )), + ) as _i6.Future<_i3.SubscriptionInfo>); @override void launchProWebPage() => super.noSuchMethod( Invocation.method( @@ -80,21 +98,21 @@ class MockSubscribeNowModel extends _i1.Mock implements _i4.SubscribeNowModel { returnValueForMissingStub: null, ); @override - _i5.Future<_i3.Either<_i7.PurchaseStatus, _i8.SubscriptionInfo>> + _i6.Future<_i4.Either<_i8.PurchaseStatus, _i3.SubscriptionInfo>> purchaseSubscription() => (super.noSuchMethod( Invocation.method( #purchaseSubscription, [], ), - returnValue: _i5.Future< - _i3.Either<_i7.PurchaseStatus, _i8.SubscriptionInfo>>.value( - _FakeEither_1<_i7.PurchaseStatus, _i8.SubscriptionInfo>( + returnValue: _i6.Future< + _i4.Either<_i8.PurchaseStatus, _i3.SubscriptionInfo>>.value( + _FakeEither_2<_i8.PurchaseStatus, _i3.SubscriptionInfo>( this, Invocation.method( #purchaseSubscription, [], ), )), - ) as _i5 - .Future<_i3.Either<_i7.PurchaseStatus, _i8.SubscriptionInfo>>); + ) as _i6 + .Future<_i4.Either<_i8.PurchaseStatus, _i3.SubscriptionInfo>>); }