-
Notifications
You must be signed in to change notification settings - Fork 72
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #303 from wealthfront/fix-import
Add basic Integration Test for Compose flavor
- Loading branch information
Showing
4 changed files
with
125 additions
and
1 deletion.
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
58 changes: 58 additions & 0 deletions
58
...idTest/java/com/wealthfront/magellan/sample/migration/DisableAnimationsAndKeyboardRule.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,58 @@ | ||
package com.wealthfront.magellan.sample.migration | ||
|
||
import android.provider.Settings.Global.ANIMATOR_DURATION_SCALE | ||
import android.provider.Settings.Global.TRANSITION_ANIMATION_SCALE | ||
import android.provider.Settings.Global.WINDOW_ANIMATION_SCALE | ||
import android.util.Log | ||
import androidx.test.platform.app.InstrumentationRegistry | ||
import androidx.test.uiautomator.UiDevice | ||
import org.junit.rules.TestRule | ||
import org.junit.runner.Description | ||
import org.junit.runners.model.Statement | ||
|
||
private const val TRANSITION_ANIMATION_SETTINGS = "settings put global $TRANSITION_ANIMATION_SCALE" | ||
private const val WINDOW_ANIMATION_SETTINGS = "settings put global $WINDOW_ANIMATION_SCALE" | ||
private const val ANIMATOR_ANIMATION_SETTINGS = "settings put global $ANIMATOR_DURATION_SCALE" | ||
private const val DISABLE_KEYBOARD_SETTINGS = "settings put secure show_ime_with_hard_keyboard" | ||
|
||
class DisableAnimationsAndKeyboardRule : TestRule { | ||
|
||
override fun apply(base: Statement, description: Description): Statement { | ||
return object : Statement() { | ||
override fun evaluate() { | ||
disableAnimationsAndKeyboard() | ||
try { | ||
base.evaluate() | ||
} finally { | ||
enableAnimationsAndKeyboard() | ||
} | ||
} | ||
} | ||
} | ||
|
||
private fun enableAnimationsAndKeyboard() { | ||
Log.v( | ||
DisableAnimationsAndKeyboardRule::class.java.simpleName, | ||
"Enabling animations and keyboard" | ||
) | ||
executeUiDeviceCommand("$TRANSITION_ANIMATION_SETTINGS 1") | ||
executeUiDeviceCommand("$WINDOW_ANIMATION_SETTINGS 1") | ||
executeUiDeviceCommand("$ANIMATOR_ANIMATION_SETTINGS 1") | ||
executeUiDeviceCommand("$DISABLE_KEYBOARD_SETTINGS 1") | ||
} | ||
|
||
private fun disableAnimationsAndKeyboard() { | ||
Log.v( | ||
DisableAnimationsAndKeyboardRule::class.java.simpleName, | ||
"Disabling animations and keyboard" | ||
) | ||
executeUiDeviceCommand("$TRANSITION_ANIMATION_SETTINGS 0") | ||
executeUiDeviceCommand("$WINDOW_ANIMATION_SETTINGS 0") | ||
executeUiDeviceCommand("$ANIMATOR_ANIMATION_SETTINGS 0") | ||
executeUiDeviceCommand("$DISABLE_KEYBOARD_SETTINGS 0") | ||
} | ||
|
||
private fun executeUiDeviceCommand(command: String) { | ||
UiDevice.getInstance(InstrumentationRegistry.getInstrumentation()).executeShellCommand(command) | ||
} | ||
} |
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
58 changes: 58 additions & 0 deletions
58
...ndroidTestCompose/java/com/wealthfront/magellan/sample/migration/uitest/NavigationTest.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,58 @@ | ||
package com.wealthfront.magellan.sample.migration.uitest | ||
|
||
import android.app.Application | ||
import androidx.compose.ui.test.junit4.ComposeTestRule | ||
import androidx.compose.ui.test.junit4.createEmptyComposeRule | ||
import androidx.compose.ui.test.onNodeWithText | ||
import androidx.compose.ui.test.performClick | ||
import androidx.test.core.app.ActivityScenario | ||
import androidx.test.core.app.ApplicationProvider | ||
import androidx.test.core.app.launchActivity | ||
import com.wealthfront.magellan.sample.migration.AppComponentContainer | ||
import com.wealthfront.magellan.sample.migration.CoroutineIdlingRule | ||
import com.wealthfront.magellan.sample.migration.DisableAnimationsAndKeyboardRule | ||
import com.wealthfront.magellan.sample.migration.MainActivity | ||
import com.wealthfront.magellan.sample.migration.TestAppComponent | ||
import com.wealthfront.magellan.sample.migration.api.DogApi | ||
import com.wealthfront.magellan.sample.migration.api.DogBreedsResponse | ||
import com.wealthfront.magellan.sample.migration.api.DogImageResponse | ||
import com.wealthfront.magellan.sample.migration.coWhen | ||
import org.junit.Before | ||
import org.junit.Rule | ||
import org.junit.Test | ||
import javax.inject.Inject | ||
|
||
class NavigationTest { | ||
|
||
@Rule @JvmField | ||
val disableAnimationsAndKeyboardRule = DisableAnimationsAndKeyboardRule() | ||
|
||
@Rule @JvmField | ||
val coroutineIdlingRule = CoroutineIdlingRule() | ||
|
||
@Rule @JvmField | ||
val composeRule: ComposeTestRule = createEmptyComposeRule() | ||
|
||
@Inject lateinit var api: DogApi | ||
|
||
private lateinit var activityScenario: ActivityScenario<MainActivity> | ||
|
||
@Before | ||
fun setup() { | ||
val context = ApplicationProvider.getApplicationContext<Application>() | ||
((context as AppComponentContainer).injector() as TestAppComponent).inject(this) | ||
|
||
coWhen { api.getAllBreeds() } | ||
.thenReturn(DogBreedsResponse(message = mapOf("robotic" to emptyList()), status = "success")) | ||
coWhen { api.getRandomImageForBreed("robotic") }.thenReturn( | ||
DogImageResponse(message = "image-url", status = "success") | ||
) | ||
} | ||
|
||
@Test | ||
fun visitRetriever() { | ||
activityScenario = launchActivity() | ||
|
||
composeRule.onNodeWithText("robotic").performClick() | ||
} | ||
} |