)
+ refute html =~ ~s(
This is a flash message.)
end
+
+ test "renders a flash message with close button" do
+ html =
+ render_component(fn assigns ->
+ ~H"""
+ <.torch_flash flash_type="error" message="Error occurred." />
+ """
+ end)
+
+ assert html =~ ~s(
Error occurred.)
+ assert html =~ ~s()
+ end
end
describe "translate_error/1" do
@@ -155,5 +288,11 @@ defmodule Torch.ComponentTest do
translated = Component.translate_errors(errors, :username)
assert translated == ["can't be blank"]
end
+
+ test "returns empty list when field has no errors" do
+ errors = [username: {"can't be blank", []}, email: {"is invalid", []}]
+ translated = Component.translate_errors(errors, :password)
+ assert translated == []
+ end
end
end
diff --git a/test/torch/config_test.exs b/test/torch/config_test.exs
new file mode 100644
index 00000000..872c3db9
--- /dev/null
+++ b/test/torch/config_test.exs
@@ -0,0 +1,69 @@
+defmodule Torch.ConfigTest do
+ use ExUnit.Case, async: true
+
+ describe "otp_app/0" do
+ test "returns the configured otp_app" do
+ # Save the original value
+ original_value = Application.get_env(:torch, :otp_app)
+
+ # Set a test value
+ Application.put_env(:torch, :otp_app, :test_app)
+ assert Torch.Config.otp_app() == :test_app
+
+ # Restore the original value
+ if original_value do
+ Application.put_env(:torch, :otp_app, original_value)
+ else
+ Application.delete_env(:torch, :otp_app)
+ end
+ end
+
+ test "returns nil when otp_app is not configured" do
+ # Save the original value
+ original_value = Application.get_env(:torch, :otp_app)
+
+ # Delete the config
+ Application.delete_env(:torch, :otp_app)
+ assert Torch.Config.otp_app() == nil
+
+ # Restore the original value
+ if original_value do
+ Application.put_env(:torch, :otp_app, original_value)
+ end
+ end
+ end
+
+ describe "i18n_backend/0" do
+ test "returns the configured i18n_backend" do
+ # Save the original value
+ original_value = Application.get_env(:torch, :i18n_backend)
+
+ # Set a test value
+ test_backend = Module.concat(["Test", "I18n", "Backend"])
+ Application.put_env(:torch, :i18n_backend, test_backend)
+ assert Torch.Config.i18n_backend() == test_backend
+
+ # Restore the original value
+ if original_value do
+ Application.put_env(:torch, :i18n_backend, original_value)
+ else
+ Application.delete_env(:torch, :i18n_backend)
+ end
+ end
+
+ test "returns default backend when i18n_backend is not configured" do
+ # Save the original value
+ original_value = Application.get_env(:torch, :i18n_backend)
+
+ # Delete the config
+ Application.delete_env(:torch, :i18n_backend)
+ assert Torch.Config.i18n_backend() == Torch.I18n.Backend
+
+ # Restore the original value
+ if original_value do
+ Application.put_env(:torch, :i18n_backend, original_value)
+ end
+ end
+ end
+end
+
From 695bb1e09272ffae096e6504bfffb881722dcdbe Mon Sep 17 00:00:00 2001
From: "codegen-sh[bot]" <131295404+codegen-sh[bot]@users.noreply.github.com>
Date: Thu, 14 Aug 2025 15:42:59 +0000
Subject: [PATCH 2/2] Fix code style issues: remove trailing whitespace and
extra blank lines
---
test/torch/component_test.exs | 26 +++++++++++++-------------
test/torch/config_test.exs | 1 -
2 files changed, 13 insertions(+), 14 deletions(-)
diff --git a/test/torch/component_test.exs b/test/torch/component_test.exs
index 30af6627..16c05e78 100644
--- a/test/torch/component_test.exs
+++ b/test/torch/component_test.exs
@@ -77,7 +77,7 @@ defmodule Torch.ComponentTest do
assert html =~ ~s(can't be blank)
end
-
+
test "renders a string input type" do
html =
render_component(fn assigns ->
@@ -89,7 +89,7 @@ defmodule Torch.ComponentTest do
assert html =~ ~s(\n Username\n)
end
-
+
test "renders a number input type" do
html =
render_component(fn assigns ->
@@ -101,7 +101,7 @@ defmodule Torch.ComponentTest do
assert html =~ ~s(\n Age\n)
end
-
+
test "renders a date input type" do
html =
render_component(fn assigns ->
@@ -113,7 +113,7 @@ defmodule Torch.ComponentTest do
assert html =~ ~s(\n Birthday\n)
end
-
+
test "renders with custom id" do
html =
render_component(fn assigns ->
@@ -124,7 +124,7 @@ defmodule Torch.ComponentTest do
assert html =~ ~s( %{
@@ -132,10 +132,10 @@ defmodule Torch.ComponentTest do
"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 ->
@@ -151,17 +151,17 @@ defmodule Torch.ComponentTest do
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 ->
@@ -225,7 +225,7 @@ defmodule Torch.ComponentTest do
assert html =~ ~s(
Information message)
assert html =~ ~s(
Error message)
end
-
+
test "renders empty flash messages" do
html =
render_component(
@@ -256,7 +256,7 @@ defmodule Torch.ComponentTest do
assert html =~ ~s(
This is a flash message.)
end
-
+
test "renders a flash message with close button" do
html =
render_component(fn assigns ->
@@ -288,7 +288,7 @@ defmodule Torch.ComponentTest do
translated = Component.translate_errors(errors, :username)
assert translated == ["can't be blank"]
end
-
+
test "returns empty list when field has no errors" do
errors = [username: {"can't be blank", []}, email: {"is invalid", []}]
translated = Component.translate_errors(errors, :password)
diff --git a/test/torch/config_test.exs b/test/torch/config_test.exs
index 872c3db9..c218cf2e 100644
--- a/test/torch/config_test.exs
+++ b/test/torch/config_test.exs
@@ -66,4 +66,3 @@ defmodule Torch.ConfigTest do
end
end
end
-