@@ -45,7 +45,12 @@ describe("CodeDebuggerComponent", () => {
4545 beforeEach ( async ( ) => {
4646 // Initialize streams and spy objects
4747 statusUpdateStream = new Subject < Record < string , OperatorStatistics > > ( ) ;
48- debugState = new Y . Map < BreakpointInfo > ( ) ;
48+ // Y.Map observers only fire when the map is attached to a Y.Doc (the doc
49+ // owns the transaction lifecycle that drives observation). A standalone
50+ // `new Y.Map()` accepts `.set()` but never notifies observers — production
51+ // never hits this because `UdfDebugService` hands out maps from a real
52+ // doc, but the spec used to construct a detached map.
53+ debugState = new Y . Doc ( ) . getMap < BreakpointInfo > ( "debug" ) ;
4954
5055 mockWorkflowStatusService = { getStatusUpdateStream : vi . fn ( ) } as unknown as Mocked < WorkflowStatusService > ;
5156 mockWorkflowStatusService . getStatusUpdateStream . mockReturnValue ( statusUpdateStream . asObservable ( ) ) ;
@@ -238,4 +243,152 @@ describe("CodeDebuggerComponent", () => {
238243
239244 expect ( component . breakpointConditionLine ) . toBeUndefined ( ) ;
240245 } ) ;
246+
247+ describe ( "registerBreakpointRenderingHandler" , ( ) => {
248+ // Stand-in for the MonacoBreakpoint instance set up in
249+ // setupMonacoBreakpointMethods. The observer in
250+ // registerBreakpointRenderingHandler reaches into these as bracket
251+ // properties, so we wire up the four it touches: createSpecifyDecoration,
252+ // removeSpecifyDecoration, setLineHighlight, removeHighlight, plus the
253+ // lineNumberAndDecorationIdMap reads by removeBreakpointDecoration.
254+ let monacoBreakpointStub : {
255+ createSpecifyDecoration : ReturnType < typeof vi . fn > ;
256+ removeSpecifyDecoration : ReturnType < typeof vi . fn > ;
257+ setLineHighlight : ReturnType < typeof vi . fn > ;
258+ removeHighlight : ReturnType < typeof vi . fn > ;
259+ lineNumberAndDecorationIdMap : Map < number , string > ;
260+ mouseDownDisposable : { dispose : ReturnType < typeof vi . fn > } ;
261+ dispose : ReturnType < typeof vi . fn > ;
262+ } ;
263+
264+ beforeEach ( ( ) => {
265+ monacoBreakpointStub = {
266+ createSpecifyDecoration : vi . fn ( ) ,
267+ removeSpecifyDecoration : vi . fn ( ) ,
268+ setLineHighlight : vi . fn ( ) ,
269+ removeHighlight : vi . fn ( ) ,
270+ lineNumberAndDecorationIdMap : new Map < number , string > ( ) ,
271+ mouseDownDisposable : { dispose : vi . fn ( ) } ,
272+ dispose : vi . fn ( ) ,
273+ } ;
274+ component . monacoBreakpoint = monacoBreakpointStub as unknown as MonacoBreakpoint ;
275+ } ) ;
276+
277+ it ( "draws a decoration when a debug-state entry with breakpointId is added" , ( ) => {
278+ debugState . set ( "3" , { breakpointId : 3 , condition : "" , hit : false } as BreakpointInfo ) ;
279+
280+ expect ( monacoBreakpointStub . createSpecifyDecoration ) . toHaveBeenCalledWith ( {
281+ startLineNumber : 3 ,
282+ startColumn : 1 ,
283+ endLineNumber : 3 ,
284+ endColumn : 1 ,
285+ } ) ;
286+ } ) ;
287+
288+ it ( "does not draw a decoration when the added entry has no breakpointId" , ( ) => {
289+ debugState . set ( "4" , { breakpointId : undefined , condition : "" , hit : false } as BreakpointInfo ) ;
290+
291+ expect ( monacoBreakpointStub . createSpecifyDecoration ) . not . toHaveBeenCalled ( ) ;
292+ } ) ;
293+
294+ it ( "removes the decoration when a debug-state entry with breakpointId is deleted" , ( ) => {
295+ debugState . set ( "5" , { breakpointId : 5 , condition : "" , hit : false } as BreakpointInfo ) ;
296+ // Mirror the lookup that removeBreakpointDecoration performs.
297+ monacoBreakpointStub . lineNumberAndDecorationIdMap . set ( 5 , "dec-5" ) ;
298+ monacoBreakpointStub . createSpecifyDecoration . mockClear ( ) ;
299+
300+ debugState . delete ( "5" ) ;
301+
302+ expect ( monacoBreakpointStub . removeSpecifyDecoration ) . toHaveBeenCalledWith ( "dec-5" , 5 ) ;
303+ } ) ;
304+
305+ it ( "does not call removeSpecifyDecoration when the deleted entry had no breakpointId" , ( ) => {
306+ // Y.Map.observe surfaces a delete with oldValue.breakpointId === undefined
307+ // when the entry never had a breakpoint to begin with.
308+ debugState . set ( "6" , { breakpointId : undefined , condition : "" , hit : false } as BreakpointInfo ) ;
309+ debugState . delete ( "6" ) ;
310+
311+ expect ( monacoBreakpointStub . removeSpecifyDecoration ) . not . toHaveBeenCalled ( ) ;
312+ } ) ;
313+
314+ it ( "calls setLineHighlight when an entry's hit flag flips on" , ( ) => {
315+ debugState . set ( "7" , { breakpointId : 7 , condition : "" , hit : false } as BreakpointInfo ) ;
316+
317+ debugState . set ( "7" , { breakpointId : 7 , condition : "" , hit : true } as BreakpointInfo ) ;
318+
319+ expect ( monacoBreakpointStub . setLineHighlight ) . toHaveBeenCalledWith ( 7 ) ;
320+ } ) ;
321+
322+ it ( "calls removeHighlight when an entry's hit flag flips off" , ( ) => {
323+ debugState . set ( "8" , { breakpointId : 8 , condition : "" , hit : true } as BreakpointInfo ) ;
324+
325+ debugState . set ( "8" , { breakpointId : 8 , condition : "" , hit : false } as BreakpointInfo ) ;
326+
327+ expect ( monacoBreakpointStub . removeHighlight ) . toHaveBeenCalled ( ) ;
328+ } ) ;
329+
330+ it ( "re-creates the decoration when the condition string changes on an existing entry" , ( ) => {
331+ debugState . set ( "9" , { breakpointId : 9 , condition : "" , hit : false } as BreakpointInfo ) ;
332+ monacoBreakpointStub . lineNumberAndDecorationIdMap . set ( 9 , "dec-9" ) ;
333+ monacoBreakpointStub . createSpecifyDecoration . mockClear ( ) ;
334+ monacoBreakpointStub . removeSpecifyDecoration . mockClear ( ) ;
335+
336+ debugState . set ( "9" , { breakpointId : 9 , condition : "x > 0" , hit : false } as BreakpointInfo ) ;
337+
338+ expect ( monacoBreakpointStub . removeSpecifyDecoration ) . toHaveBeenCalledWith ( "dec-9" , 9 ) ;
339+ expect ( monacoBreakpointStub . createSpecifyDecoration ) . toHaveBeenCalledWith ( {
340+ startLineNumber : 9 ,
341+ startColumn : 1 ,
342+ endLineNumber : 9 ,
343+ endColumn : 1 ,
344+ } ) ;
345+ } ) ;
346+ } ) ;
347+
348+ describe ( "rerenderExistingBreakpoints" , ( ) => {
349+ let monacoBreakpointStub : {
350+ createSpecifyDecoration : ReturnType < typeof vi . fn > ;
351+ } ;
352+
353+ beforeEach ( ( ) => {
354+ monacoBreakpointStub = { createSpecifyDecoration : vi . fn ( ) } ;
355+ component . monacoBreakpoint = monacoBreakpointStub as unknown as MonacoBreakpoint ;
356+ } ) ;
357+
358+ it ( "re-creates a decoration for every existing entry that has a breakpointId" , ( ) => {
359+ debugState . set ( "10" , { breakpointId : 10 , condition : "" , hit : false } as BreakpointInfo ) ;
360+ debugState . set ( "11" , { breakpointId : undefined , condition : "" , hit : false } as BreakpointInfo ) ;
361+ debugState . set ( "12" , { breakpointId : 12 , condition : "y > 0" , hit : false } as BreakpointInfo ) ;
362+ monacoBreakpointStub . createSpecifyDecoration . mockClear ( ) ;
363+
364+ component . rerenderExistingBreakpoints ( ) ;
365+
366+ // Only entries 10 and 12 carry a breakpointId; 11 is filtered out by the
367+ // early-return inside rerenderExistingBreakpoints.
368+ const lines = monacoBreakpointStub . createSpecifyDecoration . mock . calls . map ( c => c [ 0 ] . startLineNumber ) ;
369+ expect ( lines . sort ( ) ) . toEqual ( [ 10 , 12 ] ) ;
370+ } ) ;
371+ } ) ;
372+
373+ describe ( "removeMonacoBreakpointMethods" , ( ) => {
374+ it ( "disposes the mouseDownDisposable and the breakpoint instance when defined" , ( ) => {
375+ const disposeMouseDown = vi . fn ( ) ;
376+ const disposeBreakpoint = vi . fn ( ) ;
377+ component . monacoBreakpoint = {
378+ mouseDownDisposable : { dispose : disposeMouseDown } ,
379+ dispose : disposeBreakpoint ,
380+ } as unknown as MonacoBreakpoint ;
381+
382+ component . removeMonacoBreakpointMethods ( ) ;
383+
384+ expect ( disposeMouseDown ) . toHaveBeenCalledOnce ( ) ;
385+ expect ( disposeBreakpoint ) . toHaveBeenCalledOnce ( ) ;
386+ } ) ;
387+
388+ it ( "returns early without touching anything when monacoBreakpoint is undefined" , ( ) => {
389+ component . monacoBreakpoint = undefined ;
390+ // Should simply no-op.
391+ expect ( ( ) => component . removeMonacoBreakpointMethods ( ) ) . not . toThrow ( ) ;
392+ } ) ;
393+ } ) ;
241394} ) ;
0 commit comments