tapickell

tapickell

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. :face_holding_back_tears:
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.

First Post!

nwai

nwai

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.

Where Next? Top

Trending in Questions Top

RSP87
I’m working on a project that simulates the bumbl example in the programming phoenix book. It acts almost like an email client. We have a...
New
nseaSeb
Hello, I know there is an approach for handling lists that allows for optimized traversal, but I can’t recall the specific method (somet...
New
RemyXRenard
I’m seeing that a list inside a Kino.DataTable will be interpreted as a charlist, even if the Kino.configure() is set to charlists: :as_l...
New
velrest
So my question is quite simple and i have found no conclusive answer on forum, google or AI. Should we use :erlang.float for Integer to ...
New
brecabral
Documentation While reading the Scoped Routes section, I noticed that the documentation currently refers to a problem without explainin...
New
samoloth
Hi, I’ve just set up an application with ash_authentication. There is only magic link strategy for now, so there is no confirmation add o...
New
FlyingNoodle
If a change or preparation module uses Ash.Changeset.get_argument/2 or Ash.Query.get_argument/2 (or any of the other get_argument functio...
New

Other Trending Topics Top

mudasobwa
I am happy to introduce the very α version of the new programming language compiled to BEAM. Welcome Cure. It has literally three kille...
New
marciok
Hi there! We created Gust: A task orchestrator inspired by Airflow. For those who have never heard about Aiflow, it’s a Python-based wor...
New
jimsynz
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
Dmk
Xamal is a deployment tool for Elixir apps that deploys native releases to bare metal servers over SSH. It’s a port of GitHub - basecamp/...
New
netoum
Corex is an accessible, unstyled UI component library for Phoenix that integrates Zag.js state machines using Vanilla JavaScript and Live...
New
webofbits
With AI doing more of the implementation work, I’ve been wondering how much coding I should deliberately keep doing myself. My main conc...
#ai
New

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews