@@ -356,6 +356,57 @@ defmodule DemoWeb.Live.Post.FilterLiveTest do
356356 end
357357 end
358358
359+ describe "filters_changed preservation across confirmed item actions" do
360+ test "delete item action preserves cleared default filter" , % { conn: conn } do
361+ # Insert without tags to avoid the posts_tags FK preventing the delete.
362+ insert ( :post , title: "Published Post" , published: true , tags: [ ] )
363+ draft_to_keep = insert ( :post , title: "Draft to Keep" , published: false , tags: [ ] )
364+ draft_to_delete = insert ( :post , title: "Draft to Delete" , published: false , tags: [ ] )
365+
366+ session =
367+ conn
368+ |> visit ( ~p" /admin/posts" )
369+ |> assert_has ( "table tbody tr" , count: 1 )
370+ |> assert_has ( "td" , text: "Published Post" )
371+ |> refute_has ( "td" , text: "Draft to Keep" )
372+ |> unwrap ( fn view ->
373+ view
374+ |> element ( "button[phx-click='clear-filter'][phx-value-field='published'][aria-label]" )
375+ |> render_click ( )
376+ end )
377+ |> assert_has ( "table tbody tr" , count: 3 )
378+ |> assert_has ( "td" , text: "Draft to Keep" )
379+ |> unwrap ( fn view ->
380+ view
381+ |> element ( "button[aria-label='Delete'][phx-value-item-id='#{ draft_to_delete . id } ']" )
382+ |> render_click ( )
383+ end )
384+ |> unwrap ( fn view ->
385+ view
386+ |> form ( "#resource-form" )
387+ |> render_submit ( )
388+ end )
389+
390+ # After the confirmed delete the form component runs `push_navigate(return_to)`,
391+ # which remounts the index. Without the fix the URL would lose `filters_changed`,
392+ # so `maybe_redirect_to_default_filters/1` would re-apply `filters[published]=published`
393+ # and the remaining draft post would disappear from the table.
394+ session
395+ |> assert_path ( ~p" /admin/posts" ,
396+ query_params: % {
397+ "filters_changed" => "true" ,
398+ "order_by" => "id" ,
399+ "order_direction" => "asc" ,
400+ "per_page" => "15" ,
401+ "page" => "1"
402+ }
403+ )
404+ |> assert_has ( "td" , text: "Published Post" )
405+ |> assert_has ( "td" , text: draft_to_keep . title )
406+ |> refute_has ( "td" , text: draft_to_delete . title )
407+ end
408+ end
409+
359410 describe "filter badges" do
360411 test "shows badge for active category filter" , % { conn: conn } do
361412 category = insert ( :category , name: "Technology" )
0 commit comments