Skip to content

Commit f710fd4

Browse files
committed
SF-3610 Adding a latest draft check to formatting button
Before, we we only checked if the latest draft contained that book, so older drafts still had the formatting button enabled. Now, we confirm the button is only enabled when the latest revision is selected.
1 parent c5708ff commit f710fd4

File tree

3 files changed

+94
-3
lines changed

3 files changed

+94
-3
lines changed

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,10 @@
4545
<div class="apply-draft-button-container">
4646
@if (showDraftOptionsButton$ | async) {
4747
<span
48-
[matTooltip]="t(doesLatestHaveDraft ? 'format_draft_can' : 'format_draft_cannot')"
49-
[style.cursor]="doesLatestHaveDraft ? 'pointer' : 'not-allowed'"
48+
[matTooltip]="t(canConfigureFormatting ? 'format_draft_can' : 'format_draft_cannot')"
49+
[style.cursor]="canConfigureFormatting ? 'pointer' : 'not-allowed'"
5050
>
51-
<button mat-button (click)="navigateToFormatting()" [disabled]="!doesLatestHaveDraft">
51+
<button mat-button (click)="navigateToFormatting()" [disabled]="!canConfigureFormatting">
5252
<mat-icon>build</mat-icon>
5353
<transloco key="editor_draft_tab.format_draft"></transloco>
5454
</button>

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

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -559,6 +559,89 @@ describe('EditorDraftComponent', () => {
559559
}));
560560
});
561561

562+
describe('canConfigureFormatting', () => {
563+
beforeEach(() => {
564+
when(mockFeatureFlagService.newDraftHistory).thenReturn(createTestFeatureFlag(true));
565+
when(mockDraftGenerationService.getGeneratedDraftHistory(anything(), anything(), anything())).thenReturn(
566+
of(draftHistory)
567+
);
568+
spyOn<any>(component, 'getTargetOps').and.returnValue(of(targetDelta.ops));
569+
when(mockDraftHandlingService.getDraft(anything(), anything())).thenReturn(of(draftDelta.ops!));
570+
when(mockDraftHandlingService.draftDataToOps(anything(), anything())).thenReturn(draftDelta.ops!);
571+
});
572+
573+
it('should be true when latest build has draft and selected revision is latest', fakeAsync(() => {
574+
const testProjectDoc: SFProjectProfileDoc = {
575+
data: createTestProjectProfile({
576+
texts: [
577+
{
578+
bookNum: 1,
579+
chapters: [{ number: 1, permissions: { user01: SFProjectRole.ParatextAdministrator }, hasDraft: true }]
580+
}
581+
]
582+
})
583+
} as SFProjectProfileDoc;
584+
when(mockDraftGenerationService.draftExists(anything(), anything(), anything())).thenReturn(of(true));
585+
when(mockActivatedProjectService.changes$).thenReturn(of(testProjectDoc));
586+
587+
fixture.detectChanges();
588+
tick(EDITOR_READY_TIMEOUT);
589+
590+
expect(component.isSelectedDraftLatest).toBe(true);
591+
expect(component.canConfigureFormatting).toBe(true);
592+
flush();
593+
}));
594+
595+
it('should be false when selected revision is not the latest', fakeAsync(() => {
596+
const testProjectDoc: SFProjectProfileDoc = {
597+
data: createTestProjectProfile({
598+
texts: [
599+
{
600+
bookNum: 1,
601+
chapters: [{ number: 1, permissions: { user01: SFProjectRole.ParatextAdministrator }, hasDraft: true }]
602+
}
603+
]
604+
})
605+
} as SFProjectProfileDoc;
606+
when(mockDraftGenerationService.draftExists(anything(), anything(), anything())).thenReturn(of(true));
607+
when(mockActivatedProjectService.changes$).thenReturn(of(testProjectDoc));
608+
609+
fixture.detectChanges();
610+
tick(EDITOR_READY_TIMEOUT);
611+
expect(component.canConfigureFormatting).toBe(true);
612+
613+
// Select earlier revision
614+
component.onSelectionChanged({ value: draftHistory[1] } as MatSelectChange);
615+
fixture.detectChanges();
616+
tick(EDITOR_READY_TIMEOUT);
617+
618+
expect(component.isSelectedDraftLatest).toBe(false);
619+
expect(component.canConfigureFormatting).toBe(false);
620+
flush();
621+
}));
622+
623+
it('should be false when latest build does not have a draft', fakeAsync(() => {
624+
const testProjectDoc: SFProjectProfileDoc = {
625+
data: createTestProjectProfile({
626+
texts: [
627+
{
628+
bookNum: 1,
629+
chapters: [{ number: 1, permissions: { user01: SFProjectRole.ParatextAdministrator }, hasDraft: false }]
630+
}
631+
]
632+
})
633+
} as SFProjectProfileDoc;
634+
when(mockDraftGenerationService.draftExists(anything(), anything(), anything())).thenReturn(of(false));
635+
when(mockActivatedProjectService.changes$).thenReturn(of(testProjectDoc));
636+
637+
fixture.detectChanges();
638+
tick(EDITOR_READY_TIMEOUT);
639+
expect(component.isSelectedDraftLatest).toBe(true);
640+
expect(component.canConfigureFormatting).toBe(false);
641+
flush();
642+
}));
643+
});
644+
562645
describe('getLocalizedBookChapter', () => {
563646
it('should return an empty string if bookNum or chapter is undefined', () => {
564647
component.bookNum = undefined;

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,13 +150,21 @@ export class EditorDraftComponent implements AfterViewInit, OnChanges {
150150
return this.draftHandlingService.canApplyDraft(this.targetProject, this.bookNum, this.chapter, this.draftDelta.ops);
151151
}
152152

153+
get canConfigureFormatting(): boolean {
154+
return this.doesLatestHaveDraft && this.isSelectedDraftLatest;
155+
}
156+
153157
get doesLatestHaveDraft(): boolean {
154158
return (
155159
this.targetProject?.texts.find(t => t.bookNum === this.bookNum)?.chapters.find(c => c.number === this.chapter)
156160
?.hasDraft ?? false
157161
);
158162
}
159163

164+
get isSelectedDraftLatest(): boolean {
165+
return this.selectedRevision?.timestamp === this._draftRevisions[0].timestamp;
166+
}
167+
160168
set draftRevisions(value: Revision[]) {
161169
this._draftRevisions = value;
162170
}

0 commit comments

Comments
 (0)