it('should show', () => {
            dialogService.confirm({
                header: '',
                message: ''
            });

            fixture.detectChanges();
            const confirm = de.query(By.css('p-confirmDialog'));
            expect(confirm === null).toBe(false);
        });
        it('should add message', () => {
            dialogService.alert({
                header: 'Header Test',
                message: 'Hello world message'
            });

            fixture.detectChanges();
            const message = de.query(By.css('.ui-dialog-content p'));
            expect(message.nativeElement.textContent).toEqual('Hello world message');
        });
Example #3
0
  /**
   * Gets a child DebugElement by css selector.
   *
   * The child of DebugElement are other elements that are "known" to
   * Angular.
   */
  static getChildrenBySelector(parent: DebugElement, selector: string): DebugElement[] {
    const results = [];

    parent.queryAll(By.css(selector)).forEach((el) => results.push(el));
    parent.children.forEach((de) => {
      TestHelper.getChildrenBySelector(de, selector).forEach((el) => results.push(el));
    });

    return results;
  }
        it('should show only accept button', () => {
            dialogService.alert({
                header: '',
                message: ''
            });

            fixture.detectChanges();

            const buttons = de.queryAll(By.css('p-dialog button'));
            expect(buttons.length).toBe(1);
        });
        it('should have right attrs', () => {
            dialogService.confirm({
                header: '',
                message: ''
            });

            fixture.detectChanges();
            const confirm = de.query(By.css('p-confirmDialog')).componentInstance;
            expect(confirm.responsive).toBe(true, 'responsive');
            expect(confirm.width).toBe('400', 'width');
            expect(confirm.closable).toBe(false, 'closable');
        });
        it('should show only accept and reject buttons', () => {
            dialogService.alert({
                header: '',
                message: '',
                footerLabel: {
                    accept: 'accept',
                    reject: 'accept'
                }
            });

            fixture.detectChanges();

            const buttons = de.queryAll(By.css('p-dialog button'));
            expect(buttons.length).toBe(2);
        });
        it('should have right attrs', () => {
            dialogService.alert({
                header: 'Header Test',
                message: ''
            });

            fixture.detectChanges();
            const dialog = de.query(By.css('p-dialog')).componentInstance;

            expect(dialog.closable).toBe(false, 'closable');
            expect(dialog.draggable).toBe(false, 'draggable');
            expect(dialog.header).toBe('Header Test', 'header');
            expect(dialog.modal).toBe('modal', 'modal');
            expect(dialog.responsive).toBe(true, 'responsive');
            expect(dialog.visible).toBe(true, 'visible');
            expect(dialog.width).toBe('400', 'width');
        });
            fakeAsync(() => {
                spyOn(component, 'onClickConfirm');

                dialogService.confirm({
                    header: '',
                    message: ''
                });

                fixture.detectChanges(); // ngIf
                tick();
                fixture.detectChanges(); // confirmation service make it happen

                const buttons = de.queryAll(By.css('p-confirmDialog button'));
                buttons[0].nativeElement.click();
                expect(component.onClickConfirm).toHaveBeenCalledTimes(1);

                buttons[1].nativeElement.click();
                expect(component.onClickConfirm).toHaveBeenCalledTimes(2);
            })
        it('should bind accept and reject button events', () => {
            spyOn(dialogService, 'alertAccept');
            spyOn(dialogService, 'alertReject');

            dialogService.alert({
                header: '',
                message: '',
                footerLabel: {
                    accept: 'accept',
                    reject: 'reject'
                }
            });

            fixture.detectChanges();

            const buttons = de.queryAll(By.css('p-dialog button'));
            buttons[1].nativeElement.click();
            expect(dialogService.alertAccept).toHaveBeenCalledTimes(1);
            buttons[0].nativeElement.click();
            expect(dialogService.alertReject).toHaveBeenCalledTimes(1);
        });
Example #10
0
 it('should have confirm and dialog null by default', () => {
     const confirm = de.query(By.css('p-confirmDialog'));
     const alert = de.query(By.css('p-dialog'));
     expect(confirm === null).toBe(true);
     expect(alert === null).toBe(true);
 });