本文整理匯總了TypeScript中app/service/dialog.service.DialogService類的典型用法代碼示例。如果您正苦於以下問題:TypeScript service.DialogService類的具體用法?TypeScript service.DialogService怎麽用?TypeScript service.DialogService使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
在下文中一共展示了service.DialogService類的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。
示例1: describe
describe('MetronDialogComponent', () => {
let component: MetronDialogComponent;
let fixture: ComponentFixture<MetronDialogComponent>;
let dialogService: DialogService;
beforeEach(() => {
TestBed.configureTestingModule({
declarations: [MetronDialogComponent],
providers: [DialogService]
});
fixture = TestBed.createComponent(MetronDialogComponent);
component = fixture.componentInstance;
fixture.detectChanges();
dialogService = TestBed.get(DialogService);
});
it('should create', () => {
expect(component).toBeTruthy();
});
it('should show when showModal is true', () => {
component.showModal = false;
fixture.detectChanges();
let modal = fixture.nativeElement.querySelector('[data-qe-id="modal"]');
expect(modal).toBeNull();
component.showModal = true;
fixture.detectChanges();
modal = fixture.nativeElement.querySelector('[data-qe-id="modal"]');
expect(modal).toBeTruthy();
});
it('should display the passed message', () => {
const testMessage = 'This is a confirmation message';
dialogService.launchDialog(testMessage);
fixture.detectChanges();
const modalMessage = fixture.nativeElement.querySelector(
'[data-qe-id="modal-message"]'
);
expect(modalMessage.textContent).toBe(testMessage);
});
it('should display the correct title based on the dialog type', () => {
dialogService.launchDialog('');
fixture.detectChanges();
let modalTitle = fixture.nativeElement.querySelector(
'[data-qe-id="modal-title"]'
);
expect(modalTitle.textContent).toBe('Confirmation');
dialogService.launchDialog('', DialogType.Error);
fixture.detectChanges();
modalTitle = fixture.nativeElement.querySelector(
'[data-qe-id="modal-title"]'
);
expect(modalTitle.textContent).toBe('Error');
});
it('should execute cancel() when the cancel button is clicked', () => {
dialogService.launchDialog('');
const cancelSpy = spyOn(component, 'cancel').and.callThrough();
fixture.detectChanges();
const cancelButton = fixture.nativeElement.querySelector(
'[data-qe-id="modal-cancel"]'
);
cancelButton.click();
expect(cancelSpy).toHaveBeenCalled();
expect(component.showModal).toBe(false);
});
it('should execute confirm() when the ok button is clicked', () => {
dialogService.launchDialog('');
const confirmSpy = spyOn(component, 'confirm').and.callThrough();
fixture.detectChanges();
const confirmButton = fixture.nativeElement.querySelector(
'[data-qe-id="modal-confirm"]'
);
confirmButton.click();
expect(confirmSpy).toHaveBeenCalled();
expect(component.showModal).toBe(false);
});
it('should only display a cancel() button when the dialog type is Error', () => {
dialogService.launchDialog('', DialogType.Error);
fixture.detectChanges();
const errorCancelButton = fixture.nativeElement.querySelector(
'[data-qe-id="modal-error-cancel"]'
);
expect(errorCancelButton).toBeTruthy();
const confirmCancelButton = fixture.nativeElement.querySelector(
'[data-qe-id="modal-cancel"]'
);
expect(confirmCancelButton).toBeNull();
const confirmApproveButton = fixture.nativeElement.querySelector(
'[data-qe-id="modal-confirm"]'
//.........這裏部分代碼省略.........
示例2: it
it('should display the correct title based on the dialog type', () => {
dialogService.launchDialog('');
fixture.detectChanges();
let modalTitle = fixture.nativeElement.querySelector(
'[data-qe-id="modal-title"]'
);
expect(modalTitle.textContent).toBe('Confirmation');
dialogService.launchDialog('', DialogType.Error);
fixture.detectChanges();
modalTitle = fixture.nativeElement.querySelector(
'[data-qe-id="modal-title"]'
);
expect(modalTitle.textContent).toBe('Error');
});