refactor: add data-testid selectors for groups ui
Some checks failed
continuous-integration/drone/push Build is failing

This commit is contained in:
Simon 2026-02-20 16:34:15 +01:00
parent 83b104ecf3
commit 123227a50e
Signed by: simon
GPG key ID: 40E7A58C4AA1EDB2
13 changed files with 231 additions and 384 deletions

View file

@ -22,34 +22,33 @@ defmodule MvWeb.GroupLive.ShowTest do
test "page renders successfully", %{conn: conn} do
group = Fixtures.group_fixture()
{:ok, _view, html} = live(conn, "/groups/#{group.slug}")
{:ok, view, _html} = live(conn, "/groups/#{group.slug}")
assert html =~ group.name
assert has_element?(view, "h1", group.name)
end
test "displays group name", %{conn: conn} do
group = Fixtures.group_fixture(%{name: "Test Group Name"})
{:ok, _view, html} = live(conn, "/groups/#{group.slug}")
{:ok, view, _html} = live(conn, "/groups/#{group.slug}")
assert html =~ "Test Group Name"
assert has_element?(view, "h1", "Test Group Name")
end
test "displays group description when present", %{conn: conn} do
group = Fixtures.group_fixture(%{description: "This is a test description"})
{:ok, _view, html} = live(conn, "/groups/#{group.slug}")
{:ok, view, _html} = live(conn, "/groups/#{group.slug}")
assert html =~ "This is a test description"
assert has_element?(view, "p", "This is a test description")
end
test "displays member count", %{conn: conn} do
group = Fixtures.group_fixture()
{:ok, _view, html} = live(conn, "/groups/#{group.slug}")
{:ok, view, _html} = live(conn, "/groups/#{group.slug}")
# Member count should be displayed (might be 0 or more)
assert html =~ "0" or html =~ gettext("Members") or html =~ "member" or html =~ "Mitglied"
assert has_element?(view, "[data-testid=group-show-member-count]")
end
test "displays list of members in group", %{conn: conn} do
@ -67,26 +66,26 @@ defmodule MvWeb.GroupLive.ShowTest do
actor: system_actor
)
{:ok, _view, html} = live(conn, "/groups/#{group.slug}")
{:ok, view, _html} = live(conn, "/groups/#{group.slug}")
assert html =~ "Alice" or html =~ "Smith"
assert html =~ "Bob" or html =~ "Jones"
assert has_element?(view, "[data-testid=group-show-members-table]", "Alice")
assert has_element?(view, "[data-testid=group-show-members-table]", "Bob")
end
test "displays edit button for admin users", %{conn: conn} do
group = Fixtures.group_fixture()
{:ok, _view, html} = live(conn, "/groups/#{group.slug}")
{:ok, view, _html} = live(conn, "/groups/#{group.slug}")
assert html =~ gettext("Edit") or html =~ "edit" or html =~ "Bearbeiten"
assert has_element?(view, "[data-testid=group-show-edit-btn]")
end
test "displays delete button for admin users", %{conn: conn} do
group = Fixtures.group_fixture()
{:ok, _view, html} = live(conn, "/groups/#{group.slug}")
{:ok, view, _html} = live(conn, "/groups/#{group.slug}")
assert html =~ gettext("Delete") or html =~ "delete" or html =~ "Löschen"
assert has_element?(view, "[data-testid=group-show-delete-btn]")
end
end
@ -94,19 +93,17 @@ defmodule MvWeb.GroupLive.ShowTest do
test "route /groups/:slug works correctly", %{conn: conn} do
group = Fixtures.group_fixture(%{name: "Board Members"})
{:ok, _view, html} = live(conn, "/groups/#{group.slug}")
{:ok, view, _html} = live(conn, "/groups/#{group.slug}")
assert html =~ "Board Members"
# Verify slug is in URL
assert html =~ group.slug or html =~ "board-members"
assert has_element?(view, "h1", "Board Members")
end
test "group is found by slug via unique_slug identity", %{conn: conn} do
group = Fixtures.group_fixture(%{name: "Test Group"})
{:ok, _view, html} = live(conn, "/groups/#{group.slug}")
{:ok, view, _html} = live(conn, "/groups/#{group.slug}")
assert html =~ group.name
assert has_element?(view, "h1", group.name)
end
test "non-existent slug returns 404", %{conn: conn} do
@ -145,28 +142,26 @@ defmodule MvWeb.GroupLive.ShowTest do
test "displays empty group correctly (0 members)", %{conn: conn} do
group = Fixtures.group_fixture()
{:ok, _view, html} = live(conn, "/groups/#{group.slug}")
{:ok, view, _html} = live(conn, "/groups/#{group.slug}")
assert html =~ "0" or html =~ gettext("No members") or html =~ "empty" or
html =~ "Keine Mitglieder"
assert has_element?(view, "[data-testid=group-show-no-members]")
end
test "handles group without description correctly", %{conn: conn} do
group = Fixtures.group_fixture(%{description: nil})
{:ok, _view, html} = live(conn, "/groups/#{group.slug}")
{:ok, view, _html} = live(conn, "/groups/#{group.slug}")
# Should not crash, description should be optional
assert html =~ group.name
assert has_element?(view, "h1", group.name)
end
test "handles slug with special characters correctly", %{conn: conn} do
# Create group with name that generates slug with hyphens
group = Fixtures.group_fixture(%{name: "Test-Group-Name"})
{:ok, _view, html} = live(conn, "/groups/#{group.slug}")
{:ok, view, _html} = live(conn, "/groups/#{group.slug}")
assert html =~ "Test-Group-Name" or html =~ group.name
assert has_element?(view, "h1", group.name)
end
end
@ -177,11 +172,11 @@ defmodule MvWeb.GroupLive.ShowTest do
read_only_user = Fixtures.user_with_role_fixture("read_only")
conn = conn_with_password_user(conn, read_only_user)
{:ok, _view, html} = live(conn, "/groups/#{group.slug}")
{:ok, view, _html} = live(conn, "/groups/#{group.slug}")
assert html =~ group.name
# Should NOT see edit/delete buttons
refute html =~ gettext("Edit") or html =~ gettext("Delete")
assert has_element?(view, "h1", group.name)
refute has_element?(view, "[data-testid=group-show-edit-btn]")
refute has_element?(view, "[data-testid=group-show-delete-btn]")
end
@tag role: :unauthenticated
@ -246,14 +241,14 @@ defmodule MvWeb.GroupLive.ShowTest do
handler_id = "test-query-counter-#{System.unique_integer([:positive])}"
:telemetry.attach(handler_id, [:ash, :query, :start], handler, nil)
{:ok, _view, html} = live(conn, "/groups/#{group.slug}")
{:ok, view, _html} = live(conn, "/groups/#{group.slug}")
final_count = Agent.get(query_count_agent, & &1)
:telemetry.detach(handler_id)
# All members should be displayed
Enum.each(members, fn member ->
assert html =~ member.first_name or html =~ member.last_name
assert has_element?(view, "[data-testid=group-show-members-table]", member.first_name) or
has_element?(view, "[data-testid=group-show-members-table]", member.last_name)
end)
# Verify query count is reasonable (should avoid N+1 queries)
@ -267,10 +262,9 @@ defmodule MvWeb.GroupLive.ShowTest do
test "slug lookup is efficient (uses unique_slug index)", %{conn: conn} do
group = Fixtures.group_fixture()
# Should use index for fast lookup
{:ok, _view, html} = live(conn, "/groups/#{group.slug}")
{:ok, view, _html} = live(conn, "/groups/#{group.slug}")
assert html =~ group.name
assert has_element?(view, "h1", group.name)
end
end