From 407ae022522712e0eb65a44abd1514cc3c2fc5e8 Mon Sep 17 00:00:00 2001 From: Carlos Date: Tue, 17 Oct 2023 10:13:59 -0300 Subject: [PATCH] isPurchaseAllowed should be an answer ... instead of a question. --- .../subscription_status/subscribe_now_page.dart | 4 ++-- .../subscription_status_model.dart | 2 +- .../subscription_status/subscribe_now_page_test.dart | 12 ++++++------ .../subscribe_now_page_test.mocks.dart | 4 ++-- .../subscription_status_model_test.dart | 2 +- 5 files changed, 12 insertions(+), 12 deletions(-) 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 aa75c1fab..559290e0f 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 @@ -28,11 +28,11 @@ class SubscribeNowPage extends StatelessWidget { mainAxisAlignment: MainAxisAlignment.start, children: [ Tooltip( - message: model.isPurchaseAllowed() + message: model.purchaseAllowed() ? '' : lang.subscribeNowTooltipDisabled, child: ElevatedButton( - onPressed: model.isPurchaseAllowed() + onPressed: model.purchaseAllowed() ? () async { final subs = await model.purchaseSubscription(); 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 2171412e5..fea939ac5 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 @@ -105,7 +105,7 @@ class SubscribeNowModel extends SubscriptionStatusModel { /// Returns true if the environment variable 'UP4W_ALLOW_STORE_PURCHASE' has been set. /// Since this reading won't change during the app lifetime, even if the user changes /// it's value from outside, the value is cached so we don't check the environment more than once. - bool isPurchaseAllowed() { + bool purchaseAllowed() { return _isPurchaseAllowed ??= ['true', '1', 'on'] .contains(Environment()['UP4W_ALLOW_STORE_PURCHASE']?.toLowerCase()); } 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 ad7b0c792..c24d8c3df 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 @@ -17,7 +17,7 @@ import 'token_samples.dart' as tks; void main() { testWidgets('launch web page', (tester) async { final model = MockSubscribeNowModel(); - when(model.isPurchaseAllowed()).thenReturn(true); + when(model.purchaseAllowed()).thenReturn(true); var called = false; when(model.launchProWebPage()).thenAnswer((_) async { called = true; @@ -36,7 +36,7 @@ void main() { group('purchase button enabled by model', () { testWidgets('disabled', (tester) async { final model = MockSubscribeNowModel(); - when(model.isPurchaseAllowed()).thenReturn(false); + when(model.purchaseAllowed()).thenReturn(false); final app = buildApp(model, (_) {}); await tester.pumpWidget(app); final context = tester.element(find.byType(SubscribeNowPage)); @@ -52,7 +52,7 @@ void main() { }); testWidgets('enabled', (tester) async { final model = MockSubscribeNowModel(); - when(model.isPurchaseAllowed()).thenReturn(true); + when(model.purchaseAllowed()).thenReturn(true); final app = buildApp(model, (_) {}); await tester.pumpWidget(app); final context = tester.element(find.byType(SubscribeNowPage)); @@ -70,7 +70,7 @@ void main() { group('subscribe', () { testWidgets('calls back on success', (tester) async { final model = MockSubscribeNowModel(); - when(model.isPurchaseAllowed()).thenReturn(true); + when(model.purchaseAllowed()).thenReturn(true); var called = false; when(model.purchaseSubscription()).thenAnswer((_) async { final info = SubscriptionInfo()..ensureMicrosoftStore(); @@ -93,7 +93,7 @@ void main() { testWidgets('feedback on error', (tester) async { const purchaseError = PurchaseStatus.networkError; final model = MockSubscribeNowModel(); - when(model.isPurchaseAllowed()).thenReturn(true); + when(model.purchaseAllowed()).thenReturn(true); var called = false; when(model.purchaseSubscription()).thenAnswer((_) async { return purchaseError.left(); @@ -116,7 +116,7 @@ void main() { }); testWidgets('feedback when applying token', (tester) async { final model = MockSubscribeNowModel(); - when(model.isPurchaseAllowed()).thenReturn(true); + when(model.purchaseAllowed()).thenReturn(true); when(model.applyProToken(any)).thenAnswer((_) async { return SubscriptionInfo()..ensureUser(); }); 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 573f84bdd..491307ba5 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 @@ -116,9 +116,9 @@ class MockSubscribeNowModel extends _i1.Mock implements _i5.SubscribeNowModel { ) as _i6 .Future<_i4.Either<_i8.PurchaseStatus, _i3.SubscriptionInfo>>); @override - bool isPurchaseAllowed() => (super.noSuchMethod( + bool purchaseAllowed() => (super.noSuchMethod( Invocation.method( - #isPurchaseAllowed, + #purchaseAllowed, [], ), returnValue: false, diff --git a/gui/packages/ubuntupro/test/pages/subscription_status/subscription_status_model_test.dart b/gui/packages/ubuntupro/test/pages/subscription_status/subscription_status_model_test.dart index 71aafac2d..af164fa7c 100644 --- a/gui/packages/ubuntupro/test/pages/subscription_status/subscription_status_model_test.dart +++ b/gui/packages/ubuntupro/test/pages/subscription_status/subscription_status_model_test.dart @@ -99,7 +99,7 @@ void main() { test('disabled by default', () { final model = SubscribeNowModel(client); - expect(model.isPurchaseAllowed(), isFalse); + expect(model.purchaseAllowed(), isFalse); }); test('expected failure', () async {