diff --git a/test/petal/field_test.exs b/test/petal/field_test.exs index c47c707..751b1ac 100644 --- a/test/petal/field_test.exs +++ b/test/petal/field_test.exs @@ -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: [