-
Notifications
You must be signed in to change notification settings - Fork 18
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
Allow passing arguments to render_submit
in submit_form
#54
Comments
Hi @dabaer thanks for opening this issue. I'm currently making changes to PhoenixTest so it automatically includes all hidden fields and other defaults (e.g. a default Would that ☝️ solve your issue without you having to break out of PhoenixTest? If it doesn't, I have been considering how to best offer an escape hatch so you can drop in to LiveView when you want. My guess for now would be to do something like this: session
|> visit("/")
|> # ... do other phoenix test things
|> in_live_view(fn view ->
view
|> element("#some-hook")
|> render_hook(%{params_from_js: "hello world"})
end)
|> assert_has(text: "hello world") I like that since it is a full escape hatch (instead of patching What do you think? In the meantime, the escape hatch you're using is okay. It's technically private API, but I don't know how much it'll change (just be warned in case it breaks at some point in a weird way). If you keep using that escape hatch, I might do it like this so that you keep more of whatever is in the test "creates new work order with valid params", %{session: session} do
truck = insert(:truck)
params = params_for(:work_order, truck: truck)
session
|> visit(~p"/service_work_order")
|> click_link("span.visible a", "New")
|> then(fn session ->
{:ok, view, _} =
session.view
|> form("#work-order-form")
|> render_submit(work_order: params)
|> follow_redirect(session.conn)
%{ session | view: view}
end)
|> assert_has("span", "Truck #{truck.unit_no}")
|> click_link("a[data-title='Audit']", "Audit")
|> assert_has("td", "create")
|> assert_has("td", params.complaint)
end |
A hands-off option for working with hidden fields would be a fantastic option, though I'm not familiar enough with how For other cases an official escape hatch is also a great idea! I don't actually use the escape hatch I outlined anymore, as I use the commit I linked as the dep in my project and specify the hidden fields as the third argument (though it's not as nice as the first idea you mentioned). Using I look forward to the changes you are implementing and will try them out! As far as this issue is concerned, I believe either of the options you mentioned would negate an actual change to |
Hello again, I have a component like LiveSelect that uses JavaScript to tickle a hidden input, which provides the Magic™️.
I see there was a discussion about the issue in #37 but this seems like a nice thing to have in PhoenixTest itself.
Perhaps we could add an optional fourth argument to
submit_form
? My workaround thus far has been:but breaking in and out of PhoenixTest like this feels naughty.
Here is a POC: dabaer@f745cfe
And the much cleaner test 🎊
What do you think? Also, I wasn't quite sure how to go about presenting this to the DeadView side of things (or if it's even needed there), so the option is black-holed for now.
The text was updated successfully, but these errors were encountered: