test: add tests for smtp mailer config

This commit is contained in:
Simon 2026-03-11 09:18:37 +01:00
parent f53a3ce3cc
commit c4135308e6
Signed by: simon
GPG key ID: 40E7A58C4AA1EDB2
9 changed files with 440 additions and 0 deletions

View file

@ -65,4 +65,52 @@ defmodule MvWeb.GlobalSettingsLiveTest do
assert html =~ "must be present"
end
end
describe "SMTP / E-Mail section" do
setup %{conn: conn} do
user = create_test_user(%{email: "admin@example.com"})
conn = conn_with_oidc_user(conn, user)
{:ok, conn: conn, user: user}
end
test "renders SMTP section with host/port fields and test email area", %{conn: conn} do
{:ok, _view, html} = live(conn, ~p"/settings")
# Section title (Gettext key: SMTP or E-Mail per concept)
assert html =~ "SMTP" or html =~ "E-Mail"
end
test "shows Send test email button when SMTP is configured", %{conn: conn} do
{:ok, view, _html} = live(conn, ~p"/settings")
# When Mv.Config.smtp_configured?() is true, button and recipient input should be present
# In test env SMTP is typically not configured; we only assert the section exists
html = render(view)
assert html =~ "SMTP" or html =~ "E-Mail"
end
test "send test email with valid address shows success or error result", %{conn: conn} do
{:ok, view, _html} = live(conn, ~p"/settings")
# If test email UI exists: fill recipient, click button, assert result area updates
# Uses data-testid or button text "Send test email" / "Test email"
if has_element?(view, "[data-testid='smtp-test-email-form']") do
view
|> element("[data-testid='smtp-test-email-input']")
|> render_change(%{"to_email" => "test@example.com"})
view
|> element("[data-testid='smtp-send-test-email']")
|> render_click()
# Result is either success or error message
assert has_element?(view, "[data-testid='smtp-test-result']")
else
# Section not yet implemented: just ensure page still renders
assert render(view) =~ "Settings"
end
end
test "shows warning when SMTP is not configured in production", %{conn: conn} do
# Concept: in prod, show warning "SMTP is not configured. Transactional emails..."
# In test we only check that the section exists; warning visibility is env-dependent
{:ok, view, html} = live(conn, ~p"/settings")
assert html =~ "SMTP" or html =~ "E-Mail" or html =~ "Settings"
end
end
end

View file

@ -39,6 +39,8 @@ defmodule MvWeb.JoinLiveTest do
test "submit with valid allowlist data creates one JoinRequest and shows success copy", %{
conn: conn
} do
# Re-apply allowlist so this test is robust when run in parallel with others (Settings singleton).
enable_join_form_for_test(%{})
count_before = count_join_requests()
{:ok, view, _html} = live(conn, "/join")