Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Move about link and fix broken link #984

Merged
merged 3 commits into from
Nov 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions gui/packages/ubuntupro/lib/l10n/app_en.arb
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,16 @@
"agentStateQuerying": "Checking Ubuntu Pro background agent's state.",
"agentStateUnreachable": "Attempting to recover Ubuntu Pro background agent.",

"proHeading": "Open source software security by the publishers\nof Ubuntu, now available on Windows.",
"proHeading": "Open source software security by the publishers of Ubuntu, now available on Windows. {aboutLink}",
"@proHeading": {
"placeholders": {
"aboutLink": {
"type": "String"
}
}
},
"getUbuntuPro": "Get Ubuntu Pro",
"about": "About Ubuntu Pro",
"learnMore": "Learn more",

"subscriptionIsActive": "Your subscription is active!",
"storeManaged": "This subscription is managed through Microsoft Store.",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import 'package:agentapi/agentapi.dart';
import 'package:dart_either/dart_either.dart';
import 'package:flutter/foundation.dart';
import 'package:p4w_ms_store/p4w_ms_store.dart';
import 'package:url_launcher/url_launcher.dart';
import '/core/agent_api_client.dart';
import '/core/pro_token.dart';

Expand All @@ -16,10 +15,6 @@ class SubscribeNowModel {
return client.applyProToken(token.value);
}

void launchProWebPage() {
launchUrl(Uri.https('ubuntu.com/pro'));
}

/// Triggers a purchase transaction via MS Store.
/// If the purchase succeeds, this notifies the background agent and returns its [SubscriptionInfo] reply.
/// Otherwise the purchase status is returned so the UI can give the user some feedback.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import 'package:agentapi/agentapi.dart';
import 'package:flutter/material.dart';
import 'package:flutter_gen/gen_l10n/app_localizations.dart';
import 'package:flutter_markdown/flutter_markdown.dart';
import 'package:p4w_ms_store/p4w_ms_store.dart';
import 'package:provider/provider.dart';
import 'package:ubuntu_service/ubuntu_service.dart';
import 'package:url_launcher/url_launcher_string.dart';
import 'package:wizard_router/wizard_router.dart';

import '/core/agent_api_client.dart';
Expand All @@ -21,12 +23,24 @@ class SubscribeNowPage extends StatelessWidget {
final model = context.watch<SubscribeNowModel>();
final lang = AppLocalizations.of(context);
final theme = Theme.of(context);
final linkStyle = MarkdownStyleSheet.fromTheme(
theme.copyWith(
textTheme: theme.textTheme.copyWith(
bodyMedium: theme.textTheme.bodyLarge,
),
),
);

return LandingPage(
children: [
Text(
lang.proHeading,
style:
theme.textTheme.bodyLarge!.copyWith(fontWeight: FontWeight.w100),
SizedBox(
width: 400,
child: MarkdownBody(
data:
lang.proHeading('[${lang.learnMore}](https://ubuntu.com/pro)'),
onTapLink: (_, href, __) => launchUrlString(href!),
styleSheet: linkStyle,
),
),
const SizedBox(height: 16),
Row(
Expand Down Expand Up @@ -68,10 +82,6 @@ class SubscribeNowPage extends StatelessWidget {
),
const SizedBox(width: 8.0),
],
OutlinedButton(
onPressed: model.launchProWebPage,
child: Text(lang.about),
),
],
),
const Padding(
Expand Down
2 changes: 1 addition & 1 deletion gui/packages/ubuntupro/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -964,7 +964,7 @@ packages:
source: hosted
version: "3.2.0"
url_launcher_platform_interface:
dependency: transitive
dependency: "direct dev"
description:
name: url_launcher_platform_interface
sha256: "552f8a1e663569be95a8190206a38187b531910283c3e982193e4f2733f01029"
Expand Down
1 change: 1 addition & 0 deletions gui/packages/ubuntupro/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ dev_dependencies:
nested: ^1.0.0
protobuf: ^3.1.0
stack_trace: ^1.11.0
url_launcher_platform_interface: ^2.3.2
yaru_test: ^0.2.0

# For information on the generic Dart part of this file, see the
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ import 'package:ubuntu_service/ubuntu_service.dart';
import 'package:ubuntupro/core/agent_api_client.dart';
import 'package:ubuntupro/pages/subscribe_now/subscribe_now_model.dart';
import 'package:ubuntupro/pages/subscribe_now/subscribe_now_page.dart';
import 'package:url_launcher_platform_interface/link.dart';
import 'package:url_launcher_platform_interface/url_launcher_platform_interface.dart';
import 'package:wizard_router/wizard_router.dart';

import '../../utils/build_multiprovider_app.dart';
Expand All @@ -25,24 +27,22 @@ void main() {
// See more: https://github.com/flutter/flutter/issues/108726#issuecomment-1205035859
binding.platformDispatcher.textScaleFactorTestValue = 0.6;

final launcher = FakeUrlLauncher();
UrlLauncherPlatform.instance = launcher;

testWidgets('launch web page', (tester) async {
final model = MockSubscribeNowModel();
when(model.purchaseAllowed).thenReturn(true);
var called = false;
when(model.launchProWebPage()).thenAnswer((_) async {
called = true;
});

final app = buildApp(model, onSubscribeNoop);
await tester.pumpWidget(app);
final context = tester.element(find.byType(SubscribeNowPage));
final lang = AppLocalizations.of(context);

expect(called, isFalse);
final button = find.text(lang.about);
await tester.tap(button);
expect(launcher.launched, isFalse);
await tester.tapOnText(find.textRange.ofSubstring('Learn more'));
await tester.pump();
expect(called, isTrue);
expect(launcher.launched, isTrue);
});

group('purchase button enabled by model', () {
testWidgets('disabled', (tester) async {
final model = MockSubscribeNowModel();
Expand Down Expand Up @@ -177,3 +177,49 @@ Widget buildApp(
void onSubscribeNoop(SubscriptionInfo _) {}

class FakeAgentApiClient extends Fake implements AgentApiClient {}

class FakeUrlLauncher extends UrlLauncherPlatform {
bool launched = false;

@override
Future<bool> canLaunch(String url) async {
return true;
}

@override
Future<void> closeWebView() async {}

@override
Future<bool> launchUrl(String url, LaunchOptions options) async {
launched = true;
return true;
}

@override
Future<bool> supportsCloseForMode(PreferredLaunchMode mode) async {
return true;
}

@override
Future<bool> supportsMode(PreferredLaunchMode mode) async {
return true;
}

@override
Future<bool> launch(
String url, {
required bool useSafariVC,
required bool useWebView,
required bool enableJavaScript,
required bool enableDomStorage,
required bool universalLinksOnly,
required Map<String, String> headers,
String? webOnlyWindowName,
}) async {
launched = true;
return true;
}

@override
LinkDelegate? get linkDelegate => null;
}
Original file line number Diff line number Diff line change
Expand Up @@ -98,15 +98,6 @@ class MockSubscribeNowModel extends _i1.Mock implements _i5.SubscribeNowModel {
)),
) as _i6.Future<_i3.SubscriptionInfo>);

@override
void launchProWebPage() => super.noSuchMethod(
Invocation.method(
#launchProWebPage,
[],
),
returnValueForMissingStub: null,
);

@override
_i6.Future<_i4.Either<_i8.PurchaseStatus, _i3.SubscriptionInfo>>
purchaseSubscription() => (super.noSuchMethod(
Expand Down
Loading