Skip to content

Commit 88d668f

Browse files
committed
ensure blots are cleared and overlays closed when lynx is disabled
1 parent 639c004 commit 88d668f

File tree

3 files changed

+74
-1
lines changed

3 files changed

+74
-1
lines changed

src/SIL.XForge.Scripture/ClientApp/src/app/translate/editor/lynx/insights/lynx-insight-editor-objects/lynx-insight-editor-objects.component.spec.ts

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,63 @@ describe('LynxInsightEditorObjectsComponent', () => {
6262
verify(mockInsightRenderService.render(anything(), anything())).once();
6363
}));
6464

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+
65122
it('should close overlays when editor becomes ready', fakeAsync(() => {
66123
const env = new TestEnvironment({ initialEditorReady: false });
67124

@@ -250,6 +307,7 @@ class HostComponent {
250307

251308
interface TestEnvArgs {
252309
initialEditorReady?: boolean;
310+
insightsEnabled?: boolean;
253311
}
254312

255313
class TestEnvironment {
@@ -265,6 +323,7 @@ class TestEnvironment {
265323
constructor(args: TestEnvArgs = {}) {
266324
const textModelConverter = instance(mockTextModelConverter);
267325
const initialEditorReady = args.initialEditorReady ?? true;
326+
const insightsEnabled = args.insightsEnabled ?? true;
268327

269328
this.editorReadySubject = new BehaviorSubject<boolean>(initialEditorReady);
270329
this.filteredInsightsSubject = new BehaviorSubject<LynxInsight[]>([]);
@@ -303,6 +362,7 @@ class TestEnvironment {
303362
when(mockInsightStateService.filteredChapterInsights$).thenReturn(this.filteredInsightsSubject);
304363
when(mockInsightStateService.displayState$).thenReturn(this.displayStateSubject);
305364
when(mockInsightStateService.updateDisplayState(anything())).thenReturn();
365+
when(mockInsightStateService.clearDisplayState()).thenReturn();
306366
when(mockInsightRenderService.render(anything(), anything())).thenResolve();
307367
when(mockInsightRenderService.renderActionOverlay(anything(), anything(), anything(), anything())).thenResolve();
308368
when(mockInsightRenderService.renderCursorActiveState(anything(), anything())).thenResolve();
@@ -321,6 +381,7 @@ class TestEnvironment {
321381
// Set the inputs before calling detectChanges to ensure they're available during ngOnInit
322382
this.hostComponent.editor = actualEditor;
323383
this.hostComponent.textModelConverter = textModelConverter;
384+
this.hostComponent.insightsEnabled = insightsEnabled;
324385

325386
this.fixture.detectChanges();
326387
this.component = this.hostComponent.component;
@@ -330,6 +391,11 @@ class TestEnvironment {
330391
this.editorReadySubject.next(ready);
331392
}
332393

394+
setInsightsEnabled(enabled: boolean): void {
395+
this.hostComponent.insightsEnabled = enabled;
396+
this.fixture.detectChanges();
397+
}
398+
333399
setFilteredInsights(insights: LynxInsight[]): void {
334400
this.filteredInsightsSubject.next(insights);
335401
}

src/SIL.XForge.Scripture/ClientApp/src/app/translate/editor/lynx/insights/lynx-insight-editor-objects/lynx-insight-editor-objects.component.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,10 @@ export class LynxInsightEditorObjectsComponent implements OnChanges, OnInit, OnD
127127
distinctUntilChanged(),
128128
switchMap(show => {
129129
if (!show) {
130+
// Clear any existing blots and overlays when insights are disabled
131+
this.insightRenderService.removeAllInsightFormatting(this.editor!);
132+
this.overlayService.close();
133+
this.insightState.clearDisplayState();
130134
return EMPTY;
131135
}
132136

src/SIL.XForge.Scripture/ClientApp/src/app/translate/editor/lynx/insights/lynx-insight-state.service.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,10 @@ export class LynxInsightStateService {
207207
}
208208

209209
clearDisplayState(): void {
210-
this.displayStateSource$.next({ activeInsightIds: [], cursorActiveInsightIds: [] });
210+
this.displayStateSource$.next({
211+
activeInsightIds: [],
212+
cursorActiveInsightIds: []
213+
});
211214
}
212215

213216
togglePanelVisibility(): void {

0 commit comments

Comments
 (0)