Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
B3nedikt committed Jan 3, 2024
1 parent 0be8472 commit b67549a
Show file tree
Hide file tree
Showing 5 changed files with 79 additions and 8 deletions.
13 changes: 12 additions & 1 deletion app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ android {

buildTypes {
debug {
isMinifyEnabled = true
isMinifyEnabled = false
proguardFiles(getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro")
}
}
Expand All @@ -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)
}
Original file line number Diff line number Diff line change
@@ -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())

}
}
35 changes: 34 additions & 1 deletion app/src/main/java/dev/b3nedikt/viewpump/sample/MainActivity.kt
Original file line number Diff line number Diff line change
@@ -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() {

Expand All @@ -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)
Expand All @@ -33,6 +40,32 @@ class MainActivity : AppCompatActivity() {
}
button.text = getString(R.string.regular_button)
}

val webView = findViewById<WebView>(R.id.webView)
webView.settings.javaScriptEnabled = true
val unencodedHtml =
"""
<!DOCTYPE html>
<html>
<body>
<h1>Display a Number Field</h1>
<form action="/action_page.php">
<label for="quantity">Quantity (between 1 and 5):</label>
<input type="number" id="quantity" name="quantity" min="1" max="5">
<br>
<label for="start">Start date:</label>
<input type="date" id="start" name="trip-start" value="2018-07-22" min="2018-01-01" max="2018-12-31" />
<br>
<input type="submit">
</form>
</body>
</html>
""".trimIndent()
val encodedHtml = Base64.getEncoder().encodeToString(unencodedHtml.toByteArray())
webView.loadData(encodedHtml, "text/html", "base64")
}

override fun getDelegate(): AppCompatDelegate {
Expand Down
5 changes: 5 additions & 0 deletions app/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,11 @@
android:layout_marginTop="8dp"
android:text="@string/regular_button" />

<WebView
android:id="@+id/webView"
android:layout_width="match_parent"
android:layout_height="match_parent" />

</LinearLayout>

</merge>
6 changes: 0 additions & 6 deletions viewpump/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ android {

defaultConfig {
minSdk = AppConfig.minSdk
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
}

buildFeatures {
Expand All @@ -33,11 +32,6 @@ android {
}
}

testOptions {
unitTests {
isIncludeAndroidResources = true
}
}
namespace = "dev.b3nedikt.viewpump"
}

Expand Down

0 comments on commit b67549a

Please sign in to comment.