Skip to content

Commit a328379

Browse files
committed
Test unedited form_field
1 parent b380722 commit a328379

File tree

1 file changed

+62
-0
lines changed

1 file changed

+62
-0
lines changed

test/petal/form_test.exs

+62
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,68 @@ defmodule PetalComponents.FormTest do
228228
assert html =~ "too long"
229229
end
230230

231+
test "Unedited form_field with error does not show errors" do
232+
assigns = %{}
233+
234+
html =
235+
rendered_to_string(~H"""
236+
<.form
237+
:let={f}
238+
as={:user}
239+
for={
240+
%Ecto.Changeset{
241+
action: :update,
242+
data: %{password: ""},
243+
errors: [
244+
password: {"can't be blank", [validation: :required]}
245+
],
246+
# Simulate user only interacted with email field
247+
params: %{
248+
"_unused_password" => ""
249+
}
250+
}
251+
}
252+
>
253+
<.form_field type="password_input" form={f} field={:password} />
254+
</.form>
255+
""")
256+
257+
# Password field (unused) should not show error
258+
refute html =~ "has-error"
259+
refute html =~ "can&#39;t be blank"
260+
end
261+
262+
test "Edited form_field with error shows errors" do
263+
assigns = %{}
264+
265+
html =
266+
rendered_to_string(~H"""
267+
<.form
268+
:let={f}
269+
as={:user}
270+
for={
271+
%Ecto.Changeset{
272+
action: :update,
273+
data: %{password: ""},
274+
errors: [
275+
password: {"can't be blank", [validation: :required]}
276+
],
277+
# Simulate user only interacted with email field
278+
params: %{
279+
"password" => ""
280+
}
281+
}
282+
}
283+
>
284+
<.form_field type="password_input" form={f} field={:password} />
285+
</.form>
286+
""")
287+
288+
# Password field (unused) should not show error
289+
assert html =~ "has-error"
290+
assert html =~ "can&#39;t be blank"
291+
end
292+
231293
test "form_help_text" do
232294
assigns = %{}
233295

0 commit comments

Comments
 (0)