Skip to content

Commit cbb4b61

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

File tree

2 files changed

+104
-0
lines changed

2 files changed

+104
-0
lines changed

src/SIL.XForge.Scripture/ClientApp/src/app/translate/draft-generation/draft-history-list/draft-history-entry/draft-history-entry.component.spec.ts

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@ describe('DraftHistoryEntryComponent', () => {
109109
expect(component.buildRequestedByUserName).toBe('user-display-name');
110110
expect(component.buildRequestedByDate).toBe('formatted-date');
111111
expect(component.canDownloadBuild).toBe(true);
112+
expect(component.columnsToDisplay).toEqual(['bookNames', 'source', 'target']);
112113
expect(component.hasDetails).toBe(true);
113114
expect(component.entry).toBe(entry);
114115
expect(component.sourceLanguage).toBe('fr');
@@ -120,6 +121,52 @@ describe('DraftHistoryEntryComponent', () => {
120121
target: 'tar'
121122
}
122123
]);
124+
expect(component.trainingDataOpen).toBe(false);
125+
}));
126+
127+
it('should handle builds where the draft cannot be downloaded yet', fakeAsync(() => {
128+
when(mockedI18nService.localizeBook('GEN')).thenReturn('Genesis');
129+
when(mockedI18nService.localizeBook('EXO')).thenReturn('Exodus');
130+
const targetProjectDoc = {
131+
id: 'project01'
132+
} as SFProjectProfileDoc;
133+
when(mockedSFProjectService.getProfile('project01')).thenResolve(targetProjectDoc);
134+
const sourceProjectDoc = {
135+
id: 'project02'
136+
} as SFProjectProfileDoc;
137+
when(mockedSFProjectService.getProfile('project02')).thenResolve(sourceProjectDoc);
138+
const entry = {
139+
engine: {
140+
id: 'project01'
141+
},
142+
additionalInfo: {
143+
trainingScriptureRanges: [{ projectId: 'project02', scriptureRange: 'EXO' }],
144+
translationScriptureRanges: [{ projectId: 'project01', scriptureRange: 'GEN' }]
145+
}
146+
} as BuildDto;
147+
148+
// SUT
149+
component.entry = entry;
150+
tick();
151+
fixture.detectChanges();
152+
153+
expect(component.bookNames).toEqual(['Genesis']);
154+
expect(component.buildRequestedByUserName).toBeUndefined();
155+
expect(component.buildRequestedByDate).toBe('');
156+
expect(component.canDownloadBuild).toBe(false);
157+
expect(component.columnsToDisplay).toEqual(['bookNames', 'source', 'target']);
158+
expect(component.hasDetails).toBe(true);
159+
expect(component.entry).toBe(entry);
160+
expect(component.sourceLanguage).toBe('');
161+
expect(component.targetLanguage).toBe('');
162+
expect(component.trainingData).toEqual([
163+
{
164+
bookNames: ['Exodus'],
165+
source: '',
166+
target: ''
167+
}
168+
]);
169+
expect(component.trainingDataOpen).toBe(true);
123170
}));
124171

125172
it('should handle builds with additional info referencing a deleted user', fakeAsync(() => {

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

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,63 @@ 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+
179+
it('should support a timestamp close to the oldest draft', fakeAsync(() => {
180+
const testProjectDoc: SFProjectProfileDoc = {
181+
data: createTestProjectProfile()
182+
} as SFProjectProfileDoc;
183+
when(mockDraftGenerationService.draftExists(anything(), anything(), anything())).thenReturn(of(true));
184+
when(mockDraftGenerationService.getGeneratedDraftHistory(anything(), anything(), anything())).thenReturn(
185+
of(draftHistory)
186+
);
187+
when(mockActivatedProjectService.changes$).thenReturn(of(testProjectDoc));
188+
spyOn<any>(component, 'getTargetOps').and.returnValue(of(targetDelta.ops!));
189+
when(mockDraftHandlingService.getDraft(anything(), anything())).thenReturn(of(cloneDeep(draftDelta.ops!)));
190+
when(mockDraftHandlingService.draftDataToOps(anything(), anything())).thenReturn(draftDelta.ops!);
191+
when(mockDraftHandlingService.isDraftSegmentMap(anything())).thenReturn(false);
192+
193+
// Set the date to a time just before the earliest draft
194+
// This will account for the delay in storing the draft
195+
const timestamp = new Date(draftHistory[0].timestamp);
196+
timestamp.setMinutes(timestamp.getMinutes() - 10);
197+
fixture.componentInstance.timestamp = timestamp;
198+
199+
// SUT
200+
fixture.detectChanges();
201+
tick(EDITOR_READY_TIMEOUT);
202+
203+
verify(mockDraftHandlingService.getDraft(anything(), anything())).once();
204+
verify(mockDraftHandlingService.draftDataToOps(anything(), anything())).once();
205+
expect(component.draftCheckState).toEqual('draft-present');
206+
expect(component.draftText.editor!.getContents().ops).toEqual(draftDelta.ops);
207+
}));
208+
152209
it('should return ops and update the editor when no revision', fakeAsync(() => {
153210
const testProjectDoc: SFProjectProfileDoc = {
154211
data: createTestProjectProfile()

0 commit comments

Comments
 (0)