@@ -56,4 +56,83 @@ defmodule Honeybadger.Insights.LiveViewTest do
5656 assert event [ "assigns" ] == nil
5757 end
5858 end
59+
60+ describe "mount start handler" do
61+ test "sets socket_id in event context from socket" do
62+ :telemetry . execute (
63+ [ :phoenix , :live_view , :mount , :start ] ,
64+ % { } ,
65+ % {
66+ socket: % {
67+ id: "phx-Fmount123" ,
68+ view: MyApp.DashboardLive ,
69+ assigns: % { }
70+ }
71+ }
72+ )
73+
74+ assert Honeybadger.EventContext . get ( :socket_id ) == "phx-Fmount123"
75+ end
76+
77+ test "sets socket_id in event context from socket_id key" do
78+ :telemetry . execute (
79+ [ :phoenix , :live_view , :mount , :start ] ,
80+ % { } ,
81+ % {
82+ socket_id: "phx-Gtop456"
83+ }
84+ )
85+
86+ assert Honeybadger.EventContext . get ( :socket_id ) == "phx-Gtop456"
87+ end
88+
89+ test "socket_id propagates to subsequent events" do
90+ :telemetry . execute (
91+ [ :phoenix , :live_view , :mount , :start ] ,
92+ % { } ,
93+ % {
94+ socket: % {
95+ id: "phx-Hprop789" ,
96+ view: MyApp.DashboardLive ,
97+ assigns: % { }
98+ }
99+ }
100+ )
101+
102+ event =
103+ send_and_receive (
104+ [ :phoenix , :live_view , :handle_event , :stop ] ,
105+ % { duration: System . convert_time_unit ( 5 , :microsecond , :native ) } ,
106+ % {
107+ uri: "/dashboard" ,
108+ socket: % {
109+ id: "phx-Hprop789" ,
110+ view: MyApp.DashboardLive ,
111+ assigns: % { }
112+ } ,
113+ event: "click"
114+ }
115+ )
116+
117+ assert event [ "socket_id" ] == "phx-Hprop789"
118+ end
119+
120+ test "does not overwrite existing socket_id in event context" do
121+ Honeybadger.EventContext . merge ( % { socket_id: "existing-id" } )
122+
123+ :telemetry . execute (
124+ [ :phoenix , :live_view , :mount , :start ] ,
125+ % { } ,
126+ % {
127+ socket: % {
128+ id: "phx-Inew999" ,
129+ view: MyApp.DashboardLive ,
130+ assigns: % { }
131+ }
132+ }
133+ )
134+
135+ assert Honeybadger.EventContext . get ( :socket_id ) == "existing-id"
136+ end
137+ end
59138end
0 commit comments