germsvel / phoenix_test

PhoenixTest provides a unified way of writing feature tests -- regardless of whether you're testing LiveView pages or static (non-LiveView) pages.
https://hex.pm/packages/phoenix_test
MIT License
170 stars 22 forks source link

Build form data using Plug.Conn.Query (remove DeepMerge) #94

Closed ftes closed 3 months ago

ftes commented 4 months ago

Fixes #77 Replaces #79, #90, #93

Goal

Ensure same form handling semantics as Phoenix controllers and LiveView.

Details

Track form data as a flat list of {name, value} tuples. This can be read straight from the DOM and needs no further conversions. Example:

form_data = [
  {"user[name]", "Ada"},
  {"user[subscribe][]", "email"},
  {"user[subscribe][]", "push"}
]

Defer transforming that flat list into a nested data structure: When submitting form or evaluating other LiveLive phx-* callbacks.

Use Plug.Conn.Query.decode/4 to transform flat list into nested data structure. Reason: Phoenix Controllers and LiveView do the same (see https://github.com/germsvel/phoenix_test/issues/77#issuecomment-2123962071).

soundmonster commented 3 months ago

This PR does sound like a good idea to me. I tried supporting multiple inputs with ending with [] using DeepMerge, and being able to also uncheck a checkbox from a group made the whole thing super complex. I tried backporting the tests from my branch on yours and they don't go through, but I guess I'll be able to get it to work on top.