refactor: remove tests against basic framework functionalities
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
parent
15d328afbf
commit
91f8bb03bc
4 changed files with 524 additions and 454 deletions
|
|
@ -20,23 +20,6 @@ defmodule MvWeb.UserLive.FormTest do
|
|||
assert has_element?(view, "input[name='user[email]']")
|
||||
assert has_element?(view, "input[type='checkbox'][name='set_password']")
|
||||
end
|
||||
|
||||
test "hides password fields initially", %{conn: conn} do
|
||||
{:ok, view, _html} = setup_live_view(conn, "/users/new")
|
||||
|
||||
refute has_element?(view, "input[name='user[password]']")
|
||||
refute has_element?(view, "input[name='user[password_confirmation]']")
|
||||
end
|
||||
|
||||
test "shows password fields when checkbox toggled", %{conn: conn} do
|
||||
{:ok, view, _html} = setup_live_view(conn, "/users/new")
|
||||
|
||||
view |> element("input[name='set_password']") |> render_click()
|
||||
|
||||
assert has_element?(view, "input[name='user[password]']")
|
||||
assert has_element?(view, "input[name='user[password_confirmation]']")
|
||||
assert render(view) =~ "Password requirements"
|
||||
end
|
||||
end
|
||||
|
||||
describe "new user form - creation" do
|
||||
|
|
@ -88,68 +71,6 @@ defmodule MvWeb.UserLive.FormTest do
|
|||
assert to_string(user.email) == "storetest@example.com"
|
||||
assert is_nil(user.hashed_password)
|
||||
end
|
||||
|
||||
test "stores password when provided", %{conn: conn} do
|
||||
{:ok, view, _html} = setup_live_view(conn, "/users/new")
|
||||
|
||||
view |> element("input[name='set_password']") |> render_click()
|
||||
|
||||
view
|
||||
|> form("#user-form",
|
||||
user: %{
|
||||
email: "passwordstoretest@example.com",
|
||||
password: "securepassword123",
|
||||
password_confirmation: "securepassword123"
|
||||
}
|
||||
)
|
||||
|> render_submit()
|
||||
|
||||
system_actor = Mv.Helpers.SystemActor.get_system_actor()
|
||||
|
||||
user =
|
||||
Ash.get!(
|
||||
Mv.Accounts.User,
|
||||
[email: Ash.CiString.new("passwordstoretest@example.com")],
|
||||
domain: Mv.Accounts,
|
||||
actor: system_actor
|
||||
)
|
||||
|
||||
assert user.hashed_password != nil
|
||||
assert String.starts_with?(user.hashed_password, "$2b$")
|
||||
end
|
||||
end
|
||||
|
||||
describe "new user form - validation" do
|
||||
test "shows error for duplicate email", %{conn: conn} do
|
||||
_existing_user = create_test_user(%{email: "existing@example.com"})
|
||||
{:ok, view, _html} = setup_live_view(conn, "/users/new")
|
||||
|
||||
html =
|
||||
view
|
||||
|> form("#user-form", user: %{email: "existing@example.com"})
|
||||
|> render_submit()
|
||||
|
||||
assert html =~ "has already been taken"
|
||||
end
|
||||
|
||||
test "shows error for short password", %{conn: conn} do
|
||||
{:ok, view, _html} = setup_live_view(conn, "/users/new")
|
||||
|
||||
view |> element("input[name='set_password']") |> render_click()
|
||||
|
||||
html =
|
||||
view
|
||||
|> form("#user-form",
|
||||
user: %{
|
||||
email: "test@example.com",
|
||||
password: "123",
|
||||
password_confirmation: "123"
|
||||
}
|
||||
)
|
||||
|> render_submit()
|
||||
|
||||
assert html =~ "length must be greater than or equal to 8"
|
||||
end
|
||||
end
|
||||
|
||||
describe "edit user form - display" do
|
||||
|
|
@ -162,17 +83,6 @@ defmodule MvWeb.UserLive.FormTest do
|
|||
assert has_element?(view, "input[name='user[email]'][value='editme@example.com']")
|
||||
assert html =~ "Check 'Change Password' above to set a new password for this user"
|
||||
end
|
||||
|
||||
test "shows admin password fields when enabled", %{conn: conn} do
|
||||
user = create_test_user(%{email: "editme@example.com"})
|
||||
{:ok, view, _html} = setup_live_view(conn, "/users/#{user.id}/edit")
|
||||
|
||||
view |> element("input[name='set_password']") |> render_click()
|
||||
|
||||
assert has_element?(view, "input[name='user[password]']")
|
||||
refute has_element?(view, "input[name='user[password_confirmation]']")
|
||||
assert render(view) =~ "Admin Note"
|
||||
end
|
||||
end
|
||||
|
||||
describe "edit user form - updates" do
|
||||
|
|
@ -218,79 +128,6 @@ defmodule MvWeb.UserLive.FormTest do
|
|||
end
|
||||
end
|
||||
|
||||
describe "edit user form - validation" do
|
||||
test "shows error for duplicate email", %{conn: conn} do
|
||||
_existing_user = create_test_user(%{email: "taken@example.com"})
|
||||
user_to_edit = create_test_user(%{email: "original@example.com"})
|
||||
{:ok, view, _html} = setup_live_view(conn, "/users/#{user_to_edit.id}/edit")
|
||||
|
||||
html =
|
||||
view
|
||||
|> form("#user-form", user: %{email: "taken@example.com"})
|
||||
|> render_submit()
|
||||
|
||||
assert html =~ "has already been taken"
|
||||
end
|
||||
|
||||
test "shows error for invalid password", %{conn: conn} do
|
||||
user = create_test_user(%{email: "user@example.com"})
|
||||
{:ok, view, _html} = setup_live_view(conn, "/users/#{user.id}/edit")
|
||||
|
||||
view |> element("input[name='set_password']") |> render_click()
|
||||
|
||||
result =
|
||||
view
|
||||
|> form("#user-form",
|
||||
user: %{
|
||||
email: "user@example.com",
|
||||
password: "123"
|
||||
}
|
||||
)
|
||||
|> render_submit()
|
||||
|
||||
case result do
|
||||
{:error, {:live_redirect, %{to: "/users"}}} ->
|
||||
flunk("Expected validation error but form was submitted successfully")
|
||||
|
||||
html when is_binary(html) ->
|
||||
assert html =~ "must have length of at least 8"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe "internationalization" do
|
||||
test "shows German labels", %{conn: conn} do
|
||||
conn = conn_with_oidc_user(conn, %{email: "admin_de@example.com"})
|
||||
conn = Plug.Test.init_test_session(conn, locale: "de")
|
||||
{:ok, _view, html} = live(conn, "/users/new")
|
||||
|
||||
assert html =~ "Neue*r Benutzer*in"
|
||||
assert html =~ "E-Mail"
|
||||
assert html =~ "Passwort setzen"
|
||||
end
|
||||
|
||||
test "shows English labels", %{conn: conn} do
|
||||
conn = conn_with_oidc_user(conn, %{email: "admin_en@example.com"})
|
||||
Gettext.put_locale(MvWeb.Gettext, "en")
|
||||
{:ok, _view, html} = live(conn, "/users/new")
|
||||
|
||||
assert html =~ "New User"
|
||||
assert html =~ "Email"
|
||||
assert html =~ "Set Password"
|
||||
end
|
||||
|
||||
test "shows different labels for edit vs new", %{conn: conn} do
|
||||
user = create_test_user(%{email: "test@example.com"})
|
||||
conn = conn_with_oidc_user(conn, %{email: "admin@example.com"})
|
||||
|
||||
{:ok, _view, new_html} = live(conn, "/users/new")
|
||||
{:ok, _view, edit_html} = live(conn, "/users/#{user.id}/edit")
|
||||
|
||||
assert new_html =~ "Set Password"
|
||||
assert edit_html =~ "Change Password"
|
||||
end
|
||||
end
|
||||
|
||||
describe "member linking - display" do
|
||||
test "shows linked member with unlink button when user has member", %{conn: conn} do
|
||||
system_actor = Mv.Helpers.SystemActor.get_system_actor()
|
||||
|
|
|
|||
|
|
@ -3,26 +3,6 @@ defmodule MvWeb.UserLive.IndexTest do
|
|||
import Phoenix.LiveViewTest
|
||||
|
||||
describe "basic functionality" do
|
||||
test "shows translated title in German", %{conn: conn} do
|
||||
conn = conn_with_oidc_user(conn)
|
||||
conn = Plug.Test.init_test_session(conn, locale: "de")
|
||||
{:ok, _view, html} = live(conn, "/users")
|
||||
assert html =~ "Benutzer*innen auflisten"
|
||||
end
|
||||
|
||||
test "shows translated title in English", %{conn: conn} do
|
||||
conn = conn_with_oidc_user(conn)
|
||||
Gettext.put_locale(MvWeb.Gettext, "en")
|
||||
{:ok, _view, html} = live(conn, "/users")
|
||||
assert html =~ "Listing Users"
|
||||
end
|
||||
|
||||
test "shows New User button", %{conn: conn} do
|
||||
conn = conn_with_oidc_user(conn)
|
||||
{:ok, _view, html} = live(conn, "/users")
|
||||
assert html =~ "New User"
|
||||
end
|
||||
|
||||
test "displays users in a table", %{conn: conn} do
|
||||
# Create test users
|
||||
_user1 = create_test_user(%{email: "alice@example.com", oidc_id: "alice123"})
|
||||
|
|
@ -34,16 +14,6 @@ defmodule MvWeb.UserLive.IndexTest do
|
|||
assert html =~ "alice@example.com"
|
||||
assert html =~ "bob@example.com"
|
||||
end
|
||||
|
||||
test "shows correct action links", %{conn: conn} do
|
||||
user = create_test_user(%{email: "test@example.com"})
|
||||
conn = conn_with_oidc_user(conn)
|
||||
{:ok, _view, html} = live(conn, "/users")
|
||||
|
||||
assert html =~ "Edit"
|
||||
assert html =~ "Delete"
|
||||
assert html =~ ~r/href="[^"]*\/users\/#{user.id}\/edit"/
|
||||
end
|
||||
end
|
||||
|
||||
describe "sorting functionality" do
|
||||
|
|
@ -95,41 +65,6 @@ defmodule MvWeb.UserLive.IndexTest do
|
|||
assert mike_pos < alpha_pos,
|
||||
"mike@example.com should appear before alpha@example.com when sorted desc"
|
||||
end
|
||||
|
||||
test "toggles back to ascending when clicking sort button twice", %{conn: conn} do
|
||||
conn = conn_with_oidc_user(conn)
|
||||
{:ok, view, _html} = live(conn, "/users")
|
||||
|
||||
# Click twice to toggle: asc -> desc -> asc
|
||||
view |> element("button[phx-value-field='email']") |> render_click()
|
||||
html = view |> element("button[phx-value-field='email']") |> render_click()
|
||||
|
||||
# Should be back to ascending
|
||||
assert html =~ "hero-chevron-up"
|
||||
assert html =~ ~s(aria-sort="ascending")
|
||||
|
||||
# Should be back to original ascending order
|
||||
alpha_pos = html |> :binary.match("alpha@example.com") |> elem(0)
|
||||
mike_pos = html |> :binary.match("mike@example.com") |> elem(0)
|
||||
zulu_pos = html |> :binary.match("zulu@example.com") |> elem(0)
|
||||
|
||||
assert alpha_pos < mike_pos, "Should be back to ascending: alpha before mike"
|
||||
assert mike_pos < zulu_pos, "Should be back to ascending: mike before zulu"
|
||||
end
|
||||
|
||||
test "shows sort direction icons", %{conn: conn} do
|
||||
conn = conn_with_oidc_user(conn)
|
||||
{:ok, view, _html} = live(conn, "/users")
|
||||
|
||||
# Initially ascending - should show up arrow
|
||||
html = render(view)
|
||||
assert html =~ "hero-chevron-up"
|
||||
|
||||
# After clicking, should show down arrow
|
||||
view |> element("button[phx-value-field='email']") |> render_click()
|
||||
html = render(view)
|
||||
assert html =~ "hero-chevron-down"
|
||||
end
|
||||
end
|
||||
|
||||
describe "checkbox selection functionality" do
|
||||
|
|
@ -139,134 +74,6 @@ defmodule MvWeb.UserLive.IndexTest do
|
|||
%{users: [user1, user2]}
|
||||
end
|
||||
|
||||
test "shows select all checkbox", %{conn: conn} do
|
||||
conn = conn_with_oidc_user(conn)
|
||||
{:ok, _view, html} = live(conn, "/users")
|
||||
|
||||
assert html =~ ~s(name="select_all")
|
||||
assert html =~ ~s(phx-click="select_all")
|
||||
end
|
||||
|
||||
test "shows individual user checkboxes", %{conn: conn, users: [user1, user2]} do
|
||||
conn = conn_with_oidc_user(conn)
|
||||
{:ok, _view, html} = live(conn, "/users")
|
||||
|
||||
assert html =~ ~s(name="#{user1.id}")
|
||||
assert html =~ ~s(name="#{user2.id}")
|
||||
assert html =~ ~s(phx-click="select_user")
|
||||
end
|
||||
|
||||
test "can select individual users", %{conn: conn, users: [user1, user2]} do
|
||||
conn = conn_with_oidc_user(conn)
|
||||
{:ok, view, _html} = live(conn, "/users")
|
||||
|
||||
# Initially, individual checkboxes should exist but not be checked
|
||||
assert view |> element("input[type='checkbox'][name='#{user1.id}']") |> has_element?()
|
||||
assert view |> element("input[type='checkbox'][name='#{user2.id}']") |> has_element?()
|
||||
|
||||
# Initially, select_all should not be checked (since no individual items are selected)
|
||||
refute view
|
||||
|> element("input[type='checkbox'][name='select_all'][checked]")
|
||||
|> has_element?()
|
||||
|
||||
# Select first user checkbox
|
||||
html = view |> element("input[type='checkbox'][name='#{user1.id}']") |> render_click()
|
||||
|
||||
# The select_all checkbox should still not be checked (not all users selected)
|
||||
refute view
|
||||
|> element("input[type='checkbox'][name='select_all'][checked]")
|
||||
|> has_element?()
|
||||
|
||||
# Page should still function normally
|
||||
assert html =~ "Email"
|
||||
assert html =~ to_string(user1.email)
|
||||
end
|
||||
|
||||
test "can deselect individual users", %{conn: conn, users: [user1, _user2]} do
|
||||
conn = conn_with_oidc_user(conn)
|
||||
{:ok, view, _html} = live(conn, "/users")
|
||||
|
||||
# Select user first
|
||||
view |> element("input[type='checkbox'][name='#{user1.id}']") |> render_click()
|
||||
|
||||
# Then deselect user
|
||||
html = view |> element("input[type='checkbox'][name='#{user1.id}']") |> render_click()
|
||||
|
||||
# Select all should not be checked after deselecting individual user
|
||||
refute view
|
||||
|> element("input[type='checkbox'][name='select_all'][checked]")
|
||||
|> has_element?()
|
||||
|
||||
# Page should still function normally
|
||||
assert html =~ "Email"
|
||||
assert html =~ to_string(user1.email)
|
||||
end
|
||||
|
||||
test "select all functionality selects all users", %{conn: conn, users: [user1, user2]} do
|
||||
conn = conn_with_oidc_user(conn)
|
||||
{:ok, view, _html} = live(conn, "/users")
|
||||
|
||||
# Initially no checkboxes should be checked
|
||||
refute view
|
||||
|> element("input[type='checkbox'][name='select_all'][checked]")
|
||||
|> has_element?()
|
||||
|
||||
refute view
|
||||
|> element("input[type='checkbox'][name='#{user1.id}'][checked]")
|
||||
|> has_element?()
|
||||
|
||||
refute view
|
||||
|> element("input[type='checkbox'][name='#{user2.id}'][checked]")
|
||||
|> has_element?()
|
||||
|
||||
# Click select all
|
||||
html = view |> element("input[type='checkbox'][name='select_all']") |> render_click()
|
||||
|
||||
# After selecting all, the select_all checkbox should be checked
|
||||
assert view
|
||||
|> element("input[type='checkbox'][name='select_all'][checked]")
|
||||
|> has_element?()
|
||||
|
||||
# Page should still function normally and show all users
|
||||
assert html =~ "Email"
|
||||
assert html =~ to_string(user1.email)
|
||||
assert html =~ to_string(user2.email)
|
||||
end
|
||||
|
||||
test "deselect all functionality deselects all users", %{conn: conn, users: [user1, user2]} do
|
||||
conn = conn_with_oidc_user(conn)
|
||||
{:ok, view, _html} = live(conn, "/users")
|
||||
|
||||
# Select all first
|
||||
view |> element("input[type='checkbox'][name='select_all']") |> render_click()
|
||||
|
||||
# Verify that select_all is checked
|
||||
assert view
|
||||
|> element("input[type='checkbox'][name='select_all'][checked]")
|
||||
|> has_element?()
|
||||
|
||||
# Then deselect all
|
||||
html = view |> element("input[type='checkbox'][name='select_all']") |> render_click()
|
||||
|
||||
# After deselecting all, no checkboxes should be checked
|
||||
refute view
|
||||
|> element("input[type='checkbox'][name='select_all'][checked]")
|
||||
|> has_element?()
|
||||
|
||||
refute view
|
||||
|> element("input[type='checkbox'][name='#{user1.id}'][checked]")
|
||||
|> has_element?()
|
||||
|
||||
refute view
|
||||
|> element("input[type='checkbox'][name='#{user2.id}'][checked]")
|
||||
|> has_element?()
|
||||
|
||||
# Page should still function normally
|
||||
assert html =~ "Email"
|
||||
assert html =~ to_string(user1.email)
|
||||
assert html =~ to_string(user2.email)
|
||||
end
|
||||
|
||||
test "select all automatically checks when all individual users are selected", %{
|
||||
conn: conn,
|
||||
users: [user1, user2]
|
||||
|
|
@ -326,56 +133,6 @@ defmodule MvWeb.UserLive.IndexTest do
|
|||
end
|
||||
end
|
||||
|
||||
describe "navigation" do
|
||||
test "clicking on user row navigates to user show page", %{conn: conn} do
|
||||
user = create_test_user(%{email: "navigate@example.com"})
|
||||
conn = conn_with_oidc_user(conn)
|
||||
{:ok, view, _html} = live(conn, "/users")
|
||||
|
||||
# This test would need to check row click behavior
|
||||
# The actual navigation would happen via JavaScript
|
||||
html = render(view)
|
||||
assert html =~ ~s(/users/#{user.id})
|
||||
end
|
||||
|
||||
test "edit link points to correct edit page", %{conn: conn} do
|
||||
user = create_test_user(%{email: "edit-me@example.com"})
|
||||
conn = conn_with_oidc_user(conn)
|
||||
{:ok, _view, html} = live(conn, "/users")
|
||||
|
||||
assert html =~ ~s(/users/#{user.id}/edit)
|
||||
end
|
||||
|
||||
test "new user button points to correct new page", %{conn: conn} do
|
||||
conn = conn_with_oidc_user(conn)
|
||||
{:ok, _view, html} = live(conn, "/users")
|
||||
|
||||
assert html =~ ~s(/users/new)
|
||||
end
|
||||
end
|
||||
|
||||
describe "translations" do
|
||||
test "shows German translations for selection", %{conn: conn} do
|
||||
conn = conn_with_oidc_user(conn)
|
||||
conn = Plug.Test.init_test_session(conn, locale: "de")
|
||||
{:ok, _view, html} = live(conn, "/users")
|
||||
|
||||
assert html =~ "Alle Benutzer*innen auswählen"
|
||||
assert html =~ "Benutzer*in auswählen"
|
||||
end
|
||||
|
||||
test "shows English translations for selection", %{conn: conn} do
|
||||
conn = conn_with_oidc_user(conn)
|
||||
Gettext.put_locale(MvWeb.Gettext, "en")
|
||||
{:ok, _view, html} = live(conn, "/users")
|
||||
|
||||
# Note: English translations might be empty strings by default
|
||||
# This test would verify the structure is there
|
||||
# Checking that aria-label attributes exist
|
||||
assert html =~ ~s(aria-label=)
|
||||
end
|
||||
end
|
||||
|
||||
describe "edge cases" do
|
||||
test "handles empty user list gracefully", %{conn: conn} do
|
||||
# Don't create any users besides the authenticated one
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue