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

FR-18979 - Add tests #27

Draft
wants to merge 17 commits into
base: master
Choose a base branch
from
Draft
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
2 changes: 1 addition & 1 deletion .github/workflows/onPush.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
uses: subosito/flutter-action@v2
with:
architecture: x64
flutter-version: 3.22.2
flutter-version: 3.24.5

- name: Install dependencies
run: flutter pub get
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,4 @@ migrate_working_dir/
**/doc/api/
.dart_tool/
build/
example/.patrol.env
25 changes: 25 additions & 0 deletions example/.patrol.env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Email + password user credentials
LOGIN_EMAIL=
LOGIN_PASSWORD=

# Email + password user wrong credentials
LOGIN_WRONG_EMAIL=
LOGIN_WRONG_PASSWORD=

# Sign up user credentials
SIGN_UP_TEMPLATE=some.email+{uuid}@mail.com
SIGN_UP_NAME=Test
SIGN_UP_ORGANIZATION=Flutter Integration Testing

# Google login email
GOOGLE_EMAIL=

# Google login credentials
APPLE_EMAIL=
APPLE_PASSWORD=

# Tenants
TENANT_ID_1=1148ad6b-e8d1-447c-910b-b270ed5deb22
TENANT_ID_2=9cbbbea9-18c8-4c18-a43a-fd6f1623d422
TENANT_NAME_1=Account 1
TENANT_NAME_2=Account 2
32 changes: 29 additions & 3 deletions example/android/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,15 @@ if (flutterVersionName == null) {
flutterVersionName = '1.0'
}

def fronteggDomain = "autheu.davidantoon.me"
def fronteggClientId = "b6adfe4c-d695-4c04-b95f-3ec9fd0c6cca"
def fronteggDomain = "app-axsx38m96enh.frontegg.com"
def fronteggClientId = "392b348b-a37c-471f-8f1b-2c35d23aa7e6"

android {
namespace "com.frontegg.demo"
compileSdk 34
ndkVersion flutter.ndkVersion
ndkVersion = "26.1.10909125"


compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
Expand Down Expand Up @@ -61,6 +63,23 @@ android {
buildConfigField "String", 'FRONTEGG_CLIENT_ID', "\"$fronteggClientId\""
buildConfigField "Boolean", 'FRONTEGG_USE_ASSETS_LINKS', "true"
buildConfigField "Boolean", 'FRONTEGG_USE_CHROME_CUSTOM_TABS', "true"

testInstrumentationRunner "pl.leancode.patrol.PatrolJUnitRunner"
testInstrumentationRunnerArguments clearPackageData: "true"
}

testOptions {
execution "ANDROIDX_TEST_ORCHESTRATOR"
}

signingConfigs {
debug {
storeFile file("./../../../.github/test-jks/debug.keystore")
}

release {
storeFile file("./../../../.github/test-jks/release.keystore")
}
}

signingConfigs {
Expand All @@ -81,6 +100,11 @@ android {
shrinkResources true
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}

debug {
minifyEnabled false
shrinkResources false
}
}

buildFeatures {
Expand All @@ -94,4 +118,6 @@ flutter {
source '../..'
}

dependencies {}
dependencies {
androidTestUtil "androidx.test:orchestrator:1.5.1"
}
12 changes: 12 additions & 0 deletions example/android/app/proguard-rules.pro
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,15 @@
# Frontegg SDK

-keepclasseswithmembers class com.frontegg.** {*;}

-dontwarn com.google.android.play.core.splitcompat.SplitCompatApplication
-dontwarn com.google.android.play.core.splitinstall.SplitInstallException
-dontwarn com.google.android.play.core.splitinstall.SplitInstallManager
-dontwarn com.google.android.play.core.splitinstall.SplitInstallManagerFactory
-dontwarn com.google.android.play.core.splitinstall.SplitInstallRequest$Builder
-dontwarn com.google.android.play.core.splitinstall.SplitInstallRequest
-dontwarn com.google.android.play.core.splitinstall.SplitInstallSessionState
-dontwarn com.google.android.play.core.splitinstall.SplitInstallStateUpdatedListener
-dontwarn com.google.android.play.core.tasks.OnFailureListener
-dontwarn com.google.android.play.core.tasks.OnSuccessListener
-dontwarn com.google.android.play.core.tasks.Task
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package com.frontegg.demo;

import androidx.test.platform.app.InstrumentationRegistry;

import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
import org.junit.runners.Parameterized.Parameters;

import pl.leancode.patrol.PatrolJUnitRunner;

@RunWith(Parameterized.class)
public class MainActivityTest {
@Parameters(name = "{0}")
public static Object[] testCases() {
PatrolJUnitRunner instrumentation = (PatrolJUnitRunner) InstrumentationRegistry.getInstrumentation();
// replace "MainActivity.class" with "io.flutter.embedding.android.FlutterActivity.class"
// if in AndroidManifest.xml in manifest/application/activity you have
// android:name="io.flutter.embedding.android.FlutterActivity"
instrumentation.setUp(MainActivity.class);
instrumentation.waitForPatrolAppService();
return instrumentation.listDartTests();
}

public MainActivityTest(String dartTestName) {
this.dartTestName = dartTestName;
}

private final String dartTestName;

@Test
public void runDartTest() {
PatrolJUnitRunner instrumentation = (PatrolJUnitRunner) InstrumentationRegistry.getInstrumentation();
instrumentation.runDartTest(dartTestName);
}
}
6 changes: 3 additions & 3 deletions example/android/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools">

<application
android:label="demo"
android:label="Frontegg Demo"
android:icon="@mipmap/ic_launcher"
android:allowBackup="true"
android:supportsRtl="true"
Expand Down Expand Up @@ -33,8 +33,8 @@
android:name="flutterEmbedding"
android:value="2" />

<activity android:name="com.frontegg.android.EmbeddedAuthActivity" tools:replace="android:enabled" android:enabled="false"/>
<activity android:name="com.frontegg.android.HostedAuthActivity" tools:replace="android:enabled" android:enabled="true"/>
<activity android:name="com.frontegg.android.EmbeddedAuthActivity" tools:replace="android:enabled" android:enabled="true"/>
<activity android:name="com.frontegg.android.HostedAuthActivity" tools:replace="android:enabled" android:enabled="false"/>
</application>


Expand Down
2 changes: 1 addition & 1 deletion example/android/gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.2-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.6-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
2 changes: 1 addition & 1 deletion example/android/settings.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ pluginManagement {

plugins {
id "dev.flutter.flutter-plugin-loader" version "1.0.0"
id "com.android.application" version "7.4.2" apply false
id "com.android.application" version "8.4.0" apply false
id "org.jetbrains.kotlin.android" version "1.9.10" apply false
}

Expand Down
100 changes: 100 additions & 0 deletions example/integration_test/src/login_via_apple_test.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
import 'dart:io';

import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:frontegg_flutter_example/main.dart';
import 'package:patrol/patrol.dart';

void main() {
const appleButtonLabel = "continue with apple";

late final String email;
late final String password;

patrolSetUp(() {
email = const String.fromEnvironment('APPLE_EMAIL');
password = const String.fromEnvironment('APPLE_PASSWORD');

assert(email.isNotEmpty && password.isNotEmpty);
});

patrolTest(
'Success Login via Apple Provider',
($) async {
await $.pumpWidget(const MyApp());
await $.pumpAndSettle();

await $.tap(find.byKey(const ValueKey("LoginButton")));

await $.native.tap(
Selector(text: appleButtonLabel),
timeout: const Duration(seconds: 10),
);
await Future.delayed(const Duration(seconds: 3));
if (Platform.isIOS) {
await $.native.tap(Selector(text: "Continue"));
await Future.delayed(const Duration(seconds: 7));
}

await $.native2.enterText(
NativeSelector(
ios: IOSSelector(
label: "Email or Phone Number",
),
android: AndroidSelector(
resourceName: "account_name_text_field",
),
),
text: email,
keyboardBehavior:
Platform.isIOS ? KeyboardBehavior.showAndDismiss : KeyboardBehavior.alternative,
);
if (Platform.isAndroid) {
await $.native.tap(Selector(resourceId: "sign-in"));
}
await Future.delayed(const Duration(seconds: 3));

await $.native2.enterText(
NativeSelector(
ios: IOSSelector(
label: "password",
),
android: AndroidSelector(
resourceName: "password_text_field",
),
),
text: password,
keyboardBehavior:
Platform.isIOS ? KeyboardBehavior.showAndDismiss : KeyboardBehavior.alternative,
);
if (Platform.isAndroid) {
await $.native.tap(Selector(resourceId: "sign-in"));
}

await $.native.waitUntilVisible(Selector(textStartsWith: "Do you want to continue using"));
await Future.delayed(const Duration(seconds: 2));
await $.native2.tap(
NativeSelector(
ios: IOSSelector(
label: "Continue",
instance: 1,
),
android: AndroidSelector(
textContains: "Continue",
isClickable: true,
),
),
);

await $.pumpAndSettle();
await $.waitUntilVisible(
find.text("Logout"),
timeout: const Duration(seconds: 15),
);

await $.tap(find.byKey(const ValueKey("LogoutButton")));
await $.pumpAndSettle();
await $.waitUntilVisible(find.text("Not Authenticated"));
},
);
}
Loading