[ADF-4406] - Confirm Dialog doesn't support a third extra button option to be customised (#4608)

* [ADF-4406] - Confirm Dialog doesn't support a third extra button option to be customised

* * comments fixed

* * docs and test added
This commit is contained in:
dhrn
2019-04-23 04:13:10 +05:30
committed by Eugenio Romano
parent b58e040d7e
commit 64391a48fa
7 changed files with 89 additions and 0 deletions

View File

@@ -12,6 +12,7 @@
<span class="adf-dialog-spacer" data-automation-id="adf-confirm-dialog-spacer"></span>
<button id="adf-confirm-accept" mat-button color="primary" data-automation-id="adf-confirm-dialog-confirmation"
[mat-dialog-close]="true">{{ yesLabel | translate }}</button>
<button id="adf-confirm-all" mat-button *ngIf="thirdOptionLabel" [mat-dialog-close]="thirdOptionLabel" data-automation-id="adf-confirm-dialog-confirm-all">{{ thirdOptionLabel | translate }}</button>
<button id="adf-confirm-cancel" mat-button [mat-dialog-close]="false" data-automation-id="adf-confirm-dialog-reject"
cdkFocusInitial>{{ noLabel | translate }}</button>
</mat-dialog-actions>

View File

@@ -26,6 +26,7 @@ import { By } from '@angular/platform-browser';
describe('Confirm Dialog Component', () => {
let fixture: ComponentFixture<ConfirmDialogComponent>;
let component: ConfirmDialogComponent;
const dialogRef = {
close: jasmine.createSpy('close')
};
@@ -140,4 +141,27 @@ describe('Confirm Dialog Component', () => {
expect(messageElement.nativeElement.innerText).toBe('MAYBE NO');
});
});
describe('thirdOptionLabel is given', () => {
it('should NOT render the thirdOption if is thirdOptionLabel is not passed', () => {
component.thirdOptionLabel = undefined;
fixture.detectChanges();
const thirdOptionElement = fixture.debugElement.query(
By.css('[data-automation-id="adf-confirm-dialog-confirm-all"]')
);
expect(thirdOptionElement).toBeFalsy();
});
it('should render the thirdOption if thirdOptionLabel is passed', () => {
component.thirdOptionLabel = 'Yes All';
fixture.detectChanges();
const thirdOptionElement = fixture.debugElement.query(
By.css('[data-automation-id="adf-confirm-dialog-confirm-all"]')
);
expect(thirdOptionElement).not.toBeNull();
expect(thirdOptionElement.nativeElement.innerText).toBe('YES ALL');
});
});
});

View File

@@ -32,6 +32,7 @@ export class ConfirmDialogComponent {
message: string;
yesLabel: string;
noLabel: string;
thirdOptionLabel: string;
htmlContent: string;
constructor(@Inject(MAT_DIALOG_DATA) data, private sanitizer: DomSanitizer) {
@@ -39,6 +40,7 @@ export class ConfirmDialogComponent {
this.title = data.title || 'ADF_CONFIRM_DIALOG.CONFIRM';
this.message = data.message || 'ADF_CONFIRM_DIALOG.MESSAGE';
this.yesLabel = data.yesLabel || 'ADF_CONFIRM_DIALOG.YES_LABEL';
this.thirdOptionLabel = data.thirdOptionLabel;
this.noLabel = data.noLabel || 'ADF_CONFIRM_DIALOG.NO_LABEL';
this.htmlContent = data.htmlContent;
}
@@ -46,4 +48,5 @@ export class ConfirmDialogComponent {
public sanitizedHtmlContent() {
return this.sanitizer.sanitize(SecurityContext.HTML, this.htmlContent);
}
}