From b67549a8b36b1efefb5886a082534b3eae78afcd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Benedikt=20L=C3=B6bbecke?= Date: Mon, 1 Jan 2024 14:25:31 +0100 Subject: [PATCH] WIP --- app/build.gradle.kts | 13 ++++++- .../viewpump/WebViewIntegrationTests.kt | 28 +++++++++++++++ .../b3nedikt/viewpump/sample/MainActivity.kt | 35 ++++++++++++++++++- app/src/main/res/layout/activity_main.xml | 5 +++ viewpump/build.gradle.kts | 6 ---- 5 files changed, 79 insertions(+), 8 deletions(-) create mode 100644 app/src/androidTest/java/dev/b3nedikt/viewpump/WebViewIntegrationTests.kt diff --git a/app/build.gradle.kts b/app/build.gradle.kts index 1d206cf..82ac219 100644 --- a/app/build.gradle.kts +++ b/app/build.gradle.kts @@ -17,7 +17,7 @@ android { buildTypes { debug { - isMinifyEnabled = true + isMinifyEnabled = false proguardFiles(getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro") } } @@ -37,4 +37,15 @@ dependencies { implementation(libs.appCompat) implementation(libs.appLocale) + + // Testing + testImplementation(libs.junit) + //testImplementation(libs.junit.ktx) + testImplementation(libs.mockk) + androidTestImplementation(libs.ext.junit) + androidTestImplementation(libs.runner) + androidTestImplementation(libs.monitor) + androidTestImplementation("androidx.test:rules:1.5.0") + androidTestImplementation(libs.espresso.core) + androidTestImplementation(libs.espresso.web) } diff --git a/app/src/androidTest/java/dev/b3nedikt/viewpump/WebViewIntegrationTests.kt b/app/src/androidTest/java/dev/b3nedikt/viewpump/WebViewIntegrationTests.kt new file mode 100644 index 0000000..4e63ed8 --- /dev/null +++ b/app/src/androidTest/java/dev/b3nedikt/viewpump/WebViewIntegrationTests.kt @@ -0,0 +1,28 @@ +package dev.b3nedikt.viewpump + +import androidx.test.espresso.web.sugar.Web.onWebView +import androidx.test.espresso.web.webdriver.DriverAtoms.findElement +import androidx.test.espresso.web.webdriver.DriverAtoms.webClick +import androidx.test.espresso.web.webdriver.Locator +import androidx.test.ext.junit.rules.ActivityScenarioRule +import androidx.test.ext.junit.runners.AndroidJUnit4 +import dev.b3nedikt.viewpump.sample.MainActivity +import org.junit.Rule +import org.junit.Test +import org.junit.runner.RunWith + +@RunWith(AndroidJUnit4::class) +class WebViewIntegrationTests { + + @get:Rule + val activityRule = ActivityScenarioRule(MainActivity::class.java) + + @Test + fun test() { + onWebView() + .forceJavascriptEnabled() + .withElement(findElement(Locator.ID, "quantity")) + .perform(webClick()) + + } +} \ No newline at end of file diff --git a/app/src/main/java/dev/b3nedikt/viewpump/sample/MainActivity.kt b/app/src/main/java/dev/b3nedikt/viewpump/sample/MainActivity.kt index d44a981..3a8ec22 100644 --- a/app/src/main/java/dev/b3nedikt/viewpump/sample/MainActivity.kt +++ b/app/src/main/java/dev/b3nedikt/viewpump/sample/MainActivity.kt @@ -1,14 +1,19 @@ package dev.b3nedikt.viewpump.sample +import android.annotation.SuppressLint +import android.os.Build import android.os.Bundle +import android.webkit.WebView import android.widget.Button +import androidx.annotation.RequiresApi import androidx.appcompat.app.AppCompatActivity import androidx.appcompat.app.AppCompatDelegate import androidx.appcompat.app.ViewPumpAppCompatDelegate import dev.b3nedikt.app_locale.AppLocale import dev.b3nedikt.app_locale.AppLocale.currentLocale import dev.b3nedikt.app_locale.AppLocale.desiredLocale -import java.util.* +import java.util.Base64 +import java.util.Locale class MainActivity : AppCompatActivity() { @@ -20,6 +25,8 @@ class MainActivity : AppCompatActivity() { ) } + @SuppressLint("SetJavaScriptEnabled") + @RequiresApi(Build.VERSION_CODES.O) override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContentView(R.layout.activity_main) @@ -33,6 +40,32 @@ class MainActivity : AppCompatActivity() { } button.text = getString(R.string.regular_button) } + + val webView = findViewById(R.id.webView) + webView.settings.javaScriptEnabled = true + val unencodedHtml = + """ + + + + +

Display a Number Field

+ +
+ + +
+ + +
+ +
+ + + + """.trimIndent() + val encodedHtml = Base64.getEncoder().encodeToString(unencodedHtml.toByteArray()) + webView.loadData(encodedHtml, "text/html", "base64") } override fun getDelegate(): AppCompatDelegate { diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml index 054cc0a..16636b7 100644 --- a/app/src/main/res/layout/activity_main.xml +++ b/app/src/main/res/layout/activity_main.xml @@ -35,6 +35,11 @@ android:layout_marginTop="8dp" android:text="@string/regular_button" /> + + diff --git a/viewpump/build.gradle.kts b/viewpump/build.gradle.kts index 4360995..091cbe0 100644 --- a/viewpump/build.gradle.kts +++ b/viewpump/build.gradle.kts @@ -11,7 +11,6 @@ android { defaultConfig { minSdk = AppConfig.minSdk - testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner" } buildFeatures { @@ -33,11 +32,6 @@ android { } } - testOptions { - unitTests { - isIncludeAndroidResources = true - } - } namespace = "dev.b3nedikt.viewpump" }