Skip to content

Commit

Permalink
SF-3182 Fix warning message when training book no longer selectable (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
RaymondLuong3 authored Jan 31, 2025
1 parent f9f919e commit 9eb196b
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,58 @@ describe('DraftGenerationStepsComponent', () => {
component.onTranslatedBookSelect([]);
expect(component.selectedTrainingBooksByProj('sourceProject')).toEqual([]);
});

it('clears selected translated and reference books in training when translate book selected', () => {
clickConfirmLanguages(fixture);
component.tryAdvanceStep();
fixture.detectChanges();
component.onTranslateBookSelect([3]);
component.tryAdvanceStep();
fixture.detectChanges();
component.onTranslatedBookSelect([1, 2]);
expect(component.selectedTrainingBooksByProj('project01')).toEqual([
{ number: 1, selected: true },
{ number: 2, selected: true }
]);
expect(component.selectedTrainingBooksByProj('sourceProject')).toEqual([
{ number: 1, selected: true },
{ number: 2, selected: true }
]);
component.stepper.selectedIndex = 1;
fixture.detectChanges();
component.onTranslateBookSelect([2, 3]);
component.tryAdvanceStep();
fixture.detectChanges();
expect(component.selectedTrainingBooksByProj('sourceProject')).toEqual([{ number: 1, selected: true }]);
expect(component.selectedTrainingBooksByProj('project01')).toEqual([{ number: 1, selected: true }]);
});

it('shows unselected translate book on training page', () => {
clickConfirmLanguages(fixture);
component.tryAdvanceStep();
fixture.detectChanges();
// select Exodus and Leviticus
component.onTranslateBookSelect([2, 3]);
component.tryAdvanceStep();
fixture.detectChanges();
component.onTranslatedBookSelect([1]);
expect(component.selectableTrainingBooksByProj('project01')).toEqual([{ number: 1, selected: true }]);
expect(component.selectedTrainingBooksByProj('project01')).toEqual([{ number: 1, selected: true }]);
expect(component.selectedTrainingBooksByProj('sourceProject')).toEqual([{ number: 1, selected: true }]);
component.stepper.selectedIndex = 1;
fixture.detectChanges();
// deselect Exodus and keep Leviticus
component.onTranslateBookSelect([3]);
component.tryAdvanceStep();
fixture.detectChanges();
// Exodus becomes a selectable training book
expect(component.selectableTrainingBooksByProj('project01')).toEqual([
{ number: 1, selected: true },
{ number: 2, selected: false }
]);
expect(component.selectedTrainingBooksByProj('sourceProject')).toEqual([{ number: 1, selected: true }]);
expect(component.selectedTrainingBooksByProj('project01')).toEqual([{ number: 1, selected: true }]);
});
});

describe('additional training source', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -430,6 +430,7 @@ export class DraftGenerationStepsComponent implements OnInit {
}

onStepChange(): void {
this.updateSelectedTrainingBooks();
this.clearErrorMessage();
}

Expand All @@ -450,7 +451,7 @@ export class DraftGenerationStepsComponent implements OnInit {

const trainingData: ProjectScriptureRange[] = [];
for (const source of this.trainingSources) {
const booksForThisSource = this.availableTrainingBooks[source.projectRef].filter(b => b.selected);
const booksForThisSource: Book[] = this.selectedTrainingBooksByProj(source.projectRef);
if (booksForThisSource.length > 0) {
trainingData.push({
projectId: source.projectRef,
Expand Down Expand Up @@ -478,6 +479,14 @@ export class DraftGenerationStepsComponent implements OnInit {
return projectLabel(source);
}

private updateSelectedTrainingBooks(): void {
const booksForTranslation: number[] = this.availableTranslateBooks.filter(b => b.selected).map(b => b.number);
for (const [, trainingBooks] of Object.entries(this.availableTrainingBooks)) {
// set the selected state of any training book to false if it is selected for translation
trainingBooks.forEach(b => (b.selected = booksForTranslation.includes(b.number) ? false : b.selected));
}
}

private validateCurrentStep(): boolean {
const isValid = this.stepper.selected?.completed!;
this.showBookSelectionError = !isValid;
Expand Down

0 comments on commit 9eb196b

Please sign in to comment.