From 071dd38489449871fd3477e05ee4a70f1a910491 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Sat, 28 Oct 2023 10:57:07 +0200 Subject: [PATCH] More tests --- test/phoenix_html/form_test.exs | 49 +++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) 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