Testing LiveView form with phx_trigger_action

I’m curious how folks are testing LiveView forms that use phx_trigger_action?

Here’s where its mentioned in the docs: Form bindings — Phoenix LiveView v0.15.4

I have a registration form that I’m validating with LiveView and then submitting to a regular controller action over HTTP.

Once phx-trigger-action is true, LiveView disconnects and then submits the form.

Any idea on how to test that the form actually gets posted?

Calling render_submit/2 returns the rendered HTML which I can test to ensure that there are no changeset errors, but I’m at a loss on how to test that it actually posts.

Here’s my form:

<%= f = form_for @changeset, Routes.user_registration_path(@socket, :create),
  id: "post-form",
  phx_change: "validate",
  phx_submit: "register",
  phx_trigger_action: @trigger_submit %>

  <%= label f, :email %>
  <%= email_input f, :email, required: true, phx_debounce: "blur" %>
  <%= error_tag f, :email %>

  <%= label f, :password %>
  <%= password_input f, :password,
    required: true,
    value: input_value(f, :password),
    phx_debounce: "blur" %>
  <%= error_tag f, :password %>

  <div>
    <%= submit "Register", phx_disable_with: "Registering..." %>
  </div>
</form>

And the corresponding event handlers:

  @impl true
  def handle_event("validate", %{"user" => user_params}, socket) do
    changeset =
      %User{}
      |> Accounts.change_user_registration(user_params)
      |> Map.put(:action, :validate)

    {:noreply, assign(socket, changeset: changeset, changes_from_session: nil)}
  end

  def handle_event("register", %{"user" => user_params}, socket) do
    %User{}
    |> Accounts.change_user_registration(user_params)
    |> Map.put(:action, :validate)
    |> case do
      %{valid?: true} = changeset ->
        {:noreply, assign(socket, changeset: changeset, trigger_submit: true)}

      %{valid?: false} = changeset ->
        {:noreply, assign(socket, changeset: changeset, trigger_submit: false)}
    end
  end

And the test so far:

    test "registers new user", %{conn: conn} do
      {:ok, new_live, html} = live(conn, Routes.user_registration_new_path(conn, :new))

      assert html =~ "<h1>Register</h1>"
      assert html =~ "Log in</a>"
      assert html =~ "Register</a>"

      assert new_live
             |> form("#post-form", user: @invalid_attrs)
             |> render_submit() =~ "can&#39;t be blank"

      refute new_live
             |> form("#post-form", user: @create_attrs)
             |> render_submit() =~ "invalid-feedback"
    end