How to test `push_navigate` coming from `handle_info`?

Hello,

I don’t have any form or events to click or submit to follow_redirect . But i had a handle_info similarly like this:

def handle_info({FormComponent, {:ok, company_info}}, socket) do
    socket =
      socket
      |> put_flash(:info, "Company Details saved successfully!")
      |> push_navigate(to: "/onboarding/subscription")

    {:noreply, socket}
  end

How can i test this? In my test case, I am sending the fake event using send, but i want to assert the flash message and successful redirect.

 {:ok, live_view, html} = live(conn, live_path)

      send(
        live_view.pid,
        {FormComponent, {:ok, company_information}}
      )

# TODO: Assert Flash and redirect

Can someone help me how to assert?

Thank you

What happens if you put your live_view through assert_redirect or assert_redirected?

asserted_redirected works. Thank you :grinning_face_with_smiling_eyes:

1 Like