Skip to content
Prev Previous commit
Next Next commit
Adressing review comments
Change-Id: Id15eb3775869d8914e49d73f5fbc66f05ba4e09c
  • Loading branch information
JoseAlcerreca committed Nov 20, 2020
commit d984804f85b949a29e51d72fd96fb0f2f225e5b3
26 changes: 15 additions & 11 deletions Owl/app/src/androidTest/java/com/example/owl/ui/NavigationTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@ import androidx.compose.runtime.Providers
import androidx.compose.ui.test.hasLabel
import androidx.compose.ui.test.hasSubstring
import androidx.compose.ui.test.junit4.createAndroidComposeRule
import androidx.compose.ui.test.junit4.createComposeRule
import androidx.compose.ui.test.onNodeWithLabel
import androidx.compose.ui.test.onNodeWithSubstring
import androidx.compose.ui.test.onRoot
import androidx.compose.ui.test.performClick
import androidx.compose.ui.test.printToLog
import androidx.test.platform.app.InstrumentationRegistry
import com.example.owl.R
import com.example.owl.model.courses
Expand All @@ -40,22 +40,27 @@ import org.junit.Test
*/
class NavigationTest {

/**
* Using an empty activity to have control of the content that is set.
*
* This activity must be declared in the manifest (see src/debug/AndroidManifest.xml)
*/
@get:Rule
val composeTestRule = createAndroidComposeRule<ComponentActivity>()
lateinit var activity: ComponentActivity

private fun startActivity(startDestination: String? = null) {
composeTestRule.activityRule.scenario.onActivity {
activity = it
}
composeTestRule.setContent {
Providers(AmbientBackDispatcher provides activity.onBackPressedDispatcher) {
ProvideWindowInsets {
ProvideTestImageLoader {
if (startDestination == null) {
NavGraph()
} else {
NavGraph(startDestination)
composeTestRule.setContent {
Providers(AmbientBackDispatcher provides activity.onBackPressedDispatcher) {
ProvideWindowInsets {
ProvideTestImageLoader {
if (startDestination == null) {
NavGraph()
} else {
NavGraph(startDestination)
}
}
}
}
Expand Down Expand Up @@ -90,7 +95,6 @@ class NavigationTest {
// Given the app in the courses screen
startActivity(MainDestinations.COURSES_ROUTE)

composeTestRule.onRoot().printToLog("jalc")
// Navigate to the first course
composeTestRule.onNode(
hasLabel(getFeaturedCourseLabel()).and(hasSubstring(courses.first().name))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ import coil.request.SuccessResult
import dev.chrisbanes.accompanist.coil.AmbientImageLoader

/**
* Replaces all images with a simple black drawable to make testing faster and hermetic.
* Replaces all remote images with a simple black drawable to make testing faster and hermetic.
*/
@OptIn(ExperimentalCoilApi::class)
@Composable
Expand Down
19 changes: 19 additions & 0 deletions Owl/app/src/debug/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
Copyright 2020 The Android Open Source Project

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.
-->
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
<application>
<activity android:name="androidx.activity.ComponentActivity" />
</application>
</manifest>
1 change: 0 additions & 1 deletion Owl/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name="androidx.activity.ComponentActivity" />
</application>

</manifest>
2 changes: 1 addition & 1 deletion Owl/app/src/main/java/com/example/owl/ui/NavGraph.kt
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ import com.example.owl.ui.courses.Courses
import com.example.owl.ui.onboarding.Onboarding

/**
* Destinations used in the main screen ([OwlApp]).
* Destinations used in the ([OwlApp]).
*/
object MainDestinations {
const val ONBOARDING_ROUTE = "onboarding"
Expand Down