Add flash bar tests and fix snapshot capture after complete
Fix the dashboard-after-complete snapshot to wait for .flash-bar
instead of #series-note-detail, since completing now redirects to
the dashboard with a flash (not the series page).
Strengthen the flash test to verify HTML structure: data-undo-path
attribute, button classes, and inline addEventListener script. Add
a test for flash without undo_path (message-only flash hides the
undo button).
https://claude.ai/code/session_01NLGBcJgbiyWGDBGFh8DRas
diff --git a/lib/ketchup/snapshots.rb b/lib/ketchup/snapshots.rb
index 6b0aa82..ba15b04 100644
--- a/lib/ketchup/snapshots.rb
+++ b/lib/ketchup/snapshots.rb
@@ -153,9 +153,7 @@ module Ketchup
end
wait_for(".complete-btn").click
- wait_for("#series-note-detail")
- goto @base
- wait_for(".dashboard")
+ wait_for(".flash-bar")
entries << snap("dashboard-after-complete")
# ── New series ──
diff --git a/test/test_web.rb b/test/test_web.rb
index 63c1dbc..5cf11f7 100644
--- a/test/test_web.rb
+++ b/test/test_web.rb
@@ -591,11 +591,38 @@ class TestWeb < Minitest::Test
csrf_post "/series/#{series[:id]}/tasks/#{task[:id]}/complete", {}, auth_headers
get "/", {}, auth_headers
+ body = last_response.body
assert last_response.ok?
- assert_includes last_response.body, "Completed"
- assert_includes last_response.body, "Call Mom"
- assert_includes last_response.body, "Undo"
- assert_includes last_response.body, "/complete"
+ assert_includes body, "Completed"
+ assert_includes body, "Call Mom"
+
+ # Flash bar structure: data attribute carries the undo path
+ undo_path = "/series/#{series[:id]}/tasks/#{task[:id]}/complete"
+ assert_includes body, "data-undo-path=\"#{undo_path}\""
+ assert_includes body, "flash-undo-btn"
+ assert_includes body, "flash-close-btn"
+
+ # Inline script wires up click handlers (no Alpine dependency)
+ assert_includes body, "addEventListener"
+ assert_includes body, "fetch(path"
+ end
+
+ def test_complete_flash_without_undo_path
+ create_series(note: "Call Mom", interval_unit: "week", interval_count: "2",
+ first_due_date: (Date.today - 3).to_s)
+
+ task = DB[:tasks].first
+ series = DB[:series].first
+
+ # Simulate a flash with no undo_path (message only)
+ env "rack.session", {"flash" => {"message" => "Something happened"}}
+ get "/", {}, auth_headers
+ body = last_response.body
+ assert_includes body, "flash-bar"
+ assert_includes body, "Something happened"
+ assert_includes body, "flash-close-btn"
+ refute_includes body, "data-undo-path"
+ assert_match(/hidden/, body[/flash-undo-btn[^>]*/])
end
def test_flash_is_cleared_after_display