Skip to content

Commit b380722

Browse files
committed
Adjust tests for forms V1
1 parent 97e6119 commit b380722

File tree

4 files changed

+57
-38
lines changed

4 files changed

+57
-38
lines changed

assets/default.css

+4
Original file line numberDiff line numberDiff line change
@@ -2521,6 +2521,10 @@ label.has-error {
25212521
@apply !text-danger-900 dark:!text-danger-200;
25222522
}
25232523

2524+
span.has-error {
2525+
@apply !text-danger-900 dark:!text-danger-200;
2526+
}
2527+
25242528
textarea.has-error,
25252529
input.has-error:not(:checked),
25262530
select.has-error {

lib/petal_components/form.ex

+45-12
Original file line numberDiff line numberDiff line change
@@ -14,20 +14,23 @@ defmodule PetalComponents.Form do
1414
Deprecated in favor of field.ex and input.ex, which use the new `%Phoenix.HTML.FormField{}` struct.
1515
"""
1616

17-
attr(:form, :any, default: nil, doc: "")
18-
attr(:field, :atom, default: nil, doc: "")
19-
attr(:label, :string, default: nil, doc: "labels your field")
20-
attr(:class, :any, doc: "CSS classes to add to your label")
21-
slot(:inner_block, required: false)
22-
attr(:rest, :global, include: ~w(for))
17+
attr :form, :any, default: nil, doc: ""
18+
attr :field, :atom, default: nil, doc: ""
19+
attr :label, :string, default: nil, doc: "labels your field"
20+
attr :class, :any, doc: "CSS classes to add to your label"
21+
22+
attr :compound, :boolean, default: false, doc: "Avoid using label/for for compound inputs"
23+
24+
slot :inner_block, required: false
25+
attr :rest, :global, include: ~w(for)
2326

2427
def form_label(assigns) do
2528
assigns =
2629
assigns
2730
|> assign(:classes, label_classes(assigns))
2831

2932
~H"""
30-
<%= if @form && @field do %>
33+
<%= if @form && @field && !@compound do %>
3134
<%= Form.label @form, @field, [class: @classes] ++ Map.to_list(@rest) do %>
3235
{render_slot(@inner_block) || @label || Form.humanize(@field)}
3336
<% end %>
@@ -136,10 +139,22 @@ defmodule PetalComponents.Form do
136139
</div>
137140
</label>
138141
<% "checkbox_group" -> %>
139-
<.form_label form={@form} field={@field} label={@label} class={@label_class} />
142+
<.form_label
143+
form={@form}
144+
field={@field}
145+
label={@label}
146+
class={@label_class}
147+
compound={true}
148+
/>
140149
<.checkbox_group form={@form} field={@field} {@rest} />
141150
<% "radio_group" -> %>
142-
<.form_label form={@form} field={@field} label={@label} class={@label_class} />
151+
<.form_label
152+
form={@form}
153+
field={@field}
154+
label={@label}
155+
class={@label_class}
156+
compound={true}
157+
/>
143158
<.radio_group form={@form} field={@field} {@rest} />
144159
<% "text_input" -> %>
145160
<.form_label form={@form} field={@field} label={@label} class={@label_class} />
@@ -166,16 +181,34 @@ defmodule PetalComponents.Form do
166181
<.form_label form={@form} field={@field} label={@label} class={@label_class} />
167182
<.time_input form={@form} field={@field} {@rest} />
168183
<% "time_select" -> %>
169-
<.form_label form={@form} field={@field} label={@label} class={@label_class} />
184+
<.form_label
185+
form={@form}
186+
field={@field}
187+
label={@label}
188+
class={@label_class}
189+
compound={true}
190+
/>
170191
<.time_select form={@form} field={@field} {@rest} />
171192
<% "datetime_select" -> %>
172-
<.form_label form={@form} field={@field} label={@label} class={@label_class} />
193+
<.form_label
194+
form={@form}
195+
field={@field}
196+
label={@label}
197+
class={@label_class}
198+
compound={true}
199+
/>
173200
<.datetime_select form={@form} field={@field} {@rest} />
174201
<% "datetime_local_input" -> %>
175202
<.form_label form={@form} field={@field} label={@label} class={@label_class} />
176203
<.datetime_local_input form={@form} field={@field} {@rest} />
177204
<% "date_select" -> %>
178-
<.form_label form={@form} field={@field} label={@label} class={@label_class} />
205+
<.form_label
206+
form={@form}
207+
field={@field}
208+
label={@label}
209+
class={@label_class}
210+
compound={true}
211+
/>
179212
<.date_select form={@form} field={@field} {@rest} />
180213
<% "date_input" -> %>
181214
<.form_label form={@form} field={@field} label={@label} class={@label_class} />

mix.lock

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
"file_system": {:hex, :file_system, "1.0.1", "79e8ceaddb0416f8b8cd02a0127bdbababe7bf4a23d2a395b983c1f8b3f73edd", [:mix], [], "hexpm", "4414d1f38863ddf9120720cd976fce5bdde8e91d8283353f0e31850fa89feb9e"},
1414
"floki": {:hex, :floki, "0.36.3", "1102f93b16a55bc5383b85ae3ec470f82dee056eaeff9195e8afdf0ef2a43c30", [:mix], [], "hexpm", "fe0158bff509e407735f6d40b3ee0d7deb47f3f3ee7c6c182ad28599f9f6b27a"},
1515
"hackney": {:hex, :hackney, "1.20.1", "8d97aec62ddddd757d128bfd1df6c5861093419f8f7a4223823537bad5d064e2", [:rebar3], [{:certifi, "~> 2.12.0", [hex: :certifi, repo: "hexpm", optional: false]}, {:idna, "~> 6.1.0", [hex: :idna, repo: "hexpm", optional: false]}, {:metrics, "~> 1.0.0", [hex: :metrics, repo: "hexpm", optional: false]}, {:mimerl, "~> 1.1", [hex: :mimerl, repo: "hexpm", optional: false]}, {:parse_trans, "3.4.1", [hex: :parse_trans, repo: "hexpm", optional: false]}, {:ssl_verify_fun, "~> 1.1.0", [hex: :ssl_verify_fun, repo: "hexpm", optional: false]}, {:unicode_util_compat, "~> 0.7.0", [hex: :unicode_util_compat, repo: "hexpm", optional: false]}], "hexpm", "fe9094e5f1a2a2c0a7d10918fee36bfec0ec2a979994cff8cfe8058cd9af38e3"},
16-
"heroicons": {:git, "https://github.com/tailwindlabs/heroicons.git", "ad0ad1f6d51bd64dcd67e363d2b2833a8de25154", [tag: "v2.1.5", sparse: "optimized", depth: 1]},
16+
"heroicons": {:git, "https://github.com/tailwindlabs/heroicons.git", "ad0ad1f6d51bd64dcd67e363d2b2833a8de25154", [tag: "v2.1.5", sparse: "optimized"]},
1717
"hpax": {:hex, :hpax, "1.0.0", "28dcf54509fe2152a3d040e4e3df5b265dcb6cb532029ecbacf4ce52caea3fd2", [:mix], [], "hexpm", "7f1314731d711e2ca5fdc7fd361296593fc2542570b3105595bb0bc6d0fad601"},
1818
"httpoison": {:hex, :httpoison, "2.2.1", "87b7ed6d95db0389f7df02779644171d7319d319178f6680438167d7b69b1f3d", [:mix], [{:hackney, "~> 1.17", [hex: :hackney, repo: "hexpm", optional: false]}], "hexpm", "51364e6d2f429d80e14fe4b5f8e39719cacd03eb3f9a9286e61e216feac2d2df"},
1919
"idna": {:hex, :idna, "6.1.1", "8a63070e9f7d0c62eb9d9fcb360a7de382448200fbbd1b106cc96d3d8099df8d", [:rebar3], [{:unicode_util_compat, "~> 0.7.0", [hex: :unicode_util_compat, repo: "hexpm", optional: false]}], "hexpm", "92376eb7894412ed19ac475e4a86f7b413c1b9fbb5bd16dccd57934157944cea"},

test/petal/form_test.exs

+7-25
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ defmodule PetalComponents.FormTest do
1717
assert html =~ "user[name]"
1818
assert html =~ "itemid"
1919
assert html =~ "something"
20-
assert html =~ "phx-feedback-for"
2120
refute html =~ " disabled "
2221
assert html =~ "pc-text-input"
2322
assert html =~ "!w-max"
@@ -56,7 +55,6 @@ defmodule PetalComponents.FormTest do
5655
assert html =~ "user[description]"
5756
assert html =~ "itemid"
5857
assert html =~ "placeholder"
59-
assert html =~ "phx-feedback-for"
6058
assert html =~ "dummy text"
6159
end
6260

@@ -75,7 +73,6 @@ defmodule PetalComponents.FormTest do
7573
assert html =~ "itemid"
7674
assert html =~ "<option"
7775
assert html =~ "admin"
78-
assert html =~ "phx-feedback-for"
7976
assert html =~ "Admin"
8077
end
8178

@@ -91,7 +88,6 @@ defmodule PetalComponents.FormTest do
9188

9289
assert html =~ "checkbox"
9390
assert html =~ "user[read_terms]"
94-
assert html =~ "phx-feedback-for"
9591
assert html =~ "itemid"
9692
end
9793

@@ -111,7 +107,6 @@ defmodule PetalComponents.FormTest do
111107
assert html =~ "user_roles_write"
112108
assert html =~ "user[roles][]"
113109
assert html =~ "Read"
114-
assert html =~ "phx-feedback-for"
115110
assert html =~ "Write"
116111
refute html =~ "checked"
117112

@@ -143,7 +138,6 @@ defmodule PetalComponents.FormTest do
143138

144139
assert html =~ "checkbox"
145140
assert html =~ "user[read_terms]"
146-
assert html =~ "phx-feedback-for"
147141
assert html =~ "itemid"
148142
assert html =~ "sr-only"
149143
assert html =~ "peer"
@@ -163,7 +157,6 @@ defmodule PetalComponents.FormTest do
163157
assert html =~ "user[eye_color]"
164158
assert html =~ "green"
165159
assert html =~ "itemid"
166-
assert html =~ "phx-feedback-for"
167160
end
168161

169162
test "form_label" do
@@ -178,7 +171,6 @@ defmodule PetalComponents.FormTest do
178171

179172
assert html =~ "label"
180173
assert html =~ "Name"
181-
assert html =~ "phx-feedback-for"
182174
assert html =~ "text-pink-500"
183175

184176
html =
@@ -222,7 +214,8 @@ defmodule PetalComponents.FormTest do
222214
errors: [
223215
name: {"can't be blank", [validation: :required]},
224216
name: {"too long", [validation: :required]}
225-
]
217+
],
218+
params: %{"name" => ""}
226219
}
227220
}
228221
>
@@ -231,7 +224,6 @@ defmodule PetalComponents.FormTest do
231224
""")
232225

233226
assert html =~ "pc-form-field-error"
234-
assert html =~ "phx-feedback-for"
235227
assert html =~ "blank"
236228
assert html =~ "too long"
237229
end
@@ -284,7 +276,8 @@ defmodule PetalComponents.FormTest do
284276
errors: [
285277
name: {"can't be blank", [validation: :required]},
286278
name: {"too long", [validation: :required]}
287-
]
279+
],
280+
params: %{"name" => ""}
288281
}
289282
}
290283
>
@@ -305,7 +298,7 @@ defmodule PetalComponents.FormTest do
305298
assert html =~ "John"
306299
assert html =~ "too long"
307300
assert html =~ "blank"
308-
assert html =~ "<div class=\"wrapper-test\" phx-feedback-for=\"user[name]\">"
301+
assert html =~ "<div class=\"wrapper-test\">"
309302
assert html =~ "Help!"
310303
end
311304

@@ -337,7 +330,8 @@ defmodule PetalComponents.FormTest do
337330
errors: [
338331
name: {"can't be blank", [validation: :required]},
339332
name: {"too long", [validation: :required]}
340-
]
333+
],
334+
params: %{"name" => ""}
341335
}
342336
}
343337
>
@@ -532,7 +526,6 @@ defmodule PetalComponents.FormTest do
532526
assert html =~ "user[name]"
533527
assert html =~ "itemid"
534528
assert html =~ "something"
535-
assert html =~ "phx-feedback-for"
536529
end
537530

538531
test "email_input" do
@@ -550,7 +543,6 @@ defmodule PetalComponents.FormTest do
550543
assert html =~ "user[name]"
551544
assert html =~ "itemid"
552545
assert html =~ "something"
553-
assert html =~ "phx-feedback-for"
554546
end
555547

556548
test "password_input" do
@@ -568,7 +560,6 @@ defmodule PetalComponents.FormTest do
568560
assert html =~ "user[name]"
569561
assert html =~ "itemid"
570562
assert html =~ "something"
571-
assert html =~ "phx-feedback-for"
572563
end
573564

574565
test "search_input" do
@@ -586,7 +577,6 @@ defmodule PetalComponents.FormTest do
586577
assert html =~ "user[name]"
587578
assert html =~ "itemid"
588579
assert html =~ "something"
589-
assert html =~ "phx-feedback-for"
590580
end
591581

592582
test "telephone_input" do
@@ -604,7 +594,6 @@ defmodule PetalComponents.FormTest do
604594
assert html =~ "user[name]"
605595
assert html =~ "itemid"
606596
assert html =~ "something"
607-
assert html =~ "phx-feedback-for"
608597
end
609598

610599
test "url_input" do
@@ -622,7 +611,6 @@ defmodule PetalComponents.FormTest do
622611
assert html =~ "user[name]"
623612
assert html =~ "itemid"
624613
assert html =~ "something"
625-
assert html =~ "phx-feedback-for"
626614
end
627615

628616
test "time_input" do
@@ -640,7 +628,6 @@ defmodule PetalComponents.FormTest do
640628
assert html =~ "user[name]"
641629
assert html =~ "itemid"
642630
assert html =~ "something"
643-
assert html =~ "phx-feedback-for"
644631
end
645632

646633
test "time_select" do
@@ -672,7 +659,6 @@ defmodule PetalComponents.FormTest do
672659
assert html =~ "user[name]"
673660
assert html =~ "itemid"
674661
assert html =~ "something"
675-
assert html =~ "phx-feedback-for"
676662
end
677663

678664
test "datetime_select" do
@@ -718,7 +704,6 @@ defmodule PetalComponents.FormTest do
718704
assert html =~ "user[name]"
719705
assert html =~ "itemid"
720706
assert html =~ "something"
721-
assert html =~ "phx-feedback-for"
722707
end
723708

724709
test "color_input" do
@@ -736,7 +721,6 @@ defmodule PetalComponents.FormTest do
736721
assert html =~ "user[name]"
737722
assert html =~ "itemid"
738723
assert html =~ "something"
739-
assert html =~ "phx-feedback-for"
740724
end
741725

742726
test "file_input" do
@@ -755,7 +739,6 @@ defmodule PetalComponents.FormTest do
755739
assert html =~ "itemid"
756740
assert html =~ "something"
757741
assert html =~ "pc-file-input"
758-
assert html =~ "phx-feedback-for"
759742
end
760743

761744
test "range_input" do
@@ -773,7 +756,6 @@ defmodule PetalComponents.FormTest do
773756
assert html =~ "user[name]"
774757
assert html =~ "itemid"
775758
assert html =~ "something"
776-
assert html =~ "phx-feedback-for"
777759
end
778760

779761
test "hidden_input" do

0 commit comments

Comments
 (0)