Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -1100,90 +1100,6 @@ describe('DraftGenerationStepsComponent', () => {
});
});

describe('target contains previously selected books', () => {
const availableBooks = [{ bookNum: 2 }, { bookNum: 3 }];
const allBooks = [{ bookNum: 1 }, ...availableBooks, { bookNum: 4 }];
const draftingSourceBooks = availableBooks.concat({ bookNum: 5 });
const draftingSourceId = 'draftingSource';
const config = {
trainingSources: [
{
projectRef: 'source1',
shortName: 'sP1',
writingSystem: { tag: 'eng' },
texts: availableBooks.concat({ bookNum: 1 })
},
{
projectRef: 'source2',
shortName: 'sP2',
writingSystem: { tag: 'eng' },
texts: availableBooks
}
] as [DraftSource, DraftSource],
trainingTargets: [
{
projectRef: projectId,
shortName: 'tT',
writingSystem: { tag: 'nllb' },
texts: allBooks.filter(b => b.bookNum !== 4)
}
] as [DraftSource],
draftingSources: [
{
projectRef: draftingSourceId,
shortName: 'dS',
writingSystem: { tag: 'eng' },
texts: draftingSourceBooks
}
] as [DraftSource]
};

const mockTargetProjectDoc = {
id: 'project01',
data: createTestProjectProfile({
texts: [{ bookNum: 1 }, { bookNum: 2 }, { bookNum: 3 }],
translateConfig: {
draftConfig: {
lastSelectedTrainingDataFiles: [],
lastSelectedTrainingScriptureRanges: [
{ projectId: 'source1', scriptureRange: 'GEN;1SA' },
{ projectId: 'source2', scriptureRange: '1SA;2SA' }
],
lastSelectedTranslationScriptureRanges: [{ projectId: 'draftingSource', scriptureRange: 'EXO;LEV' }]
}
}
})
} as SFProjectProfileDoc;

beforeEach(fakeAsync(() => {
when(mockDraftSourceService.getDraftProjectSources()).thenReturn(of(config));
when(mockActivatedProjectService.projectDoc).thenReturn(mockTargetProjectDoc);
when(mockActivatedProjectService.projectDoc$).thenReturn(of(mockTargetProjectDoc));
setupProjectProfileMock(
draftingSourceId,
draftingSourceBooks.map(b => b.bookNum)
);
when(mockFeatureFlagService.showDeveloperTools).thenReturn(createTestFeatureFlag(false));

fixture = TestBed.createComponent(DraftGenerationStepsComponent);
component = fixture.componentInstance;
fixture.detectChanges();
tick();
}));

it('should restore previously selected ranges', () => {
expect(component.selectedTranslateBooksAsString()).toEqual('Exodus and Leviticus');
expect(component.booksToTranslate()).toEqual([
{ number: 2, selected: true },
{ number: 3, selected: true }
]);
expect(component.selectedTrainingBooksByProj('project01')).toEqual([{ number: 1, selected: true }]);
//for source1, Genesis was previously selected, but it's no longer present on both source and target
expect(component.selectedTrainingBooksByProj('source1')).toEqual([{ number: 1, selected: true }]);
expect(component.selectedTrainingBooksByProj('source2')).toEqual([]);
});
});

describe('can add additional training data', () => {
const availableBooks = [{ bookNum: 2 }, { bookNum: 3 }];
const draftingSourceId = 'draftingSource';
Expand Down Expand Up @@ -1403,6 +1319,8 @@ describe('DraftGenerationStepsComponent', () => {
}));

it('should localize and concatenate the books to translate', () => {
expect(component.selectedTranslateBooksAsString()).toEqual('');
component.onTranslateBookSelect([3], config.draftingSources[0]);
expect(component.selectedTranslateBooksAsString()).toEqual('Leviticus');
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -368,7 +368,6 @@ export class DraftGenerationStepsComponent implements OnInit {
}

this.setInitialTrainingBooks(projectId!);
this.setInitialTranslateBooks();

// Store the books that are not in the target
this.unusableTrainingTargetBooks = [...trainingSourceBooks].filter(
Expand Down Expand Up @@ -694,23 +693,6 @@ export class DraftGenerationStepsComponent implements OnInit {
this.showBookSelectionError = false;
}

private setInitialTranslateBooks(): void {
// Get the previously selected translation books from the target project
const previousTranslation =
this.activatedProject.projectDoc?.data?.translateConfig.draftConfig.lastSelectedTranslationScriptureRanges ?? [];
for (const range of previousTranslation) {
const source = this.draftingSources.find(s => s.projectRef === range.projectId);
if (source !== undefined) {
for (const bookNum of booksFromScriptureRange(range.scriptureRange)) {
const sourceBook = this.availableTranslateBooks[source.projectRef].find(b => b.number === bookNum);
if (sourceBook !== undefined) {
sourceBook.selected = true;
}
}
}
}
}

private setInitialTrainingBooks(targetProjectId: string): void {
// Get the previously selected training books from the target project
const previousTraining =
Expand Down
Loading