diff --git a/test/torch/component_test.exs b/test/torch/component_test.exs index dab4d861..16c05e78 100644 --- a/test/torch/component_test.exs +++ b/test/torch/component_test.exs @@ -77,6 +77,109 @@ defmodule Torch.ComponentTest do assert html =~ ~s(can't be blank) end + + test "renders a string input type" do + html = + render_component(fn assigns -> + ~H""" + <.torch_input type="string" name="username" value="test_user" label="Username" /> + """ + end) + + assert html =~ ~s(\n Username\n) + end + + test "renders a number input type" do + html = + render_component(fn assigns -> + ~H""" + <.torch_input type="number" name="age" value="25" label="Age" /> + """ + end) + + assert html =~ ~s(\n Age\n) + end + + test "renders a date input type" do + html = + render_component(fn assigns -> + ~H""" + <.torch_input type="date" name="birthday" value="2023-01-01" label="Birthday" /> + """ + end) + + assert html =~ ~s(\n Birthday\n) + end + + test "renders with custom id" do + html = + render_component(fn assigns -> + ~H""" + <.torch_input type="text" name="username" id="custom-id" value="test_user" /> + """ + end) + + assert html =~ ~s( %{ + "name" => "John Doe", + "email" => "john@example.com" + } + } + + form = Phoenix.Component.to_form(form_data, as: :user) + field = Phoenix.HTML.FormField.to_form_field(form, :name) + + html = + render_component( + fn assigns -> + ~H""" + <.torch_input field={@field} type="text" label="Name" /> + """ + end, + %{ + field: field + } + ) + + assert html =~ ~s(\n Name\n) + end + + test "renders with form field and multiple flag" do + form_data = %{ + "user" => %{ + "roles" => ["admin", "editor"] + } + } + + form = Phoenix.Component.to_form(form_data, as: :user) + field = Phoenix.HTML.FormField.to_form_field(form, :roles) + + html = + render_component( + fn assigns -> + ~H""" + <.torch_input field={@field} type="select" multiple={true} options={@options} label="Roles" /> + """ + end, + %{ + field: field, + options: [{"Admin", "admin"}, {"Editor", "editor"}, {"Viewer", "viewer"}] + } + ) + + assert html =~ ~s(