@@ -189,5 +189,84 @@ defmodule ReencodarrWeb.DashboardLiveTest do
189189 # Note: We can't test button clicking when disabled,
190190 # so we'll just verify the page handles the sync state
191191 end
192+
193+ test "handles batch_analysis_completed event without crashing" , % { conn: conn } do
194+ { :ok , view , _ } = live ( conn , ~p" /" )
195+
196+ send ( view . pid , { :batch_analysis_completed , % { batch_size: 5 } } )
197+ :timer . sleep ( 50 )
198+
199+ assert render ( view ) =~ "Processing Pipeline"
200+ end
201+
202+ test "handles analyzer_progress event without crashing" , % { conn: conn } do
203+ { :ok , view , _ } = live ( conn , ~p" /" )
204+
205+ send ( view . pid , { :analyzer_progress , % { current: 3 , total: 10 , batch_size: 2 } } )
206+ :timer . sleep ( 50 )
207+
208+ assert render ( view ) =~ "Processing Pipeline"
209+ end
210+
211+ test "encoder_health_alert stalled shows error flash" , % { conn: conn } do
212+ { :ok , view , _ } = live ( conn , ~p" /" )
213+
214+ send (
215+ view . pid ,
216+ { :encoder_health_alert , % { video_path: "/tmp/video.mkv" , reason: :stalled_23_hours } }
217+ )
218+
219+ :timer . sleep ( 50 )
220+
221+ html = render ( view )
222+ assert html =~ "Encoder may be stuck"
223+ end
224+
225+ test "encoder_health_alert with unknown reason shows generic message" , % { conn: conn } do
226+ { :ok , view , _ } = live ( conn , ~p" /" )
227+
228+ send ( view . pid , { :encoder_health_alert , % { video_path: nil , reason: :some_other_reason } } )
229+ :timer . sleep ( 50 )
230+
231+ html = render ( view )
232+ assert html =~ "Encoder health alert"
233+ end
234+ end
235+
236+ describe "sync event handlers" do
237+ test "sync_sonarr event starts sync and shows flash" , % { conn: conn } do
238+ { :ok , view , _ } = live ( conn , ~p" /" )
239+
240+ html = view |> render_click ( "sync_sonarr" , % { } )
241+
242+ assert html =~ "Sonarr sync started"
243+ end
244+
245+ test "sync_radarr event starts sync and shows flash" , % { conn: conn } do
246+ { :ok , view , _ } = live ( conn , ~p" /" )
247+
248+ html = view |> render_click ( "sync_radarr" , % { } )
249+
250+ assert html =~ "Radarr sync started"
251+ end
252+
253+ test "sync_sonarr shows error when sync already in progress" , % { conn: conn } do
254+ { :ok , view , _ } = live ( conn , ~p" /" )
255+
256+ send ( view . pid , { :sync_started , % { service_type: "sonarr" } } )
257+ :timer . sleep ( 50 )
258+
259+ html = view |> render_click ( "sync_sonarr" , % { } )
260+
261+ assert html =~ "Sync already in progress"
262+ end
263+
264+ test "unknown sync_service event shows error flash" , % { conn: conn } do
265+ { :ok , view , _ } = live ( conn , ~p" /" )
266+
267+ html = view |> render_click ( "sync_unknownservice" , % { } )
268+
269+ assert html =~ "Unknown sync service"
270+ end
192271 end
193272end
0 commit comments