Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change form fields from hidden to text for liveview testing ease of use #50

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

efleming
Copy link

@efleming efleming commented Dec 14, 2023

I can't use the normal liveview testing functions when using this library because of the hidden inputs. I would have to modify all my tests to populate the form field in a different way when using live_select. If we make the form fields type text and add a hidden class to them, then the tests will work without modification.

Example, I have a form that is using the live_select component for an org_id on a user:

In current library state with hidden form fields:

create_attrs = %{
  org_id: 1,
  first_name: "John",
  last_name: "Doe",
  email: "john.doe@email.com",
  phone_number: "1234567890"
}

assert index_live
       |> form("#user-form", user: Map.delete(create_attrs, :org_id))
       |> render_submit(%{user: %{org_id: create_attrs[:org_id]}})

Using my PR, we can keep the tests the way they come using phoenix generators:

create_attrs = %{
  org_id: 1,
  first_name: "John",
  last_name: "Doe",
  email: "john.doe@email.com",
  phone_number: "1234567890"
}

assert index_live
       |> form("#user-form", user: create_attrs)
       |> render_submit()

@maxmarcon
Copy link
Owner

Hi and thanks for giving some thought to this. Having to account for a hidden input is in fact not ideal when writing tests, I agree.

However, your solution only works for folks who use tailwindcss and have a hidden class defined. For all the others the text input will be visible, which we don't want.

One could use inline css to hide the input, but inline css is forbidden under certain CSP settings.

I'm open to suggestions on alternative ways to make this work. So far, I haven't thought much about it to be honest.

Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants