[ADF-5355] - Fix attach button visibility when using external source (#6784)

This commit is contained in:
arditdomi
2021-03-12 09:03:42 +00:00
committed by GitHub
parent b2a531c814
commit 2ed632f9fc
3 changed files with 43 additions and 1 deletions

View File

@@ -33,7 +33,7 @@
<button *ngIf="isLoggedIn()"
mat-button
[disabled]="!chosenNode"
[disabled]="!hasNodeSelected()"
class="adf-choose-action"
(click)="onClick()"
data-automation-id="attach-file-dialog-actions-choose">{{ buttonActionName | translate }}

View File

@@ -209,4 +209,42 @@ describe('AttachFileWidgetDialogComponent', () => {
expect(matDialogRef.close).toHaveBeenCalled();
});
});
describe('Attach button', () => {
beforeEach(async(() => {
isLogged = true;
}));
it('should be disabled by default', () => {
fixture.detectChanges();
const actionButton = fixture.debugElement.query(By.css('[data-automation-id="attach-file-dialog-actions-choose"]'));
expect(actionButton.nativeElement.disabled).toBeTruthy();
});
it('should be enabled when a node is chosen', () => {
widget.onSelect([new Node({ id: 'fake' })]);
fixture.detectChanges();
const actionButton = fixture.debugElement.query(By.css('[data-automation-id="attach-file-dialog-actions-choose"]'));
expect(actionButton.nativeElement.disabled).toBeFalsy();
});
it('should be disabled when no node chosen', () => {
widget.onSelect([new Node({ id: 'fake' })]);
fixture.detectChanges();
const actionButtonWithNodeSelected = fixture.debugElement.query(By.css('[data-automation-id="attach-file-dialog-actions-choose"]'));
expect(actionButtonWithNodeSelected.nativeElement.disabled).toBe(false);
widget.onSelect([]);
fixture.detectChanges();
const actionButtonWithoutNodeSelected = fixture.debugElement.query(By.css('[data-automation-id="attach-file-dialog-actions-choose"]'));
expect(actionButtonWithoutNodeSelected.nativeElement.disabled).toBe(true);
});
});
});

View File

@@ -105,4 +105,8 @@ export class AttachFileWidgetDialogComponent {
getTitleTranslation(action: string, name?: string): string {
return this.translation.instant(`ATTACH-FILE.ACTIONS.${action}_ITEM`, { name: this.translation.instant(name) });
}
hasNodeSelected(): boolean {
return this.chosenNode?.length > 0;
}
}