Skip to content

Commit e1fd41c

Browse files
chore: adding clear filter tests
1 parent 3594ac3 commit e1fd41c

File tree

1 file changed

+69
-0
lines changed

1 file changed

+69
-0
lines changed

test/components/resource/data_table_filtering_test.exs

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -418,4 +418,73 @@ defmodule AshAdmin.Test.Components.Resource.DataTableFilteringTest do
418418
refute html =~ "Third post about Testing"
419419
end
420420
end
421+
422+
describe "clear filters" do
423+
test "clearing filters restores all results", %{conn: conn} do
424+
{view, _html} =
425+
live_and_wait(conn, "/api/admin?domain=Domain&resource=Post&action_type=read&action=read")
426+
427+
# Apply a filter first
428+
view
429+
|> element("form")
430+
|> render_change(%{"filters" => %{"body" => "Phoenix"}})
431+
432+
# Wait for Cinder to re-query
433+
html = render_async(view)
434+
435+
# Should show only filtered result
436+
assert html =~ "Second post about Phoenix"
437+
refute html =~ "First post about Elixir"
438+
refute html =~ "Third post about Testing"
439+
440+
# Clear the filter by setting it to empty string
441+
view
442+
|> element("form")
443+
|> render_change(%{"filters" => %{"body" => ""}})
444+
445+
# Wait for Cinder to re-query
446+
html = render_async(view)
447+
448+
# Should show all posts again
449+
assert html =~ "First post about Elixir"
450+
assert html =~ "Second post about Phoenix"
451+
assert html =~ "Third post about Testing"
452+
end
453+
454+
test "clicking clear all button clears all filters", %{conn: conn} do
455+
{view, _html} =
456+
live_and_wait(conn, "/api/admin?domain=Domain&resource=Post&action_type=read&action=read")
457+
458+
# Apply multiple filters
459+
view
460+
|> element("form")
461+
|> render_change(%{
462+
"filters" => %{
463+
"body" => "Phoenix",
464+
"expires_at_from" => "2025-01-01"
465+
}
466+
})
467+
468+
# Wait for Cinder to re-query
469+
html = render_async(view)
470+
471+
# Should show only filtered result
472+
assert html =~ "Second post about Phoenix"
473+
refute html =~ "First post about Elixir"
474+
refute html =~ "Third post about Testing"
475+
476+
# Click the clear all button
477+
view
478+
|> element("button[phx-click='clear_all_filters']")
479+
|> render_click()
480+
481+
# Wait for Cinder to re-query
482+
html = render_async(view)
483+
484+
# Should show all posts again
485+
assert html =~ "First post about Elixir"
486+
assert html =~ "Second post about Phoenix"
487+
assert html =~ "Third post about Testing"
488+
end
489+
end
421490
end

0 commit comments

Comments
 (0)