Running into some issues trying to write good tests for Uploads.
I am using the live_file_input for being able to upload files in a component that is mounted in a Liveview.
read through the example and docs on Uploads. It works great, the drag and drop functionality is super nice.
The only issue I am having is that I am having a hard time testing it to get code coverage.
I am trying to test it in a test on the main liveview that the component is mounted from .
Using the file_input function in the test I am seeing an error with the upload not being allowed.
This is because the allow_upload function is on the component not the liveview.
I tried moving the allow_upload to the parent liveview but that breaks the upload functionality in the component.
I tried testing this at the component level.
We only have a socket in this test, but I did find how to put_entries onto the socket.
This seems to work great for testing that when the event to cancel and to save get called that the correct things happen.
This however is not good for asserting that the HTML has changed on the component when we add an upload.
I have been scouring the interwebs/github looking for examples of something similar.
I see plenty of examples of people using this functionality in a component, which is understandable, it is really cool.
But I do not see anyone writing tests around the component.
Right now I am working on a very hacky thing that probably wont work well, because I am out of ideas.
I really feel like I am either missing something, or maybe that Liveview is missing some functionality around testing something this way.
If anyone has done this or has any suggestions / proposed solutions I would greatly appreciate any feedback.
Had a similar issue when trying to test a component with a live_file_input in it. In my case the following code:
Phoenix.LiveViewTest.render_component(&Component.upload_modal/1, assigns)
Gives rise to (ArgumentError) missing required :upload attribute to <.live_file_input/>
. Adding an :upload
key to the assigns map used for the test did not help.