Skip to content

Commit 8dd4d5a

Browse files
committed
update tests.
1 parent 163f115 commit 8dd4d5a

File tree

2 files changed

+17
-3
lines changed

2 files changed

+17
-3
lines changed

lib/kaffy/resource_form.ex

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,14 @@ defmodule Kaffy.ResourceForm do
182182
values = Enum.map(values, &to_string/1)
183183
value = Map.get(data, field, nil)
184184

185-
select(form, field, values, [class: "custom-select", value: value] ++ opts)
185+
# NOTE enum_options preserves the order of enum defined in the schema
186+
enum_options =
187+
Enum.map(values, fn v ->
188+
capitalized = String.capitalize(v)
189+
{capitalized, v}
190+
end)
191+
192+
select(form, field, enum_options, [class: "custom-select", value: value] ++ opts)
186193

187194
{:parameterized, Ecto.Enum, %{mappings: mappings, on_cast: on_cast}} ->
188195
value = Map.get(data, field, nil)
@@ -202,7 +209,14 @@ defmodule Kaffy.ResourceForm do
202209
values = Enum.map(values, &to_string/1)
203210
value = Map.get(data, field, nil)
204211

205-
multiple_select(form, field, values, [value: value] ++ opts)
212+
# NOTE enum_options preserves the order of enum defined in the schema
213+
enum_options =
214+
Enum.map(values, fn v ->
215+
capitalized = String.capitalize(v)
216+
{capitalized, v}
217+
end)
218+
219+
multiple_select(form, field, enum_options, [value: value] ++ opts)
206220

207221
{:array, {:parameterized, Ecto.Enum, %{mappings: mappings, on_cast: on_cast}}} ->
208222
value = Map.get(data, field, nil)

test/kaffy/resource_form_test.exs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ defmodule Kaffy.ResourceFormTest do
5151
html = render_field(:travel_type)
5252
assert html =~ ~r/dummy\[travel_type]/
5353
assert html =~ ~r/^<select/
54-
assert html =~ ~r/<option value="undisclosed">Other<\/option>/
54+
assert html =~ ~r/<option value="other">Other<\/option>/
5555
end
5656

5757
test "render enum array field" do

0 commit comments

Comments
 (0)