New override to InMemoryToastService to include toast details
jennifer-lebantino opened this issue · 2 comments
Is your feature request related to a problem? Please describe.
When testing custom toast components that use BlazoredToast, not enough information is passed to the InMemoryToastService. This limits test capability as there's not enough detail available (i.e. toast level, message).
Describe the solution you'd like
It would be great to add an override that takes in whole components in the InMemoryToastService so we can access this data.
Describe alternatives you've considered
Currently I can only test that some toast message does appear which defaults to an 'info' level and the message is null.
Additional context
N/A
Instead of adding a new override that takes in whole components to the InMemoryToastService, a nullable ToastParameters field could be added to the InMemoryToast class, which is then populated when ToastParameters is passed as a parameter to the ShowToast<TComponent>
overrides.
The advantage of going for this approach would be that consumers of the package would not need to use a new override to get this functionality, meaning they do not need to update the code in the client to test the parameters which are set.
For assertions, assuming the custom component has a status, the value could be verified by doing the below:
Assert.Equal(ToastLevel.Info, toastService.Toasts.Single().ToastParameters!.TryGet<ToastLevel>(nameof(Status));
Eventually, a wrapper around the above could be nice to add, so that the assertions are more readable.
If this approach is okay, I can get a PR created for this.
This looks like a great approach, Theo. I especially like the fact developers already using the library won't need to change anything to take advantage of this.
I agree that perhaps an extension method to make accessing a property on a component would be a great addition. But please feel free to submit a PR when you're ready.