test: added tests
This commit is contained in:
parent
c3502a326e
commit
3cfae95b1e
2 changed files with 48 additions and 1 deletions
12
test/mv_web/components/sort_header_component_test.exs
Normal file
12
test/mv_web/components/sort_header_component_test.exs
Normal file
|
|
@ -0,0 +1,12 @@
|
||||||
|
defmodule MvWeb.Components.SortHeaderComponentTest do
|
||||||
|
use MvWeb.ConnCase, async: true
|
||||||
|
use Phoenix.Component
|
||||||
|
import Phoenix.LiveViewTest
|
||||||
|
|
||||||
|
test "renders sort header with correct attributes", %{conn: conn} do
|
||||||
|
conn = conn_with_oidc_user(conn)
|
||||||
|
{:ok, view, _html} = live(conn, "/members")
|
||||||
|
|
||||||
|
assert view |> element("[data-testid='first_name']")
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
@ -56,7 +56,6 @@ defmodule MvWeb.MemberLive.IndexTest do
|
||||||
|
|
||||||
test "shows translated flash message after creating a member in English", %{conn: conn} do
|
test "shows translated flash message after creating a member in English", %{conn: conn} do
|
||||||
conn = conn_with_oidc_user(conn)
|
conn = conn_with_oidc_user(conn)
|
||||||
conn = Plug.Test.init_test_session(conn, locale: "en")
|
|
||||||
{:ok, form_view, _html} = live(conn, "/members/new")
|
{:ok, form_view, _html} = live(conn, "/members/new")
|
||||||
|
|
||||||
form_data = %{
|
form_data = %{
|
||||||
|
|
@ -75,6 +74,42 @@ defmodule MvWeb.MemberLive.IndexTest do
|
||||||
assert has_element?(index_view, "#flash-group", "Member create successfully")
|
assert has_element?(index_view, "#flash-group", "Member create successfully")
|
||||||
end
|
end
|
||||||
|
|
||||||
|
describe "sorting interaction" do
|
||||||
|
test "clicking a column header toggles sort order and updates the URL", %{conn: conn} do
|
||||||
|
conn = conn_with_oidc_user(conn)
|
||||||
|
{:ok, view, _html} = live(conn, "/members")
|
||||||
|
|
||||||
|
# The component data test ids are built as "<field>"
|
||||||
|
# First click – should sort ASC
|
||||||
|
view
|
||||||
|
|> element("[data-testid='email']")
|
||||||
|
|> render_click()
|
||||||
|
|
||||||
|
# The LiveView pushes a patch with the new query params
|
||||||
|
assert_patch(view, "/members?sort_field=email&sort_order=asc")
|
||||||
|
|
||||||
|
# Second click – toggles to DESC
|
||||||
|
view
|
||||||
|
|> element("[data-testid='email']")
|
||||||
|
|> render_click()
|
||||||
|
|
||||||
|
assert_patch(view, "/members?sort_field=email&sort_order=desc")
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
describe "URL param handling" do
|
||||||
|
test "handle_params reads sort query and applies it", %{conn: conn} do
|
||||||
|
conn = conn_with_oidc_user(conn)
|
||||||
|
url = "/members?sort_field=email&sort_order=desc"
|
||||||
|
|
||||||
|
conn = get(conn, url)
|
||||||
|
|
||||||
|
# The LiveView must have parsed the params and stored them as atoms.
|
||||||
|
assert conn.assigns.sort_field == :email
|
||||||
|
assert conn.assigns.sort_order == :desc
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
test "handle_info(:search_changed) updates assigns with search results", %{conn: conn} do
|
test "handle_info(:search_changed) updates assigns with search results", %{conn: conn} do
|
||||||
conn = conn_with_oidc_user(conn)
|
conn = conn_with_oidc_user(conn)
|
||||||
{:ok, view, _html} = live(conn, "/members")
|
{:ok, view, _html} = live(conn, "/members")
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue