Skip to content

Commit aa1f7da

Browse files
committed
Improve test coverage
1 parent 9ff9a14 commit aa1f7da

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

src/SIL.XForge.Scripture/ClientApp/src/app/translate/editor/editor-draft/editor-draft.component.spec.ts

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,33 @@ describe('EditorDraftComponent', () => {
149149
expect(component.draftText.editor!.getContents().ops).toEqual(draftDelta.ops);
150150
}));
151151

152+
it('should support a timestamp earlier than the oldest draft', fakeAsync(() => {
153+
const testProjectDoc: SFProjectProfileDoc = {
154+
data: createTestProjectProfile()
155+
} as SFProjectProfileDoc;
156+
when(mockDraftGenerationService.draftExists(anything(), anything(), anything())).thenReturn(of(true));
157+
when(mockDraftGenerationService.getGeneratedDraftHistory(anything(), anything(), anything())).thenReturn(
158+
of(draftHistory)
159+
);
160+
when(mockActivatedProjectService.changes$).thenReturn(of(testProjectDoc));
161+
spyOn<any>(component, 'getTargetOps').and.returnValue(of(targetDelta.ops!));
162+
when(mockDraftHandlingService.getDraft(anything(), anything())).thenReturn(of(cloneDeep(draftDelta.ops!)));
163+
when(mockDraftHandlingService.draftDataToOps(anything(), anything())).thenReturn(draftDelta.ops!);
164+
when(mockDraftHandlingService.isDraftSegmentMap(anything())).thenReturn(false);
165+
166+
// Set the date to a time before the earliest draft
167+
fixture.componentInstance.timestamp = new Date('2024-03-22T03:02:01Z');
168+
169+
// SUT
170+
fixture.detectChanges();
171+
tick(EDITOR_READY_TIMEOUT);
172+
173+
verify(mockDraftHandlingService.getDraft(anything(), anything())).once();
174+
verify(mockDraftHandlingService.draftDataToOps(anything(), anything())).once();
175+
expect(component.draftCheckState).toEqual('draft-present');
176+
expect(component.draftText.editor!.getContents().ops).toEqual(draftDelta.ops);
177+
}));
178+
152179
it('should return ops and update the editor when no revision', fakeAsync(() => {
153180
const testProjectDoc: SFProjectProfileDoc = {
154181
data: createTestProjectProfile()

0 commit comments

Comments
 (0)