feat: Added InputFile setup#700
feat: Added InputFile setup#700linkdotnet merged 16 commits intobUnit-dev:mainfrom linkdotnet:feature/input-file
Conversation
|
A few thoughts.
|
|
Perfect thank you very much for that valuable input ;) That helps a lot. I will update the PR and let you know once I have a presentable version. |
|
Hey @egil. Took some time today to work on that topic. Feel like I opened too much things and want to finish one by one those tasks. The structure and everything is like it should be. I only have to satisfy some warnings in the test. (Edit: Fixed as well) I basically incorporated all the feedback you had. Let me know your thoughts. The only current downside is that (this is artificial and I don’t thing we will have users running into that), users can’t mock the internal InputFile call anymore so that it throws an exception (which they shouldn’t do in the first place). |
|
One open point on my todo-list is documentation. Where do you think this would fit the best? |
egil
left a comment
There was a problem hiding this comment.
Good work on this.
- A few suggestions and questions related to the code.
- Yes, documentation is needed, otherwise your efforts will be wasted here, most wont notice it. A small page under "Test doubles" is my best suggestion with the current documentation struture.
Co-authored-by: Egil Hansen <[email protected]>
|
Added all the feedback plus documentation. As always thanks for the nice feedback. |
Co-authored-by: Egil Hansen <[email protected]>
Co-authored-by: Egil Hansen <[email protected]>
Co-authored-by: Egil Hansen <[email protected]>
|
I do think we covered now everything. Thanks again |
Indeed. Good work! |
* feat: Added InputFile setup Co-authored-by: Egil Hansen <[email protected]>
InputFile - Easy setup of uploaded files
Description
This PR relates directly to #317 (closes #317) and should give an easy setup for
InputFile. In its current state there is no easy way of setting up anInputFile. This PR introduces two methods which makes it possible.AddInputFileSupportto setup the JavaScript partUploadFilesAsyncto configure the files which will be returned byInputFileand also directly invoking theOnChangeevent.Implementation
The implementation is straight forward. We just introduce a bunch of new types which are test doubles of the ones from the framework itself. I decided to go with an extension for
IRenderedComponent<InputFile>because users can have multipleInputFiles in their code and they are used to callcut.Find("...");anyway.Usage
A typical test would look like this:
What is open? / discussion
Here are some points I want to discuss:
AddInputFileSupportwe will get JavaScript Interop errors that the call was not set up in strict mode. I didn't want to mock that call (Blazor._internal.InputFile.init) by default. But we could. Via default we setup the JS call and let the user opt-out via an extension method. That might make more sense, because on average the user does not want to setupInputFilestuff on their own.InputFileContentis alwaysbyte[]. I played around with two versions:stringandbyte[]and went withbyte[]because it makes our code easier and pushes the responsibility to the caller instead of us. Text / encoding can be very hard. And especially when people want to upload images or so,byte[]seems the appropriate way.InputFiletest in any of our test assemblies because that type was introduced withnet5.0. Either we build one from scratch viaBuildRenderTree(RenderTreeBuilder builder). If you have any tips, let me know.Alternatives
I played around with the idea to replace or a given
InputFilevia ourComponentFactorieswith a test double. We might make this work as well, but it doesn't seem that much nice when it comes down to implementation details.Info
This PR is only draft atm and meant as a base for discussions. Once we are aligned on the API design, xmldoc and tests will follow.