Hi all!
I am trying to write a test for a liveview. Within this liveview, the user is supposed to be able to select shifts from a calendar and be redirected to a normal view where he/she can print the shifts, after having clicked a print button.
I started to write the following test:
test "Redirects to a view where all selected shifts can be printed, after user has clicked the print button",
%{conn: conn, token: token, shift: shift} do
{:ok, view, _html} = conn |> live(Routes.live_path(conn, ShiftApplicationLive, token))
params = [shift_ids: [shift.id]]
redirect_path = Routes.shift_path(conn, :print_shifts, token, params)
render_click(view, :select_shift, %{"shift-id" => shift.id})
assert_redirect(view, ^redirect_path, fn ->
assert render_click(view, :print_shifts)
end)
end
However, I always got the error:
No message matching {^ref, {:redirect, ^topic, %{to: ^redirect_path}}} after 100ms.
[... truncated error ...]
code: assert_redirect(view, ^redirect_path, fn ->
stacktrace:
lib/shift_application_web/live/shift_application_live_test.exs:289: (test)
The problems seems to be with this part of my test:
assert_redirect(view, ^redirect_path, fn ->
assert render_click(view, :print_shifts)
end)
When I execute the render_click(view, :print_shifts)
, I got the following data back:
{:error,
{:redirect,
%{
to: "/shift-application/contract/tlOSOpL2E_5a7yrxr4NeWgdOJbG5mz2WcuD7ClCBvdeBw1iKHcfv0Gb20b51rKBYAAAAAF4h6rd7ImF1ZnRyYWdzbnVtbWVyIjoiNTAwMDAifQ%253D%253D/print_shifts?schift_ids[]=8eec-4547-a3c8-7a6174051021"
}}}
-
Is it normal that the
renders_click
method returns an:error
? -
Why is there different level of encodings? The URL encoded by
redirect_path = Routes.shift_path(conn, :print_shifts, token, params)
is encoded one time, while the URL returned by therenders_click
is encoded two times; so if I try to compare them, they’ll always be different, unless I decode them withURI.decode()
.