@@ -62,6 +62,63 @@ describe('LynxInsightEditorObjectsComponent', () => {
62
62
verify ( mockInsightRenderService . render ( anything ( ) , anything ( ) ) ) . once ( ) ;
63
63
} ) ) ;
64
64
65
+ it ( 'should clear formatting and overlays when insights are disabled' , fakeAsync ( ( ) => {
66
+ const env = new TestEnvironment ( ) ;
67
+ const testInsight = env . createTestInsight ( ) ;
68
+
69
+ // Setup initial state with insights enabled
70
+ env . setEditorReady ( true ) ;
71
+ env . setFilteredInsights ( [ testInsight ] ) ;
72
+ tick ( ) ;
73
+ flush ( ) ;
74
+
75
+ // Verify initial render occurred
76
+ verify ( mockInsightRenderService . render ( anything ( ) , anything ( ) ) ) . atLeast ( 1 ) ;
77
+
78
+ // Disable insights
79
+ env . setInsightsEnabled ( false ) ;
80
+ tick ( ) ;
81
+ flush ( ) ;
82
+
83
+ // Verify cleanup methods were called
84
+ verify ( mockInsightRenderService . removeAllInsightFormatting ( anything ( ) ) ) . atLeast ( 1 ) ;
85
+ verify ( mockOverlayService . close ( ) ) . atLeast ( 1 ) ;
86
+ verify ( mockInsightStateService . clearDisplayState ( ) ) . atLeast ( 1 ) ;
87
+ } ) ) ;
88
+
89
+ it ( 'should not render insights when initially disabled' , fakeAsync ( ( ) => {
90
+ const env = new TestEnvironment ( { insightsEnabled : false } ) ;
91
+
92
+ env . setEditorReady ( true ) ;
93
+ env . setFilteredInsights ( [ env . createTestInsight ( ) ] ) ;
94
+ tick ( ) ;
95
+ flush ( ) ;
96
+
97
+ // Verify render was not called when insights are disabled
98
+ verify ( mockInsightRenderService . render ( anything ( ) , anything ( ) ) ) . never ( ) ;
99
+ } ) ) ;
100
+
101
+ it ( 'should resume rendering when insights are re-enabled' , fakeAsync ( ( ) => {
102
+ const env = new TestEnvironment ( { insightsEnabled : false } ) ;
103
+ const testInsight = env . createTestInsight ( ) ;
104
+
105
+ env . setEditorReady ( true ) ;
106
+ env . setFilteredInsights ( [ testInsight ] ) ;
107
+ tick ( ) ;
108
+ flush ( ) ;
109
+
110
+ // Verify no rendering when disabled
111
+ verify ( mockInsightRenderService . render ( anything ( ) , anything ( ) ) ) . never ( ) ;
112
+
113
+ // Re-enable insights
114
+ env . setInsightsEnabled ( true ) ;
115
+ tick ( ) ;
116
+ flush ( ) ;
117
+
118
+ // Verify rendering resumes
119
+ verify ( mockInsightRenderService . render ( anything ( ) , anything ( ) ) ) . once ( ) ;
120
+ } ) ) ;
121
+
65
122
it ( 'should close overlays when editor becomes ready' , fakeAsync ( ( ) => {
66
123
const env = new TestEnvironment ( { initialEditorReady : false } ) ;
67
124
@@ -250,6 +307,7 @@ class HostComponent {
250
307
251
308
interface TestEnvArgs {
252
309
initialEditorReady ?: boolean ;
310
+ insightsEnabled ?: boolean ;
253
311
}
254
312
255
313
class TestEnvironment {
@@ -265,6 +323,7 @@ class TestEnvironment {
265
323
constructor ( args : TestEnvArgs = { } ) {
266
324
const textModelConverter = instance ( mockTextModelConverter ) ;
267
325
const initialEditorReady = args . initialEditorReady ?? true ;
326
+ const insightsEnabled = args . insightsEnabled ?? true ;
268
327
269
328
this . editorReadySubject = new BehaviorSubject < boolean > ( initialEditorReady ) ;
270
329
this . filteredInsightsSubject = new BehaviorSubject < LynxInsight [ ] > ( [ ] ) ;
@@ -303,6 +362,7 @@ class TestEnvironment {
303
362
when ( mockInsightStateService . filteredChapterInsights$ ) . thenReturn ( this . filteredInsightsSubject ) ;
304
363
when ( mockInsightStateService . displayState$ ) . thenReturn ( this . displayStateSubject ) ;
305
364
when ( mockInsightStateService . updateDisplayState ( anything ( ) ) ) . thenReturn ( ) ;
365
+ when ( mockInsightStateService . clearDisplayState ( ) ) . thenReturn ( ) ;
306
366
when ( mockInsightRenderService . render ( anything ( ) , anything ( ) ) ) . thenResolve ( ) ;
307
367
when ( mockInsightRenderService . renderActionOverlay ( anything ( ) , anything ( ) , anything ( ) , anything ( ) ) ) . thenResolve ( ) ;
308
368
when ( mockInsightRenderService . renderCursorActiveState ( anything ( ) , anything ( ) ) ) . thenResolve ( ) ;
@@ -321,6 +381,7 @@ class TestEnvironment {
321
381
// Set the inputs before calling detectChanges to ensure they're available during ngOnInit
322
382
this . hostComponent . editor = actualEditor ;
323
383
this . hostComponent . textModelConverter = textModelConverter ;
384
+ this . hostComponent . insightsEnabled = insightsEnabled ;
324
385
325
386
this . fixture . detectChanges ( ) ;
326
387
this . component = this . hostComponent . component ;
@@ -330,6 +391,11 @@ class TestEnvironment {
330
391
this . editorReadySubject . next ( ready ) ;
331
392
}
332
393
394
+ setInsightsEnabled ( enabled : boolean ) : void {
395
+ this . hostComponent . insightsEnabled = enabled ;
396
+ this . fixture . detectChanges ( ) ;
397
+ }
398
+
333
399
setFilteredInsights ( insights : LynxInsight [ ] ) : void {
334
400
this . filteredInsightsSubject . next ( insights ) ;
335
401
}
0 commit comments