Skip to content

Commit f4e5bd2

Browse files
josephmyerspmachapman
authored andcommitted
Review comments
1 parent 4dcfea7 commit f4e5bd2

File tree

5 files changed

+69
-50
lines changed

5 files changed

+69
-50
lines changed

src/SIL.XForge.Scripture/ClientApp/src/app/translate/editor/editor-draft/editor-draft.component.html

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -70,12 +70,12 @@
7070
}
7171
</button>
7272
}
73-
@if (!canApplyDraft) {
74-
<app-notice icon="warning" type="warning" mode="fill-dark">
75-
{{ "editor_draft_tab.cannot_import" | transloco }}
76-
</app-notice>
77-
}
7873
</div>
74+
@if (!canApplyDraft) {
75+
<app-notice icon="warning" type="warning" mode="fill-dark">
76+
{{ "editor_draft_tab.cannot_import" | transloco }}
77+
</app-notice>
78+
}
7979
</div>
8080
}
8181
} @else {

src/SIL.XForge.Scripture/ClientApp/src/app/translate/editor/editor-draft/editor-draft.component.scss

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ app-notice {
3131
flex-grow: 1;
3232
display: flex;
3333
justify-content: flex-end;
34-
column-gap: 4px;
34+
gap: 4px;
3535
align-items: center;
3636
flex-wrap: wrap;
3737
}

src/SIL.XForge.Scripture/ClientApp/src/app/translate/editor/editor-draft/editor-draft.component.spec.ts

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@ import { NoopAnimationsModule } from '@angular/platform-browser/animations';
77
import { cloneDeep } from 'lodash-es';
88
import { TranslocoMarkupModule } from 'ngx-transloco-markup';
99
import { Delta } from 'quill';
10+
import { SFProjectRole } from 'realtime-server/lib/esm/scriptureforge/models/sf-project-role';
1011
import { createTestProjectProfile } from 'realtime-server/lib/esm/scriptureforge/models/sf-project-test-data';
12+
import { ParagraphBreakFormat, QuoteFormat } from 'realtime-server/lib/esm/scriptureforge/models/translate-config';
1113
import { BehaviorSubject, of } from 'rxjs';
1214
import { anything, mock, verify, when } from 'ts-mockito';
1315
import { ActivatedProjectService } from 'xforge-common/activated-project.service';
@@ -391,6 +393,40 @@ describe('EditorDraftComponent', () => {
391393
}));
392394

393395
describe('applyDraft', () => {
396+
it('should allow user to apply draft when formatting selected', fakeAsync(() => {
397+
const testProjectDoc: SFProjectProfileDoc = {
398+
data: createTestProjectProfile({
399+
texts: [
400+
{
401+
bookNum: 1,
402+
chapters: [{ number: 1, permissions: { user01: SFProjectRole.ParatextAdministrator }, hasDraft: true }]
403+
}
404+
],
405+
translateConfig: {
406+
draftConfig: {
407+
usfmConfig: { paragraphFormat: ParagraphBreakFormat.BestGuess, quoteFormat: QuoteFormat.Denormalized }
408+
}
409+
}
410+
})
411+
} as SFProjectProfileDoc;
412+
when(mockDraftGenerationService.draftExists(anything(), anything(), anything())).thenReturn(of(true));
413+
when(mockDraftGenerationService.getGeneratedDraftHistory(anything(), anything(), anything())).thenReturn(
414+
of(draftHistory)
415+
);
416+
when(mockActivatedProjectService.changes$).thenReturn(of(testProjectDoc));
417+
when(mockDialogService.confirm(anything(), anything())).thenResolve(true);
418+
when(mockDraftHandlingService.canApplyDraft(anything(), anything(), anything(), anything())).thenReturn(true);
419+
spyOn<any>(component, 'getTargetOps').and.returnValue(of(targetDelta.ops));
420+
when(mockDraftHandlingService.getDraft(anything(), anything())).thenReturn(of(draftDelta.ops!));
421+
when(mockDraftHandlingService.draftDataToOps(anything(), anything())).thenReturn(draftDelta.ops!);
422+
423+
fixture.detectChanges();
424+
tick(EDITOR_READY_TIMEOUT);
425+
426+
expect(component.canApplyDraft).toBe(true);
427+
flush();
428+
}));
429+
394430
it('should show a prompt when applying if the target has content', fakeAsync(() => {
395431
const testProjectDoc: SFProjectProfileDoc = {
396432
data: createTestProjectProfile()

src/SIL.XForge.Scripture/ClientApp/src/app/translate/editor/editor-draft/editor-draft.component.ts

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,24 @@ export class EditorDraftComponent implements AfterViewInit, OnChanges {
101101
private readonly router: Router
102102
) {}
103103

104+
get bookId(): string {
105+
return this.bookNum !== undefined ? Canon.bookNumberToId(this.bookNum) : '';
106+
}
107+
108+
get canApplyDraft(): boolean {
109+
if (this.targetProject == null || this.bookNum == null || this.chapter == null || this.draftDelta?.ops == null) {
110+
return false;
111+
}
112+
return this.draftHandlingService.canApplyDraft(this.targetProject, this.bookNum, this.chapter, this.draftDelta.ops);
113+
}
114+
115+
get doesLatestHaveDraft(): boolean {
116+
return (
117+
this.targetProject?.texts.find(t => t.bookNum === this.bookNum)?.chapters.find(c => c.number === this.chapter)
118+
?.hasDraft ?? false
119+
);
120+
}
121+
104122
set draftRevisions(value: Revision[]) {
105123
this._draftRevisions = value;
106124
}
@@ -128,10 +146,6 @@ export class EditorDraftComponent implements AfterViewInit, OnChanges {
128146
this.selectedRevisionSubject.next(this.selectedRevision);
129147
}
130148

131-
get bookId(): string {
132-
return this.bookNum !== undefined ? Canon.bookNumberToId(this.bookNum) : '';
133-
}
134-
135149
populateDraftTextInit(): void {
136150
combineLatest([
137151
this.onlineStatusService.onlineStatus$,
@@ -249,20 +263,6 @@ export class EditorDraftComponent implements AfterViewInit, OnChanges {
249263
});
250264
}
251265

252-
get canApplyDraft(): boolean {
253-
if (this.targetProject == null || this.bookNum == null || this.chapter == null || this.draftDelta?.ops == null) {
254-
return false;
255-
}
256-
return this.draftHandlingService.canApplyDraft(this.targetProject, this.bookNum, this.chapter, this.draftDelta.ops);
257-
}
258-
259-
get doesLatestHaveDraft(): boolean {
260-
return (
261-
this.targetProject?.texts.find(t => t.bookNum === this.bookNum)?.chapters.find(c => c.number === this.chapter)
262-
?.hasDraft ?? false
263-
);
264-
}
265-
266266
navigateToFormatting(): void {
267267
this.router.navigateByUrl(`/projects/${this.projectId}/draft-generation/format/${this.bookId}/${this.chapter}`);
268268
}

src/SIL.XForge.Scripture/ClientApp/src/app/translate/editor/editor.component.spec.ts

Lines changed: 9 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -4072,10 +4072,6 @@ describe('EditorComponent', () => {
40724072
Object.defineProperty(env.component, 'showSource', { get: () => true });
40734073
});
40744074
when(mockedPermissionsService.canAccessDrafts(anything(), anything())).thenReturn(true);
4075-
const projectDoc = env.getProjectDoc('project01');
4076-
if (projectDoc.data != null) {
4077-
(projectDoc.data.translateConfig as any).draftConfig = { usfmConfig: {} };
4078-
}
40794075
env.wait();
40804076
env.routeWithParams({ projectId: 'project01', bookId: 'LUK', chapter: '1' });
40814077
env.wait();
@@ -4094,10 +4090,6 @@ describe('EditorComponent', () => {
40944090
Object.defineProperty(env.component, 'showSource', { get: () => false });
40954091
});
40964092
when(mockedPermissionsService.canAccessDrafts(anything(), anything())).thenReturn(true);
4097-
const projectDoc = env.getProjectDoc('project01');
4098-
if (projectDoc.data != null) {
4099-
(projectDoc.data.translateConfig as any).draftConfig = { usfmConfig: {} };
4100-
}
41014093
env.wait();
41024094
env.routeWithParams({ projectId: 'project01', bookId: 'LUK', chapter: '1' });
41034095
env.wait();
@@ -4115,6 +4107,7 @@ describe('EditorComponent', () => {
41154107
const env = new TestEnvironment(env => {
41164108
Object.defineProperty(env.component, 'showSource', { get: () => true });
41174109
});
4110+
env.setupProject({ translateConfig: { draftConfig: {} } });
41184111
when(mockedPermissionsService.canAccessDrafts(anything(), anything())).thenReturn(true);
41194112
env.wait();
41204113
env.routeWithParams({ projectId: 'project01', bookId: 'LUK', chapter: '1' });
@@ -4133,10 +4126,6 @@ describe('EditorComponent', () => {
41334126
Object.defineProperty(env.component, 'showSource', { get: () => true });
41344127
});
41354128
when(mockedPermissionsService.canAccessDrafts(anything(), anything())).thenReturn(true);
4136-
const projectDoc = env.getProjectDoc('project01');
4137-
if (projectDoc.data != null) {
4138-
(projectDoc.data.translateConfig as any).draftConfig = { usfmConfig: {} };
4139-
}
41404129
env.routeWithParams({ projectId: 'project01', bookId: 'LUK', chapter: '1' });
41414130
env.wait();
41424131

@@ -4173,10 +4162,6 @@ describe('EditorComponent', () => {
41734162
Object.defineProperty(env.component, 'showSource', { get: () => false });
41744163
});
41754164
when(mockedPermissionsService.canAccessDrafts(anything(), anything())).thenReturn(true);
4176-
const projectDoc = env.getProjectDoc('project01');
4177-
if (projectDoc.data != null) {
4178-
(projectDoc.data.translateConfig as any).draftConfig = { usfmConfig: {} };
4179-
}
41804165
env.routeWithParams({ projectId: 'project01', bookId: 'LUK', chapter: '1' });
41814166
env.wait();
41824167

@@ -4213,10 +4198,6 @@ describe('EditorComponent', () => {
42134198
queryParams: { 'draft-active': 'true', 'draft-timestamp': new Date().toISOString() }
42144199
} as any);
42154200
when(mockedPermissionsService.canAccessDrafts(anything(), anything())).thenReturn(true);
4216-
const projectDoc = env.getProjectDoc('project01');
4217-
if (projectDoc.data != null) {
4218-
(projectDoc.data.translateConfig as any).draftConfig = { usfmConfig: {} };
4219-
}
42204201
env.wait();
42214202
env.routeWithParams({ projectId: 'project01', bookId: 'LUK', chapter: '1' });
42224203
env.wait();
@@ -4231,10 +4212,6 @@ describe('EditorComponent', () => {
42314212
const env = new TestEnvironment();
42324213
when(mockedActivatedRoute.snapshot).thenReturn({ queryParams: {} } as any);
42334214
when(mockedPermissionsService.canAccessDrafts(anything(), anything())).thenReturn(true);
4234-
const projectDoc = env.getProjectDoc('project01');
4235-
if (projectDoc.data != null) {
4236-
(projectDoc.data.translateConfig as any).draftConfig = { usfmConfig: {} };
4237-
}
42384215
env.wait();
42394216
env.routeWithParams({ projectId: 'project01', bookId: 'LUK', chapter: '1' });
42404217
env.wait();
@@ -4622,7 +4599,10 @@ describe('EditorComponent', () => {
46224599
});
46234600

46244601
const defaultTranslateConfig = {
4625-
translationSuggestionsEnabled: false
4602+
translationSuggestionsEnabled: false,
4603+
draftConfig: {
4604+
usfmConfig: {}
4605+
}
46264606
};
46274607

46284608
class TestEnvironment {
@@ -4940,7 +4920,7 @@ class TestEnvironment {
49404920

49414921
this.setupUsers();
49424922
this.setCurrentUser('user01');
4943-
this.setupProject();
4923+
this.setupProject({ translateConfig: defaultTranslateConfig });
49444924
this.addParatextNoteThread(1, 'MAT 1:1', 'chapter 1', { start: 8, length: 9 }, ['user01', 'user02', 'user03']);
49454925
this.addParatextNoteThread(2, 'MAT 1:3', 'target: chapter 1, verse 3.', { start: 0, length: 0 }, ['user01']);
49464926
this.addParatextNoteThread(3, 'MAT 1:3', 'verse 3', { start: 20, length: 7 }, ['user01']);
@@ -5164,6 +5144,9 @@ class TestEnvironment {
51645144
data.translateConfig?.source
51655145
);
51665146
}
5147+
if (data.translateConfig?.draftConfig != null) {
5148+
projectProfileData.translateConfig.draftConfig = data.translateConfig.draftConfig as any;
5149+
}
51675150
if (data.biblicalTermsConfig !== undefined) {
51685151
projectProfileData.biblicalTermsConfig = merge(projectProfileData.biblicalTermsConfig, data.biblicalTermsConfig);
51695152
}

0 commit comments

Comments
 (0)