Skip to content

Commit

Permalink
nites on android test, Hide ads while running on CI.
Browse files Browse the repository at this point in the history
  • Loading branch information
jigar-f committed Dec 26, 2024
1 parent 01721ae commit 2b54f3d
Show file tree
Hide file tree
Showing 6 changed files with 59 additions and 24 deletions.
2 changes: 1 addition & 1 deletion android/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -376,7 +376,7 @@ dependencies {
// androidTestImplementation "org.jetbrains.kotlin:kotlin-test-junit:$kotlin_version"
testImplementation 'junit:junit:4.13.2'
testImplementation "io.mockk:mockk:1.13.12"
androidTestUtil "androidx.test:orchestrator:1.4.2"
androidTestUtil "androidx.test:orchestrator:1.5.1"
// androidTestImplementation 'androidx.test:rules:1.6.1'
// androidTestImplementation 'androidx.annotation:annotation:1.8.2'
// androidTestImplementation 'androidx.test:runner:1.6.2'
Expand Down
55 changes: 34 additions & 21 deletions integration_test/features/vpn/vpn_flow_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import 'package:lantern/features/vpn/vpn_server_location.dart';
import 'package:lantern/features/vpn/vpn_status.dart';
import 'package:lantern/features/vpn/vpn_switch.dart';
import 'package:lantern/features/vpn/vpn_tab.dart';
import 'package:lantern/main.dart' as app;

import '../../utils/test_utils.dart';

Expand Down Expand Up @@ -80,25 +81,37 @@ void main() {
},
);

patrol(
'VPN turn off/on on mobile platforms',
(pTester) async {
final $ = pTester as PatrolIntegrationTester;
await $(VPNTab).waitUntilVisible();
await $.pump(const Duration(seconds: 3));
expect($('Disconnected'.i18n), findsOneWidget);
await $(const AdvancedSwitch()).tap();
await $.pump(const Duration(seconds: 1));
//Turn on
$.native.tap(Selector(text: 'OK'));
await $.pumpAndSettle();
expect($('connected'.i18n), findsOneWidget);
expect($('Disconnected'.i18n), findsNothing);
//Turn off
await $.pump(const Duration(seconds: 1));
await $(const AdvancedSwitch()).tap();
expect($('connected'.i18n), findsNothing);
expect($('Disconnected'.i18n), findsOneWidget);
},
);
if (isMobile()) {
patrolTest(
"VPN end to end",
skip: isDesktop(),
($) async {
await app.main(testMode: true);
await $.pumpAndSettle();
await $(VPNTab).waitUntilVisible();
await $.pump(const Duration(seconds: 6));
expect($('Disconnected'.i18n), findsOneWidget);
await $(AdvancedSwitch).tap();
await $.pump(const Duration(seconds: 1));

try {
//Turn on
await $.native.tap(Selector(text: 'OK'));
} on PatrolActionException {
//Do nothing it means user has already accepted the dialog
}
await $.pumpAndSettle();
await $.pump(const Duration(seconds: 1));
expect($('connected'.i18n), findsOneWidget);
expect($('Disconnected'.i18n), findsNothing);

//Tun off
await $(AdvancedSwitch).tap();
await $.pumpAndSettle();
await $.pump(const Duration(seconds: 1));
expect($('connected'.i18n), findsNothing);
expect($('Disconnected'.i18n), findsOneWidget);
},
);
}
}
14 changes: 14 additions & 0 deletions integration_test/test_bundle.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions lib/core/utils/utils.dart
Original file line number Diff line number Diff line change
Expand Up @@ -212,3 +212,8 @@ Map<String, PaymentMethod> paymentMethodsFromJson(dynamic json) {
});
return paymentMethods;
}

bool isTestRunning() {
final patrol = const String.fromEnvironment("PATROL_ANDROID_APP_NAME", defaultValue: "");
return patrol!="";
}
6 changes: 5 additions & 1 deletion lib/features/vpn/vpn_switch.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import 'package:lantern/core/utils/common_desktop.dart';
import 'package:lantern/features/vpn/vpn.dart';
import 'package:lantern/features/vpn/vpn_notifier.dart';

import '../../core/utils/utils.dart';

class VPNSwitch extends StatefulWidget {
const VPNSwitch({super.key});

Expand All @@ -26,7 +28,9 @@ class _VPNSwitchState extends State<VPNSwitch> {
final vpnNotifier = context.watch<VPNChangeNotifier>();
if (isMobile()) {
return sessionModel.shouldShowAds((context, provider, child) {
adHelper.loadAds(provider: provider);
if (!isTestRunning()) {
adHelper.loadAds(provider: provider);
}
return vpnModel.vpnStatus(context,
(BuildContext context, String vpnStatus, Widget? child) {
// Changes scale on mobile due to hit target
Expand Down
1 change: 0 additions & 1 deletion lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import 'package:window_manager/window_manager.dart';
// IOS issue
// https://github.com/flutter/flutter/issues/133465
Future<void> main({bool testMode = false}) async {
// CI will be true only when running appium test
WidgetsFlutterBinding.ensureInitialized();
try {
// To load the .env file contents into dotenv.
Expand Down

0 comments on commit 2b54f3d

Please sign in to comment.