Liveview testing, testing multiple actions

Is there a way of manually triggering events from a liveview test?

I basically want to test a user doing a sequence of actions, eg Pressing a button, to open a form, then inputting a value in that form.

I can test a button press with render_click() on the element, but then it returns html and not a view.

How can i do the click and get back a view?

In testing, the view is stateful/mutable, so you can do something like this:

{:ok, view, _html} = live(conn, "/path")

view |> element("#open-form-button") |> render_click

view |> form("#my-form", %{foo: %{bar: "baz"}}) |> render_submit

assert render(view) =~ "form was submitted!"
5 Likes

wow I had no idea it was stateful, that is incredibly useful!

Many thanks!

3 Likes

Jeez, exactly the same misunderstanding for me :sweat_smile: Thanks !

1 Like

And here is brief explanation why is that view mutable: Is the test LiveView immutable or not?

3 Likes