Skip to content

Commit a0bdf99

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 f4314c3 commit a0bdf99

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
@@ -558,6 +558,89 @@ describe('EditorDraftComponent', () => {
558558
}));
559559
});
560560

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

123+
get canConfigureFormatting(): boolean {
124+
return this.doesLatestHaveDraft && this.isSelectedDraftLatest;
125+
}
126+
123127
get doesLatestHaveDraft(): boolean {
124128
return (
125129
this.targetProject?.texts.find(t => t.bookNum === this.bookNum)?.chapters.find(c => c.number === this.chapter)
126130
?.hasDraft ?? false
127131
);
128132
}
129133

134+
get isSelectedDraftLatest(): boolean {
135+
return this.selectedRevision?.timestamp === this._draftRevisions[0].timestamp;
136+
}
137+
130138
set draftRevisions(value: Revision[]) {
131139
this._draftRevisions = value;
132140
}

0 commit comments

Comments
 (0)