boydm / phoenix_integration

Lightweight server side integration test tools for Phoenix
Apache License 2.0
219 stars 25 forks source link

Consider buttons with a name and value as possible input for a form on follow_form #58

Open mrnovalles opened 3 years ago

mrnovalles commented 3 years ago

I have a use case where form has multiple buttons each of them pointing at the same controller action but each with a separate name and value:

<button class="btn btn-sm btn-danger" id="mark-released" name="action[is_released]" type="submit" value="true">Release</button>
<button class="btn btn-sm btn-danger" id="mark-released" name="action[is_deployed]" type="submit" value="true">Deployed</button>

In my tests, with the current implementation of follow_form I can never get the value of the button to be set as:

follow_form(conn, %{
  action: %{is_deployed: "true"},
  metadata: %{"#{version0.id}": "true", "#{version1.id}": "true"},
},

We currently use v0.7.0 but if this is of interest I'd be willing to submit a patch to 0.7.0 and higher versions. From a quick look at it in 0.7.0, it requires adding some lines in request.ex

  defp get_form_data(form) do
    %{}
    |> build_form_by_type(form, "input")
    |> build_form_by_type(form, "textarea")
    |> build_form_by_type(form, "select")
    |> build_form_by_type(form, "button")
  end

...

  defp get_input_value(input, "button") do
    Floki.attribute(input, "value")
  end

I can see this would be very different for current HEAD, so I wanted to check before jumping into the code currently in master.

boydm commented 2 years ago

@zucaritask I'm open to this. Would want the fix in master tho.