Skip to content

Commit

Permalink
Check if target book is empty
Browse files Browse the repository at this point in the history
  • Loading branch information
RaymondLuong3 committed Jan 17, 2025
1 parent b9fb326 commit a1bd6e6
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ describe('DraftApplyDialogComponent', () => {
expect(env.component['getCustomErrorState']()).toBe(CustomValidatorState.InvalidProject);
}));

it('notifies user if books has missing chapters', fakeAsync(() => {
it('notifies user if book has missing chapters', fakeAsync(() => {
const projectDoc = {
id: 'project03',
data: createTestProjectProfile({
Expand All @@ -156,7 +156,30 @@ describe('DraftApplyDialogComponent', () => {
texts: [
{
bookNum: 1,
chapters: [{ number: 1, permissions: { user01: TextInfoPermission.Write } }],
chapters: [{ number: 1, permissions: { user01: TextInfoPermission.Write }, lastVerse: 31 }],
permissions: { user01: TextInfoPermission.Write }
}
]
})
} as SFProjectProfileDoc;
env = new TestEnvironment({ projectDoc });
env.selectParatextProject('paratextId3');
expect(env.component['targetProjectId']).toBe('project03');
tick();
env.fixture.detectChanges();
expect(env.component['getCustomErrorState']()).toBe(CustomValidatorState.MissingChapters);
}));

it('notifies user if book is empty', fakeAsync(() => {
const projectDoc = {
id: 'project03',
data: createTestProjectProfile({
paratextId: 'paratextId3',
userRoles: { user01: SFProjectRole.ParatextAdministrator },
texts: [
{
bookNum: 1,
chapters: [{ number: 1, permissions: { user01: TextInfoPermission.Write }, lastVerse: 0 }],
permissions: { user01: TextInfoPermission.Write }
}
]
Expand Down Expand Up @@ -272,8 +295,8 @@ class TestEnvironment {
{
bookNum: 1,
chapters: [
{ number: 1, permissions: { user01: permission } },
{ number: 2, permissions: { user01: permission } }
{ number: 1, permissions: { user01: permission }, lastVerse: 31 },
{ number: 2, permissions: { user01: permission }, lastVerse: 25 }
],
permissions: { user01: permission }
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -160,8 +160,12 @@ export class DraftApplyDialogComponent implements OnInit {
this.canEditProject =
this.textDocService.userHasGeneralEditRight(project) &&
targetBook?.permissions[this.userService.currentUserId] === TextInfoPermission.Write;

// also check if this is an empty book
const bookIsEmpty: boolean = targetBook?.chapters.length === 1 && targetBook?.chapters[0].lastVerse < 1;
const targetBookChapters: number[] = targetBook?.chapters.map(c => c.number) ?? [];
this.projectHasMissingChapters = this.data.chapters.filter(c => !targetBookChapters.includes(c)).length > 0;
this.projectHasMissingChapters =
bookIsEmpty || this.data.chapters.filter(c => !targetBookChapters.includes(c)).length > 0;
// emit the project profile document
if (this.canEditProject && !this.projectHasMissingChapters) {
this.targetProject$.next(project);
Expand Down

0 comments on commit a1bd6e6

Please sign in to comment.