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

Fixes part of #935: Optimised test cases for HDPI devices ( Packages M-P) #963

Merged
merged 26 commits into from
Apr 14, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
21b4588
Merge pull request #1 from oppia/develop
NullByte08 Mar 20, 2020
20af3fe
Merge pull request #2 from oppia/develop
NullByte08 Apr 2, 2020
d762755
Tests made compatible for HDPI devices
NullByte08 Apr 3, 2020
9913eae
Tests made compatible for HDPI devices commit 2
NullByte08 Apr 8, 2020
d411e55
Merge pull request #3 from oppia/develop
NullByte08 Apr 8, 2020
af09f9e
Merge remote-tracking branch 'origin/develop' into develop
NullByte08 Apr 8, 2020
dd46ae6
Tests made compatible for HDPI devices fixed packages A-H
NullByte08 Apr 10, 2020
477250b
Update ProfileEditActivity.kt
NullByte08 Apr 10, 2020
e79b084
Update ProfileEditActivityPresenter.kt
NullByte08 Apr 10, 2020
82c5124
Update ProfileEditViewModel.kt
NullByte08 Apr 10, 2020
f8d3894
Update AddProfileActivityTest.kt
NullByte08 Apr 10, 2020
a6ebf82
Update AdminPinActivityTest.kt
NullByte08 Apr 10, 2020
c7be7d8
Update PinPasswordActivityTest.kt
NullByte08 Apr 10, 2020
5f4f6bf
Update ProfileEditActivityTest.kt
NullByte08 Apr 10, 2020
2579da5
Update TopicRevisionFragmentTest.kt
NullByte08 Apr 10, 2020
ba6e537
Update NavigationDrawerTestActivityTest.kt
NullByte08 Apr 10, 2020
28d1e0d
Tests made compatible for HDPI devices for packages M-P
NullByte08 Apr 10, 2020
5fd8af6
Update AdministratorControlsActivityTest.kt
NullByte08 Apr 10, 2020
28c9419
Update AppVersionActivityTest.kt
NullByte08 Apr 10, 2020
c683929
Update HomeActivityTest.kt
NullByte08 Apr 10, 2020
9a4320e
Update PinPasswordActivityTest.kt
NullByte08 Apr 10, 2020
993c040
Update PinPasswordActivityTest.kt
NullByte08 Apr 13, 2020
8c01e77
Update ProfileChooserFragmentTest.kt
NullByte08 Apr 13, 2020
8497a22
Merge pull request #6 from oppia/develop
NullByte08 Apr 13, 2020
d693c1c
Update PinPasswordActivityTest.kt
NullByte08 Apr 14, 2020
e46aa5d
Update ProfileChooserFragmentTest.kt
NullByte08 Apr 14, 2020
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
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import androidx.test.espresso.action.GeneralClickAction
import androidx.test.espresso.action.Press
import androidx.test.espresso.action.Tap
import androidx.test.espresso.action.ViewActions.click
import androidx.test.espresso.action.ViewActions.swipeUp
import androidx.test.espresso.assertion.ViewAssertions.matches
import androidx.test.espresso.contrib.DrawerMatchers
import androidx.test.espresso.contrib.RecyclerViewActions.actionOnItemAtPosition
Expand Down Expand Up @@ -335,6 +336,7 @@ class OptionsFragmentTest {
)
onView(isRoot()).perform(orientationLandscape())
onView(withContentDescription(R.string.go_to_previous_page)).perform(click())
swipeUp()
onView(atPositionOnView(R.id.options_recyclerview, 2, R.id.audio_language_text_view)).check(
matches(withText("Chinese"))
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ class AdminPinActivityTest {
typeText("12345"),
closeSoftKeyboard()
)
onView(withId(R.id.submit_button)).perform(click())
onView(withId(R.id.submit_button)).perform(scrollTo()).perform(click())
intended(hasComponent(AddProfileActivity::class.java.name))
}
}
Expand All @@ -96,7 +96,7 @@ class AdminPinActivityTest {
typeText("12345"),
closeSoftKeyboard()
)
onView(withId(R.id.submit_button)).perform(click())
onView(withId(R.id.submit_button)).perform(scrollTo()).perform(click())
intended(hasComponent(AdministratorControlsActivity::class.java.name))
}
}
Expand Down Expand Up @@ -140,7 +140,7 @@ class AdminPinActivityTest {
typeText("1234"),
closeSoftKeyboard()
)
onView(withId(R.id.submit_button)).perform(click())
onView(withId(R.id.submit_button)).perform(scrollTo()).perform(click())
onView(allOf(withId(R.id.error_text), isDescendantOfA(withId(R.id.input_confirm_pin)))).check(
matches(
withText(
Expand All @@ -162,7 +162,7 @@ class AdminPinActivityTest {
typeText("1234"),
closeSoftKeyboard()
)
onView(withId(R.id.submit_button)).perform(click())
onView(withId(R.id.submit_button)).perform(scrollTo()).perform(click())
onView(allOf(withId(R.id.input), isDescendantOfA(withId(R.id.input_confirm_pin)))).perform(
typeText("5"),
closeSoftKeyboard()
Expand Down Expand Up @@ -310,7 +310,7 @@ class AdminPinActivityTest {
typeText("54321"),
closeSoftKeyboard()
)
onView(withId(R.id.submit_button)).perform(click())
onView(withId(R.id.submit_button)).perform(scrollTo()).perform(click())
onView(isRoot()).perform(orientationLandscape())
onView(
allOf(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
package org.oppia.app.profile

import android.app.Activity
import android.app.ActivityManager
import android.app.Application
import android.content.Context
import android.content.Context.ACTIVITY_SERVICE
import androidx.test.core.app.ActivityScenario
import androidx.test.core.app.ApplicationProvider
import androidx.test.espresso.Espresso.onView
Expand All @@ -19,6 +22,10 @@ import androidx.test.espresso.matcher.ViewMatchers.isRoot
import androidx.test.espresso.matcher.ViewMatchers.withId
import androidx.test.espresso.matcher.ViewMatchers.withText
import androidx.test.ext.junit.runners.AndroidJUnit4
import androidx.test.platform.app.InstrumentationRegistry
import androidx.test.platform.app.InstrumentationRegistry.getInstrumentation
import androidx.test.runner.lifecycle.ActivityLifecycleMonitorRegistry
import androidx.test.runner.lifecycle.Stage
import dagger.BindsInstance
import dagger.Component
import dagger.Module
Expand Down Expand Up @@ -49,6 +56,9 @@ import javax.inject.Inject
import javax.inject.Qualifier
import javax.inject.Singleton

private const val TIMEOUT = 1000L
private const val CONDITION_CHECK_INTERVAL = 100L

@RunWith(AndroidJUnit4::class)
class PinPasswordActivityTest {

Expand Down Expand Up @@ -103,7 +113,9 @@ class PinPasswordActivityTest {
adminId
)
).use {
onView(withId(R.id.input_pin)).perform(typeText("12345"))
closeSoftKeyboard()
onView(withId(R.id.input_pin)).perform(typeText("12345"), closeSoftKeyboard())
waitUntilActivityVisible<HomeActivity>()
intended(hasComponent(HomeActivity::class.java.name))
}
}
Expand All @@ -118,6 +130,7 @@ class PinPasswordActivityTest {
)
).use {
onView(withId(R.id.input_pin)).perform(typeText("123"))
waitUntilActivityVisible<HomeActivity>()
intended(hasComponent(HomeActivity::class.java.name))
}
}
Expand All @@ -132,7 +145,8 @@ class PinPasswordActivityTest {
adminId
)
).use {
onView(withId(R.id.input_pin)).perform(typeText("54321"), closeSoftKeyboard())
closeSoftKeyboard()
onView(withId(R.id.input_pin)).perform(closeSoftKeyboard()).perform(typeText("54321"), closeSoftKeyboard())
onView(withText(context.getString(R.string.pin_password_incorrect_pin))).check(matches(isDisplayed()))
}
}
Expand Down Expand Up @@ -283,6 +297,7 @@ class PinPasswordActivityTest {
onView(withText(context.getString(R.string.admin_settings_submit))).perform(click())
onView(withText(context.getString(R.string.pin_password_close))).perform(click())
onView(withId(R.id.input_pin)).perform(typeText("321"))
waitUntilActivityVisible<HomeActivity>()
intended(hasComponent(HomeActivity::class.java.name))
}
}
Expand Down Expand Up @@ -443,6 +458,8 @@ class PinPasswordActivityTest {
adminId
)
).use {
closeSoftKeyboard()
closeSoftKeyboard()
onView(withId(R.id.input_pin)).perform(typeText("54321"), closeSoftKeyboard())
onView(isRoot()).perform(orientationLandscape())
onView(withText(context.getString(R.string.pin_password_incorrect_pin))).check(matches(isDisplayed()))
Expand Down Expand Up @@ -520,6 +537,7 @@ class PinPasswordActivityTest {
adminId
)
).use {
closeSoftKeyboard()
onView(withId(R.id.input_pin)).perform(typeText(""), closeSoftKeyboard())
onView(withId(R.id.show_pin)).perform(click())
onView(isRoot()).perform(orientationLandscape())
Expand All @@ -528,6 +546,35 @@ class PinPasswordActivityTest {
}
}

private fun getCurrentActivity(): Activity? {
var currentActivity: Activity? = null
getInstrumentation().runOnMainSync {
run {
currentActivity = ActivityLifecycleMonitorRegistry.getInstance().getActivitiesInStage(
Stage.RESUMED
).elementAtOrNull(0)
}
}
return currentActivity
}

private inline fun <reified T : Activity> isVisible(): Boolean {
val am =
InstrumentationRegistry.getInstrumentation().targetContext.getSystemService(ACTIVITY_SERVICE) as ActivityManager
val visibleActivityName = this.getCurrentActivity()!!::class.java.name
return visibleActivityName == T::class.java.name
}

private inline fun <reified T : Activity> waitUntilActivityVisible() {
val startTime = System.currentTimeMillis()
while (!isVisible<T>()) {
Thread.sleep(CONDITION_CHECK_INTERVAL)
if (System.currentTimeMillis() - startTime >= TIMEOUT) {
throw AssertionError("Activity ${T::class.java.simpleName} not visible after $TIMEOUT milliseconds")
}
}
}

@Qualifier annotation class TestDispatcher

// TODO(#89): Move this to a common test application component.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
package org.oppia.app.profile

import android.app.Activity
import android.app.ActivityManager
import android.app.Application
import android.content.Context
import android.content.Context.ACTIVITY_SERVICE
import android.content.Intent
import android.content.res.Resources
import android.widget.TextView
Expand All @@ -26,6 +29,10 @@ import androidx.test.espresso.matcher.ViewMatchers.withId
import androidx.test.espresso.matcher.ViewMatchers.withParent
import androidx.test.espresso.matcher.ViewMatchers.withText
import androidx.test.ext.junit.runners.AndroidJUnit4
import androidx.test.platform.app.InstrumentationRegistry
import androidx.test.platform.app.InstrumentationRegistry.getInstrumentation
import androidx.test.runner.lifecycle.ActivityLifecycleMonitorRegistry
import androidx.test.runner.lifecycle.Stage
import com.google.common.truth.Truth.assertThat
import dagger.BindsInstance
import dagger.Component
Expand Down Expand Up @@ -61,6 +68,9 @@ import javax.inject.Inject
import javax.inject.Qualifier
import javax.inject.Singleton

private const val TIMEOUT = 1000L
private const val CONDITION_CHECK_INTERVAL = 100L

@RunWith(AndroidJUnit4::class)
class ProfileChooserFragmentTest {

Expand Down Expand Up @@ -323,6 +333,7 @@ class ProfileChooserFragmentTest {
)
launch<ProfileActivity>(createProfileActivityIntent()).use {
onView(atPosition(R.id.profile_recycler_view, 1)).perform(click())
waitUntilActivityVisible<AdminPinActivity>()
intended(hasComponent(AdminPinActivity::class.java.name))
}
}
Expand Down Expand Up @@ -408,6 +419,35 @@ class ProfileChooserFragmentTest {
}
}

private fun getCurrentActivity(): Activity? {
var currentActivity: Activity? = null
getInstrumentation().runOnMainSync {
run {
currentActivity = ActivityLifecycleMonitorRegistry.getInstance().getActivitiesInStage(
Stage.RESUMED
).elementAtOrNull(0)
}
}
return currentActivity
}

private inline fun <reified T : Activity> isVisible(): Boolean {
val am =
InstrumentationRegistry.getInstrumentation().targetContext.getSystemService(ACTIVITY_SERVICE) as ActivityManager
val visibleActivityName = this.getCurrentActivity()!!::class.java.name
return visibleActivityName == T::class.java.name
}

private inline fun <reified T : Activity> waitUntilActivityVisible() {
val startTime = System.currentTimeMillis()
while (!isVisible<T>()) {
Thread.sleep(CONDITION_CHECK_INTERVAL)
if (System.currentTimeMillis() - startTime >= TIMEOUT) {
throw AssertionError("Activity ${T::class.java.simpleName} not visible after $TIMEOUT milliseconds")
}
}
}

private fun createProfileActivityIntent(): Intent {
return ProfileActivity.createProfileActivity(ApplicationProvider.getApplicationContext())
}
Expand Down