Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SF-3167 Fix training books not correctly listed on summary page #2969

Merged
merged 4 commits into from
Jan 28, 2025
Merged
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 @@ -225,12 +225,49 @@ describe('DraftGenerationStepsComponent', () => {
]);
});

it('does not select deselected reference book when selecting translated book', () => {
component.onTranslatedBookSelect([1, 2]);
fixture.detectChanges();
component.onSourceTrainingBookSelect([1], config.trainingSources[0]);
fixture.detectChanges();

expect(component.selectedTrainingBooksByProj('project01')).toEqual([
{ number: 1, selected: true },
{ number: 2, selected: true }
]);
expect(component.selectedTrainingBooksByProj('sourceProject')).toEqual([{ number: 1, selected: true }]);

// deselect translated book 1
component.onTranslatedBookSelect([2]);
fixture.detectChanges();
expect(component.selectedTrainingBooksByProj('project01')).toEqual([{ number: 2, selected: true }]);
// ensure that book 2 in the reference text is not re-selected
expect(component.selectedTrainingBooksByProj('sourceProject')).toEqual([]);
});

it('does not allow selecting not selectable source training books', () => {
component.onSourceTrainingBookSelect([6, 7], config.trainingSources[0]);
fixture.detectChanges();

expect(component.selectedTrainingBooksByProj('sourceProject')).toEqual([]);
});

it('clears selected reference books when translated book is unselected', () => {
component.onTranslatedBookSelect([2, 3]);
expect(component.selectedTrainingBooksByProj('project01')).toEqual([
{ number: 2, selected: true },
{ number: 3, selected: true }
]);
expect(component.selectedTrainingBooksByProj('sourceProject')).toEqual([
{ number: 2, selected: true },
{ number: 3, selected: true }
]);
component.onTranslatedBookSelect([2]);
expect(component.selectedTrainingBooksByProj('sourceProject')).toEqual([{ number: 2, selected: true }]);

component.onTranslatedBookSelect([]);
expect(component.selectedTrainingBooksByProj('sourceProject')).toEqual([]);
});
});

describe('additional training source', () => {
Expand Down Expand Up @@ -452,6 +489,30 @@ describe('DraftGenerationStepsComponent', () => {
fixture.detectChanges();
expect(component.stepper.selectedIndex).toBe(3);
});

it('clears selected reference books when translated book is unselected', () => {
component.onTranslatedBookSelect([2, 3]);
expect(component.selectedTrainingBooksByProj('project01')).toEqual([
{ number: 2, selected: true },
{ number: 3, selected: true }
]);
expect(component.selectedTrainingBooksByProj('source1')).toEqual([
{ number: 2, selected: true },
{ number: 3, selected: true }
]);
expect(component.selectedTrainingBooksByProj('source2')).toEqual([
{ number: 2, selected: true },
{ number: 3, selected: true }
]);

component.onTranslatedBookSelect([2]);
expect(component.selectedTrainingBooksByProj('source1')).toEqual([{ number: 2, selected: true }]);
expect(component.selectedTrainingBooksByProj('source2')).toEqual([{ number: 2, selected: true }]);

component.onTranslatedBookSelect([]);
expect(component.selectedTrainingBooksByProj('source1')).toEqual([]);
expect(component.selectedTrainingBooksByProj('source2')).toEqual([]);
});
});

describe('allow fast training feature flag is enabled', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -384,20 +384,27 @@ export class DraftGenerationStepsComponent implements OnInit {

onTranslatedBookSelect(selectedBooks: number[]): void {
if (this.activatedProject.projectId == null) return;
const newlySelectedBooks: number[] = this.availableTrainingBooks[this.activatedProject.projectId]
.filter(b => !b.selected && selectedBooks.includes(b.number))
.map(b => b.number);
//update selections in translated books
for (const book of this.availableTrainingBooks[this.activatedProject.projectId]) {
book.selected = selectedBooks.includes(book.number);
}

//for each selected book, select the matching book in the sources
for (const selectedBook of selectedBooks) {
for (const [projectRef, trainingBooks] of Object.entries(this.availableTrainingBooks)) {
if (projectRef === this.activatedProject.projectId) continue;
const sourceBook = trainingBooks.find(b => b.number === selectedBook);
if (sourceBook !== undefined) {
sourceBook.selected = true;
for (const [projectRef, trainingBooks] of Object.entries(this.availableTrainingBooks)) {
if (projectRef === this.activatedProject.projectId) continue;

trainingBooks.forEach(b => {
if (newlySelectedBooks.includes(b.number)) {
b.selected = true;
}
}
// ensure any books source training books not selected in translated books is unselected
if (!selectedBooks.includes(b.number)) {
b.selected = false;
}
});
}

this.clearErrorMessage();
Expand Down
Loading