-
Notifications
You must be signed in to change notification settings - Fork 5.3k
[Owl] Migrates navigation to navigation-compose #287
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
Merged
JoseAlcerreca
merged 12 commits into
android:dev_alpha08
from
JoseAlcerreca:dev_owl_navigation_alpha08
Nov 24, 2020
Merged
Changes from 1 commit
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
474dc79
[Owl] Migrates to navigation-compose
JoseAlcerreca eb9c08b
Adressing comments
JoseAlcerreca 88db781
Syntax
JoseAlcerreca 67b00c8
Navigation cleanup, safe arguments
JoseAlcerreca 2cb58c2
[Owl] Initial nav tests
JoseAlcerreca 73657aa
Test cleanup
JoseAlcerreca 8dbf05b
Merge remote-tracking branch 'github/dev_alpha08' into dev_owl_naviga…
JoseAlcerreca 97ed758
Reverts navigation abstraction and fixes tests
JoseAlcerreca 3bc7c1f
Enables tests for Owl in GHA
JoseAlcerreca d984804
Adressing review comments
JoseAlcerreca 0ea81d8
Spotless ~_~
JoseAlcerreca b3aa476
Replaces popBackStack with navigateUp
JoseAlcerreca File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
[Owl] Initial nav tests
Change-Id: I6fb4a08ee99b96438dc28d25b91abd32f9e0dbc6
- Loading branch information
commit 2cb58c28ca4a078601b04b2c576bf980967997d6
There are no files selected for viewing
112 changes: 112 additions & 0 deletions
112
Owl/app/src/androidTest/java/com/example/owl/ui/NavigationTest.kt
This file contains hidden or 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,112 @@ | ||
| /* | ||
| * 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 | ||
| * | ||
| * https://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 com.example.owl.ui | ||
|
|
||
| import androidx.activity.ComponentActivity | ||
| import androidx.compose.runtime.Providers | ||
| import androidx.test.platform.app.InstrumentationRegistry | ||
| import androidx.ui.test.createAndroidComposeRule | ||
| import androidx.ui.test.onNodeWithLabel | ||
| import androidx.ui.test.onNodeWithSubstring | ||
| import androidx.ui.test.performClick | ||
| import com.example.owl.R | ||
| import com.example.owl.model.courses | ||
| import com.example.owl.ui.fakes.ProvideTestImageLoader | ||
| import com.example.owl.ui.utils.AmbientBackDispatcher | ||
| import org.junit.Rule | ||
| import org.junit.Test | ||
|
|
||
| /** | ||
| * Checks that the navigation flows in the app are correct. | ||
| */ | ||
| class NavigationTest { | ||
|
|
||
| @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) { | ||
| ProvideTestImageLoader { | ||
| if (startDestination == null) { | ||
| NavGraph() | ||
| } else { | ||
| NavGraph(startDestination) | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
||
| @Test | ||
| fun firstScreenIsOnboarding() { | ||
| // When the app is open | ||
| startActivity() | ||
| // The first screen should be the onboarding screen. | ||
| // Assert that the FAB label for the onboarding screen exists: | ||
| composeTestRule.onNodeWithLabel(getOnboardingFabLabel()).assertExists() | ||
| } | ||
|
|
||
| @Test | ||
| fun onboardingToCourses() { | ||
| // Given the app in the onboarding screen | ||
| startActivity() | ||
|
|
||
| // Navigate to the next screen by clicking on the FAB | ||
| val fabLabel = getOnboardingFabLabel() | ||
| composeTestRule.onNodeWithLabel(fabLabel).performClick() | ||
|
|
||
| // The first course should be shown | ||
| composeTestRule.onNodeWithSubstring(courses.first().name).assertExists() | ||
| } | ||
|
|
||
| @Test | ||
| fun coursesToDetail() { | ||
| // Given the app in the courses screen | ||
| startActivity(MainDestinations.Courses.route) | ||
|
|
||
| // Navigate to the first course | ||
| composeTestRule.onNodeWithSubstring(courses.first().name).performClick() | ||
|
|
||
| // Assert navigated to the course details | ||
| composeTestRule.onNodeWithSubstring(getCourseDesc().take(15)).assertExists() | ||
| } | ||
|
|
||
| @Test | ||
| fun coursesToDetailAndBack() { | ||
| coursesToDetail() | ||
| composeTestRule.runOnUiThread { | ||
| activity.onBackPressed() | ||
| } | ||
|
|
||
| // The first course should be shown | ||
| composeTestRule.onNodeWithSubstring(courses.first().name).assertExists() | ||
| } | ||
|
|
||
| private fun getOnboardingFabLabel(): String { | ||
| return InstrumentationRegistry.getInstrumentation().targetContext.resources | ||
| .getString(R.string.continue_to_courses) | ||
| } | ||
| private fun getCourseDesc(): String { | ||
| return InstrumentationRegistry.getInstrumentation().targetContext.resources | ||
| .getString(R.string.course_desc) | ||
| } | ||
| } | ||
78 changes: 78 additions & 0 deletions
78
Owl/app/src/androidTest/java/com/example/owl/ui/fakes/ProvideTestImageLoader.kt
This file contains hidden or 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,78 @@ | ||
| /* | ||
| * 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 | ||
| * | ||
| * https://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 com.example.owl.ui.fakes | ||
|
|
||
| import android.graphics.Color | ||
| import android.graphics.drawable.ColorDrawable | ||
| import androidx.compose.runtime.Composable | ||
| import androidx.compose.runtime.Providers | ||
| import coil.ImageLoader | ||
| import coil.annotation.ExperimentalCoilApi | ||
| import coil.bitmap.BitmapPool | ||
| import coil.decode.DataSource | ||
| import coil.memory.MemoryCache | ||
| import coil.request.DefaultRequestOptions | ||
| import coil.request.Disposable | ||
| import coil.request.ImageRequest | ||
| import coil.request.ImageResult | ||
| import coil.request.SuccessResult | ||
| import com.example.owl.ui.utils.AmbientImageLoader | ||
|
|
||
| @OptIn(ExperimentalCoilApi::class) | ||
| @Composable | ||
| fun ProvideTestImageLoader(content: @Composable () -> Unit) { | ||
JoseAlcerreca marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| // From https://coil-kt.github.io/coil/image_loaders/ | ||
| val loader = object : ImageLoader { | ||
| private val drawable = ColorDrawable(Color.BLACK) | ||
|
|
||
| private val disposable = object : Disposable { | ||
| override val isDisposed get() = true | ||
| override fun dispose() {} | ||
| override suspend fun await() {} | ||
| } | ||
|
|
||
| override val bitmapPool: BitmapPool = BitmapPool(0) | ||
|
|
||
| override val defaults: DefaultRequestOptions = DefaultRequestOptions() | ||
| override val memoryCache: MemoryCache | ||
| get() = TODO("Not yet implemented") | ||
|
|
||
| override fun enqueue(request: ImageRequest): Disposable { | ||
| // Always call onStart before onSuccess. | ||
| request.target?.onStart(drawable) | ||
| request.target?.onSuccess(drawable) | ||
| return disposable | ||
| } | ||
|
|
||
| override suspend fun execute(request: ImageRequest): ImageResult { | ||
| return SuccessResult( | ||
| drawable = drawable, | ||
| request = request, | ||
| metadata = ImageResult.Metadata( | ||
| memoryCacheKey = MemoryCache.Key(""), | ||
| isSampled = false, | ||
| dataSource = DataSource.MEMORY_CACHE, | ||
| isPlaceholderMemoryCacheKeyPresent = false | ||
| ) | ||
| ) | ||
| } | ||
|
|
||
| override fun shutdown() { } | ||
| } | ||
| Providers(AmbientImageLoader provides loader, children = content) | ||
| } | ||
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.