Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
B3nedikt committed Jan 28, 2024
1 parent b67549a commit aa4569a
Show file tree
Hide file tree
Showing 5 changed files with 108 additions and 16 deletions.
Original file line number Diff line number Diff line change
@@ -1,12 +1,21 @@
package dev.b3nedikt.viewpump

import android.widget.EditText
import androidx.test.espresso.Espresso.onView
import androidx.test.espresso.matcher.RootMatchers.isDialog
import androidx.test.espresso.matcher.ViewMatchers.isAssignableFrom
import androidx.test.espresso.matcher.ViewMatchers.isDescendantOfA
import androidx.test.espresso.matcher.ViewMatchers.withId
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 kotlinx.coroutines.delay
import kotlinx.coroutines.runBlocking
import org.hamcrest.CoreMatchers.allOf
import org.junit.Rule
import org.junit.Test
import org.junit.runner.RunWith
Expand All @@ -18,11 +27,39 @@ class WebViewIntegrationTests {
val activityRule = ActivityScenarioRule(MainActivity::class.java)

@Test
fun test() {
fun testNumberPicker() {
onWebView()
.forceJavascriptEnabled()
.withElement(findElement(Locator.ID, "quantity"))
.withElement(findElement(Locator.ID, "numberPicker"))
.perform(webClick())

}

@Test
fun testDatePicker() {
onWebView()
.forceJavascriptEnabled()
.withElement(findElement(Locator.ID, "datePicker"))
.perform(webClick())

}

@Test
fun testAlertDialog() {
onWebView()
.forceJavascriptEnabled()
.withElement(findElement(Locator.ID, "alertDialog"))
.perform(webClick())

onView(allOf(
isDescendantOfA(withId(android.R.id.input)),
isAssignableFrom(EditText::class.java)))
.inRoot(isDialog())



runBlocking {
delay(5000)
}
}
}
57 changes: 47 additions & 10 deletions app/src/main/java/dev/b3nedikt/viewpump/sample/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -49,18 +49,55 @@ class MainActivity : AppCompatActivity() {
<html>
<body>
<h1>Display a Number Field</h1>
<h1>HTML which shows native views</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>
<form action="/action_page.php">
<label for="quantity">Number Picker:</label>
<input type="number" id="numberPicker" name="quantity">
<br>
<label for="start">Date Picker</label>
<input type="date" id="datePicker" name="trip-start" value="2018-07-22" min="2018-01-01" max="2018-12-31" />
<br>
<button id="alertDialog">Alert Dialog</button>
<dialog id="favDialog">
<form method="dialog">
<section>
<p><label for="favAnimal">Favorite animal:</label>
<select id="favAnimal">
<option>Brine shrimp</option>
<option>Red panda</option>
<option>Spider monkey</option>
</select>
</p>
</section>
<menu>
<button id="cancel" type="reset">Cancel</button>
<button type="submit">Confirm</button>
</menu>
</form>
</dialog>
<script>
(function () {
var updateButton = document.getElementById('alertDialog');
var cancelButton = document.getElementById('cancel');
var favDialog = document.getElementById('favDialog');
// Update button opens a modal dialog
updateButton.addEventListener('click', function () {
favDialog.showModal();
});
// Form cancel button closes the dialog box
cancelButton.addEventListener('click', function () {
favDialog.close();
});
})();
</script>
</form>
</body>
</html>
""".trimIndent()
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ org.gradle.parallel=true
android.useAndroidX=true
android.defaults.buildfeatures.buildconfig=false

version=4.0.14
version=4.0.15-alpha01
18 changes: 18 additions & 0 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,14 @@ appCompat = "1.6.1"

appLocale = "3.1.0"

junit = "4.13.2"
junitVersion = "1.1.5"
junitKtx = "1.1.5"
espressoCore = "3.5.1"
mockk = "1.13.8"
monitor = "1.6.1"
runner = "1.5.2"

[libraries]

kotlin-stdlib = { module = "org.jetbrains.kotlin:kotlin-stdlib" }
Expand All @@ -21,6 +29,16 @@ appCompat = { module = "androidx.appcompat:appcompat", version.ref = "appCompat"

appLocale = { module= "dev.b3nedikt.applocale:applocale" , version.ref = "appLocale" }

# Testing
espresso-core = { module = "androidx.test.espresso:espresso-core", version.ref = "espressoCore" }
espresso-web = { module = "androidx.test.espresso:espresso-web", version.ref = "espressoCore" }
ext-junit = { module = "androidx.test.ext:junit", version.ref = "junitVersion" }
junit = { module = "junit:junit", version.ref = "junit" }
junit-ktx = { group = "androidx.test.ext", name = "junit-ktx", version.ref = "junitKtx" }
mockk = { module = "io.mockk:mockk", version.ref = "mockk" }
monitor = { module = "androidx.test:monitor", version.ref = "monitor" }
runner = { module = "androidx.test:runner", version.ref = "runner" }

[plugins]

android-application = { id = "com.android.application", version.ref = "agp" }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -190,13 +190,13 @@ class ViewPumpAppCompatDelegate @JvmOverloads constructor(

// The following three widgets only exist on Samsung devices with android 9,
// we replace them with their counterparts from android.widgets
"com.android.internal.widget.CalendarView" ->
"CalendarView" ->
CalendarView(createWrappedContext(), attrs)

"com.android.internal.widget.DatePicker" ->
"DatePicker" ->
DatePicker(createWrappedContext(), attrs)

"com.android.internal.widget.NumberPicker" ->
"NumberPicker" ->
NumberPicker(createWrappedContext(), attrs)

else -> view
Expand Down

0 comments on commit aa4569a

Please sign in to comment.