Unless phx-click has a valid JS command, we don't really want to handle it as part of the Field.phx_click?, Button.phx_click?, or Select.phx_click? actions.
So, in this commit, we parse the phx-click attribute. When it's a JS command, we check to see if the value is push or navigate.
Why do we do this? Why not let LiveViewTest handle it?
LiveViewTest already throws an error when a phx-click has a JS command that doesn't include a push or navigate. So, why do this?
Because PhoenixTest automatically handles phx-clicks.
When an element is inside a form AND it has a phx-click that doesn't have a push or navigate (e.g. JS.dispatch/1), we need to ignore the element. We don't want to raise because it's technically valid code.
Something to note: PhoenixTest doesn't currently handle a form element AND a valid phx-click event at the same time. That is, if a form has a phx-change attribute and a checkbox has a phx-click attribute with an event or a JS.push, only one of those events (the phx-change OR the phx-click) will make it to the server. In production LiveView, both events get sent. So, that's something we want to handle, but it is not covered in this commit.
Closes #122
What changed?
Unless
phx-click
has a valid JS command, we don't really want to handle it as part of theField.phx_click?
,Button.phx_click?
, orSelect.phx_click?
actions.So, in this commit, we parse the
phx-click
attribute. When it's a JS command, we check to see if the value ispush
ornavigate
.Why do we do this? Why not let LiveViewTest handle it?
LiveViewTest already throws an error when a
phx-click
has a JS command that doesn't include apush
ornavigate
. So, why do this?Because PhoenixTest automatically handles
phx-clicks
.When an element is inside a form AND it has a
phx-click
that doesn't have apush
ornavigate
(e.g.JS.dispatch/1
), we need to ignore the element. We don't want to raise because it's technically valid code.Something to note: PhoenixTest doesn't currently handle a form element AND a valid
phx-click
event at the same time. That is, if a form has aphx-change
attribute and a checkbox has aphx-click
attribute with an event or aJS.push
, only one of those events (thephx-change
OR thephx-click
) will make it to the server. In production LiveView, both events get sent. So, that's something we want to handle, but it is not covered in this commit.