Status Update
Comments
do...@google.com <do...@google.com> #2
Filling in the data
, action
, and mimeType
fields of the Intent
for any usages of NavDeepLinkRequest
makes sense to me.
jb...@google.com <jb...@google.com>
ap...@google.com <ap...@google.com> #3
Branch: androidx-main
commit 6ac4bffb0f35827a19f761599bb642dbd98e146a
Author: Jeremy Woods <jbwoods@google.com>
Date: Wed Mar 24 12:10:03 2021
Add intent when navigating with NavDeepLinkRequest
When you navigate with a NavDeepLinkRequest, we should also fill an
intent with the data, action, and type with the values from the
NavDeepLinkRequest, and pass that intent in the arguments of the
resulting destination using KEY_DEEP_LINK_INTENT. That way, the info can
be accessed from the resulting destination.
RelNote: "When navigating using a NavDeepLinkRequest, you can now
access the uri, action, and mimetype in the resulting destination by
getting the intent from arguments via KEY_DEEP_LINK_INTENT."
Bug: 181521877
Test: Adjusted tests in NavControllerTest
Change-Id: Ide575ab7123522da7816c1b219f444173dbfab8d
M navigation/navigation-runtime/src/androidTest/java/androidx/navigation/NavControllerTest.kt
M navigation/navigation-runtime/src/main/java/androidx/navigation/NavController.kt
ap...@google.com <ap...@google.com> #4
This has been fixed internally and will be part of the Navigation 2.3.5
release (via 2.4.0-alpha01
).
ap...@google.com <ap...@google.com> #5
Branch: androidx-main
commit b333eceb8ade397c6418f8a6ecc14f24e88c484f
Author: Clara Fok <clarafok@google.com>
Date: Fri Jun 14 12:33:38 2024
Refactor SavedStateHandleFactory
Previous implementation delegates to NavDeepLink operations which has dependencies on Uri, thus limiting this API to androidTests.
Refactor away from NavDeepLink and instead manually replicate the steps that an argument value would go through.
However, since bundle is deeply integrated into the parsing of arguments by NavType, the non-instrumented test will require robolectric in order to properly support bundle.
Test: ./gradlew navigation:navigation-testing:test
Bug: 340966212
Relnote: "SavedStateHandleFactory test api can now be used in non-android tests but will require robolectric to support argument parsing with bundles."
Change-Id: I76cdc4b40474680dbdb58e6b8a6451f0e228f9b1
M navigation/navigation-common/src/main/java/androidx/navigation/serialization/RouteEncoder.kt
M navigation/navigation-common/src/main/java/androidx/navigation/serialization/RouteSerializer.kt
M navigation/navigation-testing/build.gradle
M navigation/navigation-testing/src/main/java/androidx/navigation/testing/SavedStateHandleFactory.kt
M navigation/navigation-testing/src/test/java/androidx/navigation/testing/TestSavedStateHandleFactory.kt
cl...@google.com <cl...@google.com> #6
Fixed internally and available in navigation-2.8.0-rc01
.
Note that Android Bundle is deeply integrated into the parsing of arguments by NavType and cannot be removed, hence non-instrumented tests will require robolectric in order to properly support bundles.
ap...@google.com <ap...@google.com> #7
Branch: androidx-main
commit df6f97f72af9fa61365b44af75905ddd9039bb26
Author: Clara Fok <clarafok@google.com>
Date: Tue Jun 18 10:47:42 2024
Update SavedStateHandleFactory kdoc
Clarify that android Bundles cannot be avoided at this stage and non-instrumented tests need to be run with robolectric.
Test: TH
Bug: 340966212
Relnote: "To use SavedStateHandle test factory in non-instrumented tests, robolectric is required. This is because android Bundle is necessarily integrated into the parsing of nav arguments."
Change-Id: I8047c1a2d2dff4cb2efd0452407287738f2ce157
M navigation/navigation-testing/src/main/java/androidx/navigation/testing/SavedStateHandleFactory.kt
do...@google.com <do...@google.com> #8
Thanks for doing this. Whilst this is technically an improvement, the fact remains that if you want to test a ViewModel which accepts navigation arguments you now need to introduce a dependency on Robolectric which is a fairly major blocker for many developers. Robolectric slows down tests and reduces test fidelity.
Is there no way of removing the Bundle
dependency? Or perhaps moving Bundle
into AndroidX?
pr...@google.com <pr...@google.com> #9
The following release(s) address this bug.It is possible this bug has only been partially addressed:
androidx.navigation:navigation-common:2.8.0-beta04
androidx.navigation:navigation-testing:2.8.0-beta04
do...@google.com <do...@google.com> #10
I created a follow up bug to track the Android dependency forcing unit->instrumented tests for ViewModels.
Description
Component used: Navigation Version used: 2.8.0-beta01 Devices/Android versions reproduced on: all
aosp/3073537 introduced a new API for creating a
SavedStateHandle
using an object for the route parameter e.g.SavedStateHandle(route = MyDestination)
.Internally, this constructor relies on
android.net.Uri
which means that you can only call it from an instrumented test, not a unit test.This is undesirable since one of the use cases for this API is to be able to unit test ViewModels by passing them a
SavedStateHandle
containing a route.Example:https://github.com/android/nowinandroid/pull/1413/files#diff-bbcd9ff3a5be72096922a84b290125441e34d8183492cd27536e343a903579a8R57