diff --git a/test/phoenix_html/form_test.exs b/test/phoenix_html/form_test.exs index 139ffe8..f772aad 100644 --- a/test/phoenix_html/form_test.exs +++ b/test/phoenix_html/form_test.exs @@ -239,4 +239,53 @@ defmodule Phoenix.HTML.FormTest do } end end + + describe "options_for_select/2" do + test "simple" do + assert options_for_select(~w(value novalue), "novalue") |> safe_to_string() == + ~s() <> + ~s() + + assert options_for_select(~w(value novalue), "novalue") |> safe_to_string() == + ~s() <> + ~s() + + assert options_for_select( + [ + [value: "value", key: "Value", disabled: true], + [value: "novalue", key: "No Value"] + ], + "novalue" + ) + |> safe_to_string() == + ~s() <> + ~s() + + assert options_for_select(~w(value novalue), ["value", "novalue"]) |> safe_to_string() == + ~s() <> + ~s() + end + + test "with groups" do + assert options_for_select([{"foo", ~w(bar baz)}, {"qux", ~w(qux quz)}], "qux") + |> safe_to_string() == + ~s() <> + ~s() <> + ~s() <> + ~s() <> + ~s() <> + ~s() <> + ~s() <> ~s() + + assert options_for_select([{"foo", ~w(bar baz)}, {"qux", ~w(qux quz)}], ["baz", "qux"]) + |> safe_to_string() == + ~s() <> + ~s() <> + ~s() <> + ~s() <> + ~s() <> + ~s() <> + ~s() <> ~s() + end + end end