Skip to content

Commit

Permalink
SF-3141 Fix selected reference books persisting between steps
Browse files Browse the repository at this point in the history
  • Loading branch information
kylebuss committed Dec 24, 2024
1 parent 931e3a4 commit b43d91d
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ <h2>{{ t("reference_books") }}</h2>
} @else {
<app-book-multi-select
[availableBooks]="selectableSourceTrainingBooks"
[selectedBooks]="userSelectedSourceTrainingBooks"
[selectedBooks]="refBooksSelectedTrainingBooks"
[basicMode]="true"
(bookSelect)="onSourceTrainingBookSelect($event)"
></app-book-multi-select>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,7 @@ describe('DraftGenerationStepsComponent', () => {
const trainingDataFiles: string[] = [];
const translationBooks = [2];

component.refBooksSelectedTrainingBooks = trainingBooks;
component.userSelectedTrainingBooks = trainingBooks;
component.userSelectedTranslateBooks = translationBooks;
component.selectedTrainingDataIds = trainingDataFiles;
Expand All @@ -231,13 +232,13 @@ describe('DraftGenerationStepsComponent', () => {
fixture.detectChanges();
expect(component.availableTrainingBooks).toEqual(trainingBooks);
expect(component.selectableSourceTrainingBooks).toEqual(trainingBooks);
expect(component.userSelectedSourceTrainingBooks).toEqual(trainingBooks);
expect(component.refBooksSelectedTrainingBooks).toEqual(trainingBooks);
expect(fixture.nativeElement.querySelector('.books-appear-notice')).toBeNull();

component.onSourceTrainingBookSelect([]);
fixture.detectChanges();
expect(component.selectableSourceTrainingBooks).toEqual(trainingBooks);
expect(component.userSelectedSourceTrainingBooks).toEqual([]);
expect(component.refBooksSelectedTrainingBooks).toEqual([]);
expect(fixture.nativeElement.querySelector('.books-appear-notice')).toBeNull();
});

Expand Down Expand Up @@ -335,7 +336,7 @@ describe('DraftGenerationStepsComponent', () => {
component.userSelectedTrainingBooks = trainingBooks;
component.userSelectedTranslateBooks = translationBooks;
component.selectedTrainingDataIds = trainingDataFiles;
component.userSelectedSourceTrainingBooks = trainingBooks;
component.refBooksSelectedTrainingBooks = trainingBooks.filter(book => !translationBooks.includes(book));
component['draftSourceProjectIds'] = { draftingSourceId: 'sourceProject', trainingSourceId: 'sourceProject' };

spyOn(component.done, 'emit');
Expand Down Expand Up @@ -532,7 +533,7 @@ describe('DraftGenerationStepsComponent', () => {
component.userSelectedTrainingBooks = trainingBooks;
component.userSelectedTranslateBooks = translationBooks;
component.selectedTrainingDataIds = trainingDataFiles;
component.userSelectedSourceTrainingBooks = trainingBooks;
component.refBooksSelectedTrainingBooks = trainingBooks;
component.userSelectedAdditionalSourceTrainingBooks = trainingBooks;
component['draftSourceProjectIds'] = {
draftingSourceId: 'sourceProject',
Expand Down Expand Up @@ -568,20 +569,15 @@ describe('DraftGenerationStepsComponent', () => {
it('does not allow selecting not selectable additional source training books', () => {
const trainingBooks = [3];
const trainingDataFiles: string[] = [];
const translationBooks = [1, 2];

component.userSelectedTrainingBooks = trainingBooks;
component.userSelectedTranslateBooks = translationBooks;
component.selectableAdditionalSourceTrainingBooks = trainingBooks;
component.userSelectedAdditionalSourceTrainingBooks = trainingBooks;
component.selectedTrainingDataIds = trainingDataFiles;
component['draftSourceProjectIds'] = {
draftingSourceId: 'sourceProject',
trainingSourceId: 'sourceProject',
trainingAdditionalSourceId: 'sourceProject2'
};
component.onStepChange();
expect(component.availableTrainingBooks).toEqual(trainingBooks);
expect(component.selectableSourceTrainingBooks).toEqual(trainingBooks);
expect(component.userSelectedSourceTrainingBooks).toEqual(trainingBooks);
expect(component.selectableAdditionalSourceTrainingBooks).toEqual(trainingBooks);
expect(component.userSelectedAdditionalSourceTrainingBooks).toEqual(trainingBooks);

Expand All @@ -598,7 +594,7 @@ describe('DraftGenerationStepsComponent', () => {
component.userSelectedTrainingBooks = trainingBooks;
component.userSelectedTranslateBooks = translationBooks;
component.selectedTrainingDataIds = trainingDataFiles;
component.userSelectedSourceTrainingBooks = trainingBooks;
component.refBooksSelectedTrainingBooks = trainingBooks;
component.userSelectedAdditionalSourceTrainingBooks = trainingBooks;
component['draftSourceProjectIds'] = {
draftingSourceId: 'sourceProject',
Expand Down Expand Up @@ -656,6 +652,7 @@ describe('DraftGenerationStepsComponent', () => {
component.userSelectedTranslateBooks = translationBooks;
component.selectedTrainingDataIds = trainingDataFiles;
component.userSelectedSourceTrainingBooks = trainingBooks;
component.refBooksSelectedTrainingBooks = trainingBooks;
component['draftSourceProjectIds'] = { draftingSourceId: 'sourceProject', trainingSourceId: 'sourceProject' };

spyOn(component.done, 'emit');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ export class DraftGenerationStepsComponent extends SubscriptionDisposable implem
userSelectedSourceTrainingBooks: number[] = [];
userSelectedAdditionalSourceTrainingBooks: number[] = [];

refBooksSelectedTrainingBooks: number[] = [];
selectedTrainingDataIds: string[] = [];

draftingSourceProjectName?: string;
Expand Down Expand Up @@ -270,6 +271,7 @@ export class DraftGenerationStepsComponent extends SubscriptionDisposable implem
// automatically select books that are newly selected as training books
for (const bookNum of newBookSelections) {
this.userSelectedSourceTrainingBooks.push(bookNum);
this.refBooksSelectedTrainingBooks.push(bookNum);
if (this.selectableAdditionalSourceTrainingBooks.includes(bookNum)) {
this.userSelectedAdditionalSourceTrainingBooks.push(bookNum);
}
Expand All @@ -284,7 +286,7 @@ export class DraftGenerationStepsComponent extends SubscriptionDisposable implem
}

onSourceTrainingBookSelect(selectedBooks: number[]): void {
this.userSelectedSourceTrainingBooks = this.selectableSourceTrainingBooks.filter(b => selectedBooks.includes(b));
this.refBooksSelectedTrainingBooks = this.selectableSourceTrainingBooks.filter(b => selectedBooks.includes(b));
this.clearErrorMessage();
}

Expand Down Expand Up @@ -319,10 +321,10 @@ export class DraftGenerationStepsComponent extends SubscriptionDisposable implem
}
this.isStepsCompleted = true;
const trainingScriptureRange: ProjectScriptureRange | undefined =
this.userSelectedSourceTrainingBooks.length > 0
this.refBooksSelectedTrainingBooks.length > 0
? this.convertToScriptureRange(
this.draftSourceProjectIds!.trainingAlternateSourceId ?? this.draftSourceProjectIds!.trainingSourceId,
this.userSelectedSourceTrainingBooks
this.refBooksSelectedTrainingBooks
)
: undefined;

Expand Down Expand Up @@ -372,9 +374,6 @@ export class DraftGenerationStepsComponent extends SubscriptionDisposable implem
this.selectableAdditionalSourceTrainingBooks = this.availableAdditionalTrainingBooks.filter(b =>
newSelectedTrainingBooks.includes(b)
);
this.userSelectedAdditionalSourceTrainingBooks = this.selectableAdditionalSourceTrainingBooks.filter(b =>
newSelectedTrainingBooks.includes(b)
);
}

bookNames(books: number[]): string {
Expand Down Expand Up @@ -434,6 +433,7 @@ export class DraftGenerationStepsComponent extends SubscriptionDisposable implem
this.userSelectedAdditionalSourceTrainingBooks = this.availableAdditionalTrainingBooks.filter(b =>
this.initialSelectedTrainingBooks.includes(b)
);
this.refBooksSelectedTrainingBooks = [...this.userSelectedSourceTrainingBooks];
}

private setInitialTrainingDataFiles(availableDataFiles: string[]): void {
Expand Down

0 comments on commit b43d91d

Please sign in to comment.