compose-destinations icon indicating copy to clipboard operation
compose-destinations copied to clipboard

Feature request: Allow generation of SavedStateHandle from NavArgs for testing

Open JWvanV opened this issue 1 year ago • 3 comments

In our current implementation (without destinations) we test our ViewModels constructing with a SavedStateHandle from a specific navArg in the following way:

val viewModel = XViewModel(
    savedStateHandle = FragmentXArgs(...).toSavedStateHandle()
)

the .toSavedStateHandle() method is generated by the Google navigation library.

I bet there is a similar method being generated under the hood for this project, so it would be great if we could also use it for creating an initial SavedStateHandle to be used in our tests.

Is this already on the roadmap? Or is it already implemented but I couldn't find it?

JWvanV avatar Jan 05 '24 13:01 JWvanV

Hi @JWvanV !

We discussed this here too: https://github.com/raamcosta/compose-destinations/issues/344

I believe hilt recently added changes to improve assisted injection, so injecting the arguments class directly may be easier now.

That said, I will investigate what would take to do this and report my findings here. Thanks for reporting! 🙏

raamcosta avatar Jan 05 '24 14:01 raamcosta

Good news: implemented this today for v2.

V2 is already delayed considering I wanted to release it Q4 last year, but hopefully it will be Q1 this year instead 🤞

raamcosta avatar Jan 06 '24 00:01 raamcosta

Awesome!! Really looking forward to V2. I also have a suggestion of the result recipient lambda, but I'll create a new issue for that :)

JWvanV avatar Jan 06 '24 06:01 JWvanV