Skip to content

Commit

Permalink
Test unedited field
Browse files Browse the repository at this point in the history
  • Loading branch information
mitkins committed Dec 10, 2024
1 parent a328379 commit b401be6
Showing 1 changed file with 30 additions and 1 deletion.
31 changes: 30 additions & 1 deletion test/petal/field_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,36 @@ defmodule PetalComponents.FieldTest do
assert html =~ "label-class"
end

test "field as text with field errors" do
test "Unedited field as text with field errors" do
assigns = %{
field: %Phoenix.HTML.FormField{
errors: [
{"can't be blank", [validation: :required]},
{"too short!", [validation: :length]}
],
name: "name",
value: "",
field: :name,
id: "name",
form: %Phoenix.HTML.Form{
params: %{"_unused_name" => ""}
}
}
}

html =
rendered_to_string(~H"""
<.field field={@field} />
""")

assert html =~ "name"
assert html =~ "Name"
refute html =~ "pc-form-field-error"
refute html =~ html_escape("can't be blank")
refute html =~ html_escape("too short!")
end

test "Edited field as text with field errors" do
assigns = %{
field: %Phoenix.HTML.FormField{
errors: [
Expand Down

0 comments on commit b401be6

Please sign in to comment.