-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
24 changed files
with
539 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
61 changes: 61 additions & 0 deletions
61
app/src/androidTest/kotlin/me/xizzhu/android/joshua/end2end/BaseE2eTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
/* | ||
* Copyright (C) 2020 Xizhi Zhu | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package me.xizzhu.android.joshua.end2end | ||
|
||
import androidx.annotation.CallSuper | ||
import androidx.test.core.app.ApplicationProvider | ||
import androidx.test.espresso.IdlingPolicies | ||
import me.xizzhu.android.joshua.core.repository.local.android.db.AndroidDatabase | ||
import me.xizzhu.android.joshua.core.repository.local.android.db.MetadataDao | ||
import java.util.concurrent.TimeUnit | ||
import kotlin.test.AfterTest | ||
import kotlin.test.BeforeTest | ||
import kotlin.test.assertEquals | ||
import kotlin.test.assertTrue | ||
|
||
abstract class BaseE2eTest { | ||
private lateinit var androidDatabase: AndroidDatabase | ||
|
||
@BeforeTest | ||
@CallSuper | ||
open fun setup() { | ||
IdlingPolicies.setMasterPolicyTimeout(5L, TimeUnit.MINUTES) | ||
IdlingPolicies.setIdlingResourceTimeout(5L, TimeUnit.MINUTES) | ||
|
||
androidDatabase = AndroidDatabase(ApplicationProvider.getApplicationContext()) | ||
resetLocalDatabase() | ||
} | ||
|
||
private fun resetLocalDatabase() { | ||
androidDatabase.removeAll() | ||
} | ||
|
||
@AfterTest | ||
@CallSuper | ||
open fun tearDown() { | ||
resetLocalDatabase() | ||
androidDatabase.close() | ||
} | ||
|
||
protected fun assertNoCurrentTranslation() { | ||
assertTrue(androidDatabase.metadataDao.read(MetadataDao.KEY_CURRENT_TRANSLATION, "").isEmpty()) | ||
} | ||
|
||
protected fun assertCurrentTranslation(currentTranslation: String) { | ||
assertEquals(currentTranslation, androidDatabase.metadataDao.read(MetadataDao.KEY_CURRENT_TRANSLATION, "")) | ||
} | ||
} |
101 changes: 101 additions & 0 deletions
101
app/src/androidTest/kotlin/me/xizzhu/android/joshua/end2end/BaseRobot.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
/* | ||
* Copyright (C) 2020 Xizhi Zhu | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package me.xizzhu.android.joshua.end2end | ||
|
||
import android.app.Activity | ||
import android.content.Intent | ||
import android.view.View | ||
import android.view.WindowManager | ||
import androidx.annotation.StringRes | ||
import androidx.test.espresso.Espresso | ||
import androidx.test.espresso.Espresso.onView | ||
import androidx.test.espresso.action.ViewActions.click | ||
import androidx.test.espresso.action.ViewActions.longClick | ||
import androidx.test.espresso.assertion.PositionAssertions.isCompletelyBelow | ||
import androidx.test.espresso.assertion.ViewAssertions.matches | ||
import androidx.test.espresso.matcher.RootMatchers.isDialog | ||
import androidx.test.espresso.matcher.ViewMatchers.isDisplayed | ||
import androidx.test.espresso.matcher.ViewMatchers.withText | ||
import androidx.test.rule.ActivityTestRule | ||
import org.hamcrest.Matcher | ||
|
||
open class BaseRobot<T : Activity, SELF : BaseRobot<T, SELF>>(protected val activityRule: ActivityTestRule<T>) { | ||
open fun launch(): SELF { | ||
activityRule.launchActivity(Intent()) | ||
activityRule.activity.runOnUiThread { | ||
activityRule.activity.window.addFlags( | ||
WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON or | ||
WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED or | ||
WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON | ||
) | ||
} | ||
return self() | ||
} | ||
|
||
@Suppress("UNCHECKED_CAST") | ||
protected fun self(): SELF = this as SELF | ||
|
||
fun pressBack(): SELF { | ||
Espresso.pressBack() | ||
return self() | ||
} | ||
|
||
fun clickDialogPositive(): SELF { | ||
onView(withText(android.R.string.yes)).inRoot(isDialog()).perform(click()) | ||
return self() | ||
} | ||
|
||
fun clickDialogNegative(): SELF { | ||
onView(withText(android.R.string.no)).inRoot(isDialog()).perform(click()) | ||
return self() | ||
} | ||
|
||
fun hasDialogWithText(@StringRes text: Int): SELF { | ||
onView(withText(text)).inRoot(isDialog()) | ||
return self() | ||
} | ||
|
||
fun clickText(text: String): SELF { | ||
onView(withText(text)).perform(click()) | ||
return self() | ||
} | ||
|
||
fun longClickText(text: String): SELF { | ||
onView(withText(text)).perform(longClick()) | ||
return self() | ||
} | ||
|
||
fun hasText(@StringRes text: Int): SELF { | ||
onView(withText(text)).check(matches(isDisplayed())) | ||
return self() | ||
} | ||
|
||
fun hasText(text: String): SELF { | ||
onView(withText(text)).check(matches(isDisplayed())) | ||
return self() | ||
} | ||
|
||
fun isTextDisplayedBelow(@StringRes text: Int, matcher: Matcher<View>): SELF { | ||
onView(withText(text)).check(matches(isDisplayed())).check(isCompletelyBelow(matcher)) | ||
return self() | ||
} | ||
|
||
fun isTextDisplayedBelow(text: String, matcher: Matcher<View>): SELF { | ||
onView(withText(text)).check(matches(isDisplayed())).check(isCompletelyBelow(matcher)) | ||
return self() | ||
} | ||
} |
36 changes: 36 additions & 0 deletions
36
app/src/androidTest/kotlin/me/xizzhu/android/joshua/end2end/ProgressDialogIdlingResource.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
/* | ||
* Copyright (C) 2020 Xizhi Zhu | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package me.xizzhu.android.joshua.end2end | ||
|
||
import androidx.test.espresso.IdlingResource | ||
import me.xizzhu.android.joshua.ui.ProgressDialog | ||
|
||
class ProgressDialogIdlingResource(private val dialog: ProgressDialog) : IdlingResource { | ||
private var resourceCallback: IdlingResource.ResourceCallback? = null | ||
|
||
override fun getName(): String = ProgressDialogIdlingResource::class.java.name | ||
|
||
override fun isIdleNow(): Boolean { | ||
val idle = !dialog.isShowing() | ||
if (idle) resourceCallback?.onTransitionToIdle() | ||
return idle | ||
} | ||
|
||
override fun registerIdleTransitionCallback(callback: IdlingResource.ResourceCallback?) { | ||
this.resourceCallback = callback | ||
} | ||
} |
Oops, something went wrong.