adds tests
This commit is contained in:
parent
a132383d81
commit
418b42d35a
4 changed files with 199 additions and 0 deletions
|
|
@ -84,5 +84,23 @@ defmodule MvWeb.Layouts.NavbarTest do
|
|||
# Check for correct logout path
|
||||
assert html =~ ~s(href="/sign-out")
|
||||
end
|
||||
|
||||
test "Settings link navigates to global settings page", %{conn: conn} do
|
||||
user = create_test_user(%{email: "test@example.com"})
|
||||
conn = conn_with_oidc_user(conn, user)
|
||||
|
||||
html =
|
||||
render_component(&MvWeb.Layouts.Navbar.navbar/1, %{
|
||||
current_user: user
|
||||
})
|
||||
|
||||
# Check that Settings link exists and points to /settings
|
||||
assert html =~ "Settings"
|
||||
assert html =~ ~s(href="/settings") || html =~ ~s(navigate="/settings")
|
||||
|
||||
# Verify the link actually works by navigating to it
|
||||
{:ok, _view, settings_html} = live(conn, ~p"/settings")
|
||||
assert settings_html =~ "Vereinsdaten"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
67
test/mv_web/live/global_settings_live_test.exs
Normal file
67
test/mv_web/live/global_settings_live_test.exs
Normal file
|
|
@ -0,0 +1,67 @@
|
|||
defmodule MvWeb.GlobalSettingsLiveTest do
|
||||
use MvWeb.ConnCase, async: true
|
||||
import Phoenix.LiveViewTest
|
||||
alias Mv.Membership
|
||||
|
||||
describe "Global Settings LiveView" 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 the global settings page", %{conn: conn} do
|
||||
{:ok, view, html} = live(conn, ~p"/settings")
|
||||
|
||||
assert html =~ "Vereinsdaten"
|
||||
assert html =~ "Settings"
|
||||
end
|
||||
|
||||
test "displays current club name", %{conn: conn} do
|
||||
# Set initial club name
|
||||
{:ok, settings} = Membership.get_settings()
|
||||
Membership.update_settings!(settings, %{club_name: "Test Club"})
|
||||
|
||||
{:ok, _view, html} = live(conn, ~p"/settings")
|
||||
|
||||
assert html =~ "Test Club"
|
||||
end
|
||||
|
||||
test "can update club name via form", %{conn: conn} do
|
||||
{:ok, view, _html} = live(conn, ~p"/settings")
|
||||
|
||||
# Submit form with new club name
|
||||
assert view
|
||||
|> form("#settings-form", %{setting: %{club_name: "Updated Club Name"}})
|
||||
|> render_submit()
|
||||
|
||||
# Check for success message
|
||||
assert render(view) =~ "Settings updated successfully"
|
||||
assert render(view) =~ "Updated Club Name"
|
||||
end
|
||||
|
||||
test "shows error when club_name is empty", %{conn: conn} do
|
||||
{:ok, view, _html} = live(conn, ~p"/settings")
|
||||
|
||||
# Submit form with empty club name
|
||||
html =
|
||||
view
|
||||
|> form("#settings-form", %{setting: %{club_name: ""}})
|
||||
|> render_submit()
|
||||
|
||||
assert html =~ "must be present"
|
||||
end
|
||||
|
||||
test "shows error when club_name is missing", %{conn: conn} do
|
||||
{:ok, view, _html} = live(conn, ~p"/settings")
|
||||
|
||||
# Submit form without club_name
|
||||
html =
|
||||
view
|
||||
|> form("#settings-form", %{setting: %{}})
|
||||
|> render_submit()
|
||||
|
||||
assert html =~ "must be present"
|
||||
end
|
||||
end
|
||||
end
|
||||
Loading…
Add table
Add a link
Reference in a new issue