From b9268e3310514c2dddc850f60978f692fa9b699b Mon Sep 17 00:00:00 2001 From: Raymond Luong Date: Wed, 4 Dec 2024 13:35:54 -0700 Subject: [PATCH] Add and adjusts tests --- .../book-multi-select.component.html | 2 +- .../book-multi-select.component.spec.ts | 11 ++ .../draft-generation-steps.component.html | 4 +- .../draft-generation-steps.component.spec.ts | 121 ++++++++++++++++-- .../draft-generation-steps.component.ts | 20 +-- .../draft-generation.component.spec.ts | 24 ---- .../draft-generation.component.ts | 2 - .../draft-generation.service.spec.ts | 2 - .../draft-generation/draft-generation.ts | 2 - .../draft-sources.service.spec.ts | 98 +++++++------- .../draft-generation/draft-sources.service.ts | 10 +- 11 files changed, 195 insertions(+), 101 deletions(-) diff --git a/src/SIL.XForge.Scripture/ClientApp/src/app/shared/book-multi-select/book-multi-select.component.html b/src/SIL.XForge.Scripture/ClientApp/src/app/shared/book-multi-select/book-multi-select.component.html index e656c10d13..0d2f66b464 100644 --- a/src/SIL.XForge.Scripture/ClientApp/src/app/shared/book-multi-select/book-multi-select.component.html +++ b/src/SIL.XForge.Scripture/ClientApp/src/app/shared/book-multi-select/book-multi-select.component.html @@ -1,6 +1,6 @@ @if (availableBooks.length > 0 && !readonly && !basicMode) { -
+
{ expect(component.partialOT).toBe(false); expect(component.partialDC).toBe(true); }); + + it('can hide checkboxes and progress in basic mode', async () => { + await component.ngOnChanges(); + fixture.detectChanges(); + expect(fixture.nativeElement.querySelector('.book-multi-select .border-fill')).not.toBeNull(); + expect(fixture.nativeElement.querySelector('.scope-selection')).not.toBeNull(); + component.basicMode = true; + fixture.detectChanges(); + expect(fixture.nativeElement.querySelector('.book-multi-select .border-fill')).toBeNull(); + expect(fixture.nativeElement.querySelector('.scope-selection')).toBeNull(); + }); }); diff --git a/src/SIL.XForge.Scripture/ClientApp/src/app/translate/draft-generation/draft-generation-steps/draft-generation-steps.component.html b/src/SIL.XForge.Scripture/ClientApp/src/app/translate/draft-generation/draft-generation-steps/draft-generation-steps.component.html index 31e5fce9bf..27fbf9f329 100644 --- a/src/SIL.XForge.Scripture/ClientApp/src/app/translate/draft-generation/draft-generation-steps/draft-generation-steps.component.html +++ b/src/SIL.XForge.Scripture/ClientApp/src/app/translate/draft-generation/draft-generation-steps/draft-generation-steps.component.html @@ -107,11 +107,11 @@

}

{{ t("reference_books") }}

{{ trainingSourceProjectName }}

- @if (selectableTrainingBooks.length === 0) { + @if (selectableSourceTrainingBooks.length === 0) { {{ t("training_books_will_appear") }} } @else { { component.userSelectedTrainingBooks = trainingBooks; component.userSelectedTranslateBooks = translationBooks; component.selectedTrainingDataIds = trainingDataFiles; + component.userSelectedSourceTrainingBooks = trainingBooks; + component['draftSourceProjectIds'] = { draftingSourceId: 'sourceProject', trainingSourceId: 'sourceProject' }; spyOn(component.done, 'emit'); expect(component.isStepsCompleted).toBe(false); @@ -238,11 +240,9 @@ describe('DraftGenerationStepsComponent', () => { fixture.detectChanges(); expect(component.done.emit).toHaveBeenCalledWith({ - trainingBooks: trainingBooks.filter(book => !translationBooks.includes(book)), trainingDataFiles, - trainingScriptureRanges: [], - translationBooks, - translationScriptureRanges: [], + trainingScriptureRanges: [{ projectId: 'sourceProject', scriptureRange: 'LEV' }], + translationScriptureRanges: [{ projectId: 'sourceProject', scriptureRange: 'GEN;EXO' }], fastTraining: false } as DraftGenerationStepsResult); expect(component.isStepsCompleted).toBe(true); @@ -294,6 +294,111 @@ describe('DraftGenerationStepsComponent', () => { })); }); + describe('additional training source project', () => { + beforeEach(fakeAsync(() => { + const mockTargetProjectDoc = { + data: createTestProjectProfile({ + texts: [{ bookNum: 1 }, { bookNum: 2 }, { bookNum: 3 }, { bookNum: 6 }, { bookNum: 7 }], + translateConfig: { + source: { projectRef: 'sourceProject' }, + draftConfig: { + additionalTrainingSourceEnabled: true, + additionalTrainingSource: { projectRef: 'sourceProject2' } + } + } + }) + } as SFProjectProfileDoc; + when(mockActivatedProjectService.projectDoc).thenReturn(mockTargetProjectDoc); + when(mockActivatedProjectService.projectDoc$).thenReturn(targetProjectDoc$); + when(mockFeatureFlagService.allowFastTraining).thenReturn(createTestFeatureFlag(false)); + when(mockProjectService.getProfile(anything())).thenResolve(mockSourceNonNllbProjectDoc); + when(mockNllbLanguageService.isNllbLanguageAsync(anything())).thenResolve(true); + when(mockNllbLanguageService.isNllbLanguageAsync('xyz')).thenResolve(false); + when(mockTrainingDataService.queryTrainingDataAsync(anything())).thenResolve(instance(mockTrainingDataQuery)); + when(mockTrainingDataQuery.docs).thenReturn([]); + + fixture = TestBed.createComponent(DraftGenerationStepsComponent); + component = fixture.componentInstance; + tick(); + fixture.detectChanges(); + })); + + it('should show and hide selectable training source books when training books selected', () => { + const trainingBooks = [3]; + const trainingDataFiles: string[] = []; + const translationBooks = [1, 2]; + const availableBooks = [1, 2, 3]; + + component.userSelectedTrainingBooks = []; + component.userSelectedTranslateBooks = translationBooks; + component.selectedTrainingDataIds = trainingDataFiles; + component.userSelectedSourceTrainingBooks = []; + component.userSelectedAdditionalSourceTrainingBooks = []; + component['availableAdditionalTrainingBooks'] = availableBooks; + component['draftSourceProjectIds'] = { + draftingSourceId: 'sourceProject', + trainingSourceId: 'sourceProject', + trainingAdditionalSourceId: 'sourceProject2' + }; + expect(component.availableTrainingBooks).toEqual(availableBooks); + expect(component.selectableSourceTrainingBooks).toEqual([]); + expect(component.selectableAdditionalTrainingBooks).toEqual([]); + + // select a training book + component.onTrainingBookSelect(trainingBooks); + fixture.detectChanges(); + expect(component.selectableSourceTrainingBooks).toEqual(trainingBooks); + expect(component.selectableAdditionalTrainingBooks).toEqual(trainingBooks); + expect(component.userSelectedSourceTrainingBooks).toEqual(trainingBooks); + expect(component.userSelectedAdditionalSourceTrainingBooks).toEqual(trainingBooks); + + // deselect all training books + component.onTrainingBookSelect([]); + fixture.detectChanges(); + expect(component.selectableSourceTrainingBooks).toEqual([]); + expect(component.selectableAdditionalTrainingBooks).toEqual([]); + expect(component.userSelectedSourceTrainingBooks).toEqual([]); + expect(component.userSelectedAdditionalSourceTrainingBooks).toEqual([]); + }); + + it('should correctly emit the selected books when done', () => { + const trainingBooks = [3]; + const trainingDataFiles: string[] = []; + const translationBooks = [1, 2]; + + component.userSelectedTrainingBooks = trainingBooks; + component.userSelectedTranslateBooks = translationBooks; + component.selectedTrainingDataIds = trainingDataFiles; + component.userSelectedSourceTrainingBooks = trainingBooks; + component.userSelectedAdditionalSourceTrainingBooks = trainingBooks; + component['draftSourceProjectIds'] = { + draftingSourceId: 'sourceProject', + trainingSourceId: 'sourceProject', + trainingAdditionalSourceId: 'sourceProject2' + }; + + spyOn(component.done, 'emit'); + expect(component.isStepsCompleted).toBe(false); + // Advance to the next step when at last step should emit books result + fixture.detectChanges(); + component.tryAdvanceStep(); + fixture.detectChanges(); + component.tryAdvanceStep(); + fixture.detectChanges(); + + expect(component.done.emit).toHaveBeenCalledWith({ + trainingDataFiles, + trainingScriptureRanges: [ + { projectId: 'sourceProject', scriptureRange: 'LEV' }, + { projectId: 'sourceProject2', scriptureRange: 'LEV' } + ], + translationScriptureRanges: [{ projectId: 'sourceProject', scriptureRange: 'GEN;EXO' }], + fastTraining: false + } as DraftGenerationStepsResult); + expect(component.isStepsCompleted).toBe(true); + }); + }); + describe('allow fast training feature flag is enabled', () => { beforeEach(fakeAsync(() => { when(mockActivatedProjectService.projectDoc).thenReturn(mockTargetProjectDoc); @@ -317,6 +422,8 @@ describe('DraftGenerationStepsComponent', () => { component.userSelectedTrainingBooks = trainingBooks; component.userSelectedTranslateBooks = translationBooks; component.selectedTrainingDataIds = trainingDataFiles; + component.userSelectedSourceTrainingBooks = trainingBooks; + component['draftSourceProjectIds'] = { draftingSourceId: 'sourceProject', trainingSourceId: 'sourceProject' }; spyOn(component.done, 'emit'); @@ -338,11 +445,9 @@ describe('DraftGenerationStepsComponent', () => { fixture.detectChanges(); expect(component.done.emit).toHaveBeenCalledWith({ - trainingBooks, trainingDataFiles, - trainingScriptureRanges: [], - translationBooks, - translationScriptureRanges: [], + trainingScriptureRanges: [{ projectId: 'sourceProject', scriptureRange: 'GEN;EXO' }], + translationScriptureRanges: [{ projectId: 'sourceProject', scriptureRange: 'LEV;NUM' }], fastTraining: true } as DraftGenerationStepsResult); expect(generateDraftButton['disabled']).toBe(true); diff --git a/src/SIL.XForge.Scripture/ClientApp/src/app/translate/draft-generation/draft-generation-steps/draft-generation-steps.component.ts b/src/SIL.XForge.Scripture/ClientApp/src/app/translate/draft-generation/draft-generation-steps/draft-generation-steps.component.ts index 2ed3b162ed..cca7a2e255 100644 --- a/src/SIL.XForge.Scripture/ClientApp/src/app/translate/draft-generation/draft-generation-steps/draft-generation-steps.component.ts +++ b/src/SIL.XForge.Scripture/ClientApp/src/app/translate/draft-generation/draft-generation-steps/draft-generation-steps.component.ts @@ -25,11 +25,9 @@ import { TrainingDataUploadDialogComponent } from '../training-data/training-dat import { TrainingDataService } from '../training-data/training-data.service'; export interface DraftGenerationStepsResult { - trainingBooks: number[]; trainingDataFiles: string[]; trainingScriptureRange?: string; trainingScriptureRanges: ProjectScriptureRange[]; - translationBooks: number[]; translationScriptureRange?: string; translationScriptureRanges: ProjectScriptureRange[]; fastTraining: boolean; @@ -57,7 +55,7 @@ export class DraftGenerationStepsComponent extends SubscriptionDisposable implem availableTranslateBooks?: number[] = undefined; availableTrainingBooks: number[] = []; - selectableTrainingBooks: number[] = []; + selectableSourceTrainingBooks: number[] = []; selectableAdditionalTrainingBooks: number[] = []; availableTrainingData: Readonly[] = []; @@ -245,10 +243,18 @@ export class DraftGenerationStepsComponent extends SubscriptionDisposable implem onTrainingBookSelect(selectedBooks: number[]): void { const newBookSelections: number[] = selectedBooks.filter(b => !this.userSelectedTrainingBooks.includes(b)); this.userSelectedTrainingBooks = selectedBooks; - this.selectableTrainingBooks = selectedBooks; + this.selectableSourceTrainingBooks = selectedBooks; this.selectableAdditionalTrainingBooks = this.availableAdditionalTrainingBooks.filter(b => selectedBooks.includes(b) ); + + // remove selected books that are no longer selectable + this.userSelectedSourceTrainingBooks = this.userSelectedSourceTrainingBooks.filter(b => selectedBooks.includes(b)); + this.userSelectedAdditionalSourceTrainingBooks = this.userSelectedAdditionalSourceTrainingBooks.filter(b => + selectedBooks.includes(b) + ); + + // automatically select books that are newly selected as training books for (const bookNum of newBookSelections) { this.userSelectedSourceTrainingBooks.push(bookNum); if (this.selectableAdditionalTrainingBooks.includes(bookNum)) { @@ -314,11 +320,8 @@ export class DraftGenerationStepsComponent extends SubscriptionDisposable implem this.userSelectedTranslateBooks ); this.done.emit({ - // TODO: Can trainingBooks and translationBooks be removed? - trainingBooks: this.userSelectedTrainingBooks, trainingScriptureRanges, trainingDataFiles: this.selectedTrainingDataIds, - translationBooks: this.userSelectedTranslateBooks, translationScriptureRanges: [translationScriptureRange], fastTraining: this.fastTraining }); @@ -343,7 +346,8 @@ export class DraftGenerationStepsComponent extends SubscriptionDisposable implem this.initialSelectedTrainingBooks = newSelectedTrainingBooks; this.userSelectedTrainingBooks = [...newSelectedTrainingBooks]; - this.selectableTrainingBooks = [...newSelectedTrainingBooks]; + this.userSelectedSourceTrainingBooks = [...newSelectedTrainingBooks]; + this.selectableSourceTrainingBooks = [...newSelectedTrainingBooks]; this.selectableAdditionalTrainingBooks = this.availableAdditionalTrainingBooks.filter(b => newSelectedTrainingBooks.includes(b) ); diff --git a/src/SIL.XForge.Scripture/ClientApp/src/app/translate/draft-generation/draft-generation.component.spec.ts b/src/SIL.XForge.Scripture/ClientApp/src/app/translate/draft-generation/draft-generation.component.spec.ts index 9fc12a10f1..00aebd74b9 100644 --- a/src/SIL.XForge.Scripture/ClientApp/src/app/translate/draft-generation/draft-generation.component.spec.ts +++ b/src/SIL.XForge.Scripture/ClientApp/src/app/translate/draft-generation/draft-generation.component.spec.ts @@ -1966,10 +1966,8 @@ describe('DraftGenerationComponent', () => { env.component.currentPage = 'steps'; env.component.startBuild({ - trainingBooks: [], trainingDataFiles: [], trainingScriptureRanges: [], - translationBooks: [], translationScriptureRanges: [], fastTraining: false, projectId: projectId @@ -1978,10 +1976,8 @@ describe('DraftGenerationComponent', () => { expect(env.component.currentPage).toBe('steps'); expect(mockDraftGenerationService.startBuildOrGetActiveBuild).toHaveBeenCalledWith({ projectId: projectId, - trainingBooks: [], trainingDataFiles: [], trainingScriptureRanges: [], - translationBooks: [], translationScriptureRanges: [], fastTraining: false }); @@ -1997,10 +1993,8 @@ describe('DraftGenerationComponent', () => { env.component.cancelDialogRef = instance(mockDialogRef); env.component.startBuild({ - trainingBooks: [], trainingDataFiles: [], trainingScriptureRanges: [], - translationBooks: [], translationScriptureRanges: [], fastTraining: false, projectId: projectId @@ -2008,10 +2002,8 @@ describe('DraftGenerationComponent', () => { env.startedOrActiveBuild$.next({ ...buildDto, state: BuildStates.Queued }); expect(mockDraftGenerationService.startBuildOrGetActiveBuild).toHaveBeenCalledWith({ projectId: projectId, - trainingBooks: [], trainingDataFiles: [], trainingScriptureRanges: [], - translationBooks: [], translationScriptureRanges: [], fastTraining: false }); @@ -2026,10 +2018,8 @@ describe('DraftGenerationComponent', () => { env.component.cancelDialogRef = instance(mockDialogRef); env.component.startBuild({ - trainingBooks: [], trainingDataFiles: [], trainingScriptureRanges: [], - translationBooks: [], translationScriptureRanges: [], fastTraining: false, projectId: projectId @@ -2037,10 +2027,8 @@ describe('DraftGenerationComponent', () => { env.startedOrActiveBuild$.next({ ...buildDto, state: BuildStates.Pending }); expect(mockDraftGenerationService.startBuildOrGetActiveBuild).toHaveBeenCalledWith({ projectId: projectId, - trainingBooks: [], trainingDataFiles: [], trainingScriptureRanges: [], - translationBooks: [], translationScriptureRanges: [], fastTraining: false }); @@ -2055,10 +2043,8 @@ describe('DraftGenerationComponent', () => { env.component.cancelDialogRef = instance(mockDialogRef); env.component.startBuild({ - trainingBooks: [], trainingDataFiles: [], trainingScriptureRanges: [], - translationBooks: [], translationScriptureRanges: [], fastTraining: false, projectId: projectId @@ -2066,10 +2052,8 @@ describe('DraftGenerationComponent', () => { env.startedOrActiveBuild$.next({ ...buildDto, state: BuildStates.Active }); expect(mockDraftGenerationService.startBuildOrGetActiveBuild).toHaveBeenCalledWith({ projectId: projectId, - trainingBooks: [], trainingDataFiles: [], trainingScriptureRanges: [], - translationBooks: [], translationScriptureRanges: [], fastTraining: false }); @@ -2085,10 +2069,8 @@ describe('DraftGenerationComponent', () => { env.component.cancelDialogRef = instance(mockDialogRef); env.component.startBuild({ - trainingBooks: [], trainingDataFiles: [], trainingScriptureRanges: [], - translationBooks: [], translationScriptureRanges: [], fastTraining: false, projectId: projectId @@ -2096,10 +2078,8 @@ describe('DraftGenerationComponent', () => { env.startedOrActiveBuild$.next({ ...buildDto, state: BuildStates.Canceled }); expect(mockDraftGenerationService.startBuildOrGetActiveBuild).toHaveBeenCalledWith({ projectId: projectId, - trainingBooks: [], trainingDataFiles: [], trainingScriptureRanges: [], - translationBooks: [], translationScriptureRanges: [], fastTraining: false }); @@ -2114,10 +2094,8 @@ describe('DraftGenerationComponent', () => { }); env.component.startBuild({ - trainingBooks: [], trainingDataFiles: [], trainingScriptureRanges: [], - translationBooks: [], translationScriptureRanges: [], fastTraining: false, projectId: projectId @@ -2126,10 +2104,8 @@ describe('DraftGenerationComponent', () => { expect(mockDraftGenerationService.startBuildOrGetActiveBuild).toHaveBeenCalledWith({ projectId: projectId, - trainingBooks: [], trainingDataFiles: [], trainingScriptureRanges: [], - translationBooks: [], translationScriptureRanges: [], fastTraining: false }); diff --git a/src/SIL.XForge.Scripture/ClientApp/src/app/translate/draft-generation/draft-generation.component.ts b/src/SIL.XForge.Scripture/ClientApp/src/app/translate/draft-generation/draft-generation.component.ts index cbc55533fe..5d20d957d5 100644 --- a/src/SIL.XForge.Scripture/ClientApp/src/app/translate/draft-generation/draft-generation.component.ts +++ b/src/SIL.XForge.Scripture/ClientApp/src/app/translate/draft-generation/draft-generation.component.ts @@ -445,11 +445,9 @@ export class DraftGenerationComponent extends DataLoadingComponent implements On onPreGenerationStepsComplete(result: DraftGenerationStepsResult): void { this.startBuild({ projectId: this.activatedProject.projectId!, - trainingBooks: result.trainingBooks, trainingDataFiles: result.trainingDataFiles, trainingScriptureRange: result.trainingScriptureRange, trainingScriptureRanges: result.trainingScriptureRanges, - translationBooks: result.translationBooks, translationScriptureRange: result.translationScriptureRange, translationScriptureRanges: result.trainingScriptureRanges, fastTraining: result.fastTraining diff --git a/src/SIL.XForge.Scripture/ClientApp/src/app/translate/draft-generation/draft-generation.service.spec.ts b/src/SIL.XForge.Scripture/ClientApp/src/app/translate/draft-generation/draft-generation.service.spec.ts index 1599ff8542..40ecd6e6f7 100644 --- a/src/SIL.XForge.Scripture/ClientApp/src/app/translate/draft-generation/draft-generation.service.spec.ts +++ b/src/SIL.XForge.Scripture/ClientApp/src/app/translate/draft-generation/draft-generation.service.spec.ts @@ -41,10 +41,8 @@ describe('DraftGenerationService', () => { const projectId = 'testProjectId'; const buildConfig: BuildConfig = { projectId, - trainingBooks: [], trainingDataFiles: [], translationScriptureRanges: [], - translationBooks: [], trainingScriptureRanges: [], fastTraining: false }; diff --git a/src/SIL.XForge.Scripture/ClientApp/src/app/translate/draft-generation/draft-generation.ts b/src/SIL.XForge.Scripture/ClientApp/src/app/translate/draft-generation/draft-generation.ts index 8e08feafdb..b876724e71 100644 --- a/src/SIL.XForge.Scripture/ClientApp/src/app/translate/draft-generation/draft-generation.ts +++ b/src/SIL.XForge.Scripture/ClientApp/src/app/translate/draft-generation/draft-generation.ts @@ -6,11 +6,9 @@ import { BuildStates } from '../../machine-api/build-states'; */ export interface BuildConfig { projectId: string; - trainingBooks: number[]; trainingDataFiles: string[]; trainingScriptureRange?: string; trainingScriptureRanges: ProjectScriptureRange[]; - translationBooks: number[]; translationScriptureRange?: string; translationScriptureRanges: ProjectScriptureRange[]; fastTraining: boolean; diff --git a/src/SIL.XForge.Scripture/ClientApp/src/app/translate/draft-generation/draft-sources.service.spec.ts b/src/SIL.XForge.Scripture/ClientApp/src/app/translate/draft-generation/draft-sources.service.spec.ts index ae0b6ee85e..154c595739 100644 --- a/src/SIL.XForge.Scripture/ClientApp/src/app/translate/draft-generation/draft-sources.service.spec.ts +++ b/src/SIL.XForge.Scripture/ClientApp/src/app/translate/draft-generation/draft-sources.service.spec.ts @@ -11,7 +11,7 @@ import { UserService } from 'xforge-common/user.service'; import { environment } from '../../../environments/environment'; import { SFProjectProfileDoc } from '../../core/models/sf-project-profile-doc'; import { SFProjectService } from '../../core/sf-project.service'; -import { DraftSources, DraftSourcesService } from './draft-sources.service'; +import { DraftSource, DraftSources, DraftSourcesService } from './draft-sources.service'; describe('DraftSourcesService', () => { let service: DraftSourcesService; @@ -45,7 +45,14 @@ describe('DraftSourcesService', () => { source: undefined, alternateSource: undefined, alternateTrainingSource: undefined, - additionalTrainingSource: undefined + additionalTrainingSource: undefined, + draftSourceIds: { + draftingSourceId: undefined, + draftingAlternateSourceId: undefined, + trainingSourceId: undefined, + trainingAlternateSourceId: undefined, + trainingAdditionalSourceId: undefined + } } as DraftSources); done(); }); @@ -141,6 +148,13 @@ describe('DraftSourcesService', () => { tag: 'en_UK' }, noAccess: true + }, + draftSourceIds: { + draftingSourceId: 'source_project', + draftingAlternateSourceId: 'alternate_source_project', + trainingSourceId: 'source_project', + trainingAlternateSourceId: 'alternate_training_source_project', + trainingAdditionalSourceId: 'additional_training_source_project' } } as DraftSources); done(); @@ -242,7 +256,14 @@ describe('DraftSourcesService', () => { source: sourceProject, alternateSource: alternateSourceProject, alternateTrainingSource: alternateTrainingSourceProject, - additionalTrainingSource: additionalTrainingSourceProject + additionalTrainingSource: additionalTrainingSourceProject, + draftSourceIds: { + draftingSourceId: 'source_project', + draftingAlternateSourceId: 'alternate_source_project', + trainingSourceId: 'source_project', + trainingAlternateSourceId: 'alternate_training_source_project', + trainingAdditionalSourceId: 'additional_training_source_project' + } } as DraftSources); done(); }); @@ -271,13 +292,7 @@ describe('DraftSourcesService', () => { ); service.getDraftProjectSources().subscribe(result => { - expect(result).toEqual({ - target: targetProject, - source: undefined, - alternateSource: undefined, - alternateTrainingSource: undefined, - additionalTrainingSource: undefined - } as DraftSources); + expectTargetOnly(targetProject, result); done(); }); }); @@ -286,7 +301,7 @@ describe('DraftSourcesService', () => { const targetProject = createTestProjectProfile({ translateConfig: { draftConfig: { - alternateSourceEnabled: false + alternateSourceEnabled: true } } }); @@ -297,13 +312,7 @@ describe('DraftSourcesService', () => { ); service.getDraftProjectSources().subscribe(result => { - expect(result).toEqual({ - target: targetProject, - source: undefined, - alternateSource: undefined, - alternateTrainingSource: undefined, - additionalTrainingSource: undefined - } as DraftSources); + expectTargetOnly(targetProject, result); done(); }); }); @@ -331,13 +340,7 @@ describe('DraftSourcesService', () => { ); service.getDraftProjectSources().subscribe(result => { - expect(result).toEqual({ - target: targetProject, - source: undefined, - alternateSource: undefined, - alternateTrainingSource: undefined, - additionalTrainingSource: undefined - } as DraftSources); + expectTargetOnly(targetProject, result); done(); }); }); @@ -346,7 +349,7 @@ describe('DraftSourcesService', () => { const targetProject = createTestProjectProfile({ translateConfig: { draftConfig: { - alternateTrainingSourceEnabled: false + alternateTrainingSourceEnabled: true } } }); @@ -357,13 +360,7 @@ describe('DraftSourcesService', () => { ); service.getDraftProjectSources().subscribe(result => { - expect(result).toEqual({ - target: targetProject, - source: undefined, - alternateSource: undefined, - alternateTrainingSource: undefined, - additionalTrainingSource: undefined - } as DraftSources); + expectTargetOnly(targetProject, result); done(); }); }); @@ -391,13 +388,7 @@ describe('DraftSourcesService', () => { ); service.getDraftProjectSources().subscribe(result => { - expect(result).toEqual({ - target: targetProject, - source: undefined, - alternateSource: undefined, - alternateTrainingSource: undefined, - additionalTrainingSource: undefined - } as DraftSources); + expectTargetOnly(targetProject, result); done(); }); }); @@ -406,7 +397,7 @@ describe('DraftSourcesService', () => { const targetProject = createTestProjectProfile({ translateConfig: { draftConfig: { - additionalTrainingSourceEnabled: false + additionalTrainingSourceEnabled: true } } }); @@ -417,15 +408,26 @@ describe('DraftSourcesService', () => { ); service.getDraftProjectSources().subscribe(result => { - expect(result).toEqual({ - target: targetProject, - source: undefined, - alternateSource: undefined, - alternateTrainingSource: undefined, - additionalTrainingSource: undefined - } as DraftSources); + expectTargetOnly(targetProject, result); done(); }); }); }); + + function expectTargetOnly(targetProject: DraftSource, result: DraftSources): void { + expect(result).toEqual({ + target: targetProject, + source: undefined, + alternateSource: undefined, + alternateTrainingSource: undefined, + additionalTrainingSource: undefined, + draftSourceIds: { + draftingSourceId: undefined, + draftingAlternateSourceId: undefined, + trainingSourceId: undefined, + trainingAlternateSourceId: undefined, + trainingAdditionalSourceId: undefined + } + } as DraftSources); + } }); diff --git a/src/SIL.XForge.Scripture/ClientApp/src/app/translate/draft-generation/draft-sources.service.ts b/src/SIL.XForge.Scripture/ClientApp/src/app/translate/draft-generation/draft-sources.service.ts index 7ee80895d6..f99ecf2762 100644 --- a/src/SIL.XForge.Scripture/ClientApp/src/app/translate/draft-generation/draft-sources.service.ts +++ b/src/SIL.XForge.Scripture/ClientApp/src/app/translate/draft-generation/draft-sources.service.ts @@ -25,10 +25,11 @@ interface DraftSourceDoc { } export interface DraftSourceIds { - trainingSourceId: string; + trainingSourceId?: string; trainingAlternateSourceId?: string; trainingAdditionalSourceId?: string; - draftingSourceId: string; + draftingSourceId?: string; + draftingAlternateSourceId?: string; } export interface DraftSources { @@ -129,9 +130,10 @@ export class DraftSourcesService { additionalTrainingSource: additionalTrainingSourceProjectDoc?.data, draftSourceIds: { trainingSourceId: sourceProjectId, - trainingAlternateSourceId: alternateSourceProjectId, + trainingAlternateSourceId: alternateTrainingSourceProjectId, trainingAdditionalSourceId: additionalTrainingSourceProjectId, - draftingSourceId: alternateSourceProjectId ?? sourceProjectId + draftingSourceId: sourceProjectId, + draftingAlternateSourceId: alternateSourceProjectId } }; })