Skip to content

Commit

Permalink
fix(gui): SubscribeNowPage calls back also when applying manually s…
Browse files Browse the repository at this point in the history
…upplied token. (#305)

The `SubscribeNowPage` accepts a callback that must be called when this
page causes the current subscription to change, such as when the user
purchases a subscription through the store. It turns out that the
callback was being called only in such situation, thus the previous name
made sense.

But that was a mistake: user manual input also causes the underlying
subscription to change, thus that must also call the callback. Hence,
the reason for renaming it.

This not only renames it, but also ensures it is called for the manual
input case.
  • Loading branch information
CarlosNihelton authored Oct 4, 2023
2 parents a7edf81 + 23ffe22 commit 642c5bf
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -51,7 +51,7 @@ class SubscribeNowPage extends StatelessWidget {
),
);
},
ifRight: onSubscribed,
ifRight: onSubscriptionUpdate,
);
},
child: Text(lang.subscribeNow),
Expand All @@ -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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,9 @@ class SubscribeNowModel extends SubscriptionStatusModel {
final AgentApiClient client;
SubscribeNowModel(this.client) : super._();

Future<void> applyProToken(ProToken token) {
return client.applyProToken(token.value);
Future<SubscriptionInfo> applyProToken(ProToken token) async {
await client.applyProToken(token.value);
return client.subscriptionInfo();
}

void launchProWebPage() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ class SubscriptionStatusPage extends StatelessWidget {
caption: lang.orgManaged,
),
SubscribeNowModel() => SubscribeNowPage(
onSubscribed: (info) =>
onSubscriptionUpdate: (info) =>
context.read<ValueNotifier<SubscriptionInfo>>().value = info,
),
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -119,7 +119,7 @@ Widget buildApp(
body: Provider.value(
value: model,
child: SubscribeNowPage(
onSubscribed: onSubs,
onSubscriptionUpdate: onSubs,
),
),
),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -36,8 +36,19 @@ class _FakeAgentApiClient_0 extends _i1.SmartFake
);
}

class _FakeEither_1<L, R> extends _i1.SmartFake implements _i3.Either<L, R> {
_FakeEither_1(
class _FakeSubscriptionInfo_1 extends _i1.SmartFake
implements _i3.SubscriptionInfo {
_FakeSubscriptionInfo_1(
Object parent,
Invocation parentInvocation,
) : super(
parent,
parentInvocation,
);
}

class _FakeEither_2<L, R> extends _i1.SmartFake implements _i4.Either<L, R> {
_FakeEither_2(
Object parent,
Invocation parentInvocation,
) : super(
Expand All @@ -49,7 +60,7 @@ class _FakeEither_1<L, R> extends _i1.SmartFake implements _i3.Either<L, R> {
/// 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);
}
Expand All @@ -63,14 +74,21 @@ class MockSubscribeNowModel extends _i1.Mock implements _i4.SubscribeNowModel {
),
) as _i2.AgentApiClient);
@override
_i5.Future<void> applyProToken(_i6.ProToken? token) => (super.noSuchMethod(
_i6.Future<_i3.SubscriptionInfo> applyProToken(_i7.ProToken? token) =>
(super.noSuchMethod(
Invocation.method(
#applyProToken,
[token],
),
returnValue: _i5.Future<void>.value(),
returnValueForMissingStub: _i5.Future<void>.value(),
) as _i5.Future<void>);
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(
Expand All @@ -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>>);
}

0 comments on commit 642c5bf

Please sign in to comment.