Skip to content

Commit c5977f1

Browse files
committed
Review comments
1 parent fb9c1c3 commit c5977f1

File tree

3 files changed

+26
-10
lines changed

3 files changed

+26
-10
lines changed

src/SIL.XForge.Scripture/ClientApp/src/app/translate/draft-generation/draft-generation.service.spec.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,23 @@ describe('DraftGenerationService', () => {
225225
});
226226
tick();
227227
}));
228+
229+
it('should return undefined and show error when server returns 500', fakeAsync(() => {
230+
// SUT
231+
service.getLastPreTranslationBuild(projectId).subscribe(result => {
232+
expect(result).toBeUndefined();
233+
verify(mockNoticeService.showError(anything())).once();
234+
});
235+
tick();
236+
237+
// Setup the HTTP request
238+
const req = httpTestingController.expectOne(
239+
`${MACHINE_API_BASE_URL}translation/engines/project:${projectId}/actions/getLastPreTranslationBuild`
240+
);
241+
expect(req.request.method).toEqual('GET');
242+
req.flush(null, { status: HttpStatusCode.InternalServerError, statusText: 'Server Error' });
243+
tick();
244+
}));
228245
});
229246

230247
describe('getBuildHistory', () => {

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

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -327,21 +327,20 @@ export class EditorDraftComponent implements AfterViewInit, OnChanges {
327327
}),
328328
filter(([isOnline, _]) => {
329329
return isOnline && this.doesLatestCompletedHaveDraft;
330+
}),
331+
switchMap(() => this.refreshLastPreTranslationBuild()),
332+
tap((build: BuildDto | undefined) => {
333+
this._latestPreTranslationBuild = build;
330334
})
331335
)
332-
.subscribe(() => this.refreshLastPreTranslationBuild());
336+
.subscribe();
333337
}
334338

335-
private refreshLastPreTranslationBuild(): void {
339+
private refreshLastPreTranslationBuild(): Observable<BuildDto | undefined> {
336340
if (this.projectId == null) {
337-
return;
341+
return of<BuildDto | undefined>(undefined);
338342
}
339-
this.draftGenerationService
340-
.getLastPreTranslationBuild(this.projectId)
341-
.pipe(quietTakeUntilDestroyed(this.destroyRef), take(1))
342-
.subscribe((build: BuildDto | undefined) => {
343-
this._latestPreTranslationBuild = build;
344-
});
343+
return this.draftGenerationService.getLastPreTranslationBuild(this.projectId).pipe(take(1));
345344
}
346345

347346
navigateToFormatting(): void {

test/SIL.XForge.Scripture.Tests/Services/MachineApiServiceTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2087,7 +2087,7 @@ public async Task GetLastPreTranslationBuildAsync_LatestByDateFinished_Success()
20872087
Message = MachineApiService.BuildStateCompleted,
20882088
Progress = 100,
20892089
Revision = 11,
2090-
State = JobState.Completed,
2090+
State = JobState.Canceled,
20912091
DateFinished = now.AddMinutes(-5),
20922092
};
20932093
env.TranslationEnginesClient.GetAllBuildsAsync(TranslationEngine01, CancellationToken.None)

0 commit comments

Comments
 (0)