<commit_before>import { TestBed, ComponentFixture, fakeAsync, tick } from '@angular/core/testing';
import { By } from '@angular/platform-browser';
import { Dialog } from './dialog';
import { NoopAnimationsModule } from '@angular/platform-browser/animations';
import { Component } from '@angular/core';
import { Footer } from 'primeng/api';

@Component({
    template: `
    <p-dialog [(visible)]="display">
    <p-footer>
            <button type="button" pButton icon="pi pi-check" (click)="display=false" label="Yes"></button>
            <button type="button" pButton icon="pi pi-times" (click)="display=false" label="No" class="ui-button-secondary"></button>
    </p-footer>
    </p-dialog>
    <button type="button" (click)="showDialog()" pButton icon="pi pi-info-circle" label="Show"></button>
    `
  })
  class TestDialogComponent {
    display: boolean = false;

    showDialog() {
        this.display = true;
    }
  }

describe('Dialog', () => {
    
    let dialog: Dialog;
    let fixture: ComponentFixture<TestDialogComponent>;
    let testComponent: TestDialogComponent;
    
    beforeEach(() => {
        TestBed.configureTestingModule({
            imports: [
                NoopAnimationsModule    
            ],
            declarations: [
                Dialog,
                Footer,
                TestDialogComponent
            ]
        });
        
        fixture = TestBed.createComponent(TestDialogComponent);
        dialog = fixture.debugElement.children[0].componentInstance;
        testComponent = fixture.debugElement.componentInstance;
    });
    
    it('should display the header', () => {
        dialog.header = 'PrimeNG Dialog Header';
        fixture.detectChanges();
        
        const buttonEl = fixture.debugElement.query(By.css('button'));
        buttonEl.nativeElement.click();
        fixture.detectChanges();

        const headerEl = fixture.debugElement.query(By.css('.ui-dialog-title'));
        expect(headerEl.nativeElement.textContent).toContain('PrimeNG Dialog Header')
    });
    
    it('should display the close icon when closable', () => {
        const buttonEl = fixture.debugElement.query(By.css('button'));
        buttonEl.nativeElement.click();
        fixture.detectChanges();
        
        const closeEl = fixture.debugElement.query(By.css('.ui-dialog-titlebar-close'));
        expect(closeEl).not.toBeNull();
    });
    
    it('should display the resizer when resizable is true', () => {
        const buttonEl = fixture.debugElement.query(By.css('button'));
        buttonEl.nativeElement.click();
        fixture.detectChanges();

        const resizeEl = fixture.debugElement.query(By.css('.ui-resizable-handle'));
        expect(resizeEl).not.toBeNull();
    });

    it('should not create the container element by default', () => {
        fixture.detectChanges();

        expect(fixture.debugElement.children[0].nativeElement.childElementCount).toEqual(0);
        expect(dialog.visible).toEqual(false);
    });
    
    it('should add rtl class when rtl is enabled', () => {
        dialog.rtl = true;
        const buttonEl = fixture.debugElement.query(By.css('button'));
        buttonEl.nativeElement.click();
        fixture.detectChanges();

        const rtlEl = fixture.debugElement.query(By.css('.ui-dialog-rtl'));
        expect(rtlEl).toBeTruthy();
    });
    
    it('should add draggable class when dragging is enabled', () => {
        const buttonEl = fixture.debugElement.query(By.css('button'));
        buttonEl.nativeElement.click();
        fixture.detectChanges();

        const draggableEl = fixture.debugElement.query(By.css('.ui-dialog-draggable'));
        expect(draggableEl).toBeTruthy();
    });
            
    it('should update visible as false binding when close icon is clicked', () => {
        let show = true;
        const buttonEl = fixture.debugElement.query(By.css('button'));
        buttonEl.nativeElement.click();
        fixture.detectChanges();
        dialog.visibleChange.subscribe(value => show = value);
        
        const closeEl = fixture.nativeElement.querySelector('.ui-dialog-titlebar-close');
        closeEl.click();
        
        expect(show).toEqual(false);
    });

    it('should maximizable', fakeAsync(() => {
        dialog.maximizable = true;
        fixture.detectChanges();

        const buttonEl = fixture.debugElement.query(By.css('button'));
        buttonEl.nativeElement.click();
        fixture.detectChanges();
        
        tick(300);
        const maximizeSpy = spyOn(dialog,'maximize').and.callThrough();
        const revertMaximizSpy = spyOn(dialog,'revertMaximize').and.callThrough();
        const maximizableEl = fixture.nativeElement.querySelector('.ui-dialog-titlebar-maximize');
        expect(maximizableEl).toBeTruthy();
        maximizableEl.click();
        fixture.detectChanges();

        const minIconEl = fixture.debugElement.query(By.css('.pi-window-minimize'));
        expect(maximizeSpy).toHaveBeenCalled();
        expect(dialog.maximized).toEqual(true);
        expect(minIconEl).toBeTruthy();
        dialog.container = fixture.debugElement.query(By.css('div')).nativeElement;
        fixture.detectChanges();

        maximizableEl.click();
        tick(350);
        fixture.detectChanges();

        expect(revertMaximizSpy).toHaveBeenCalled();
        expect(dialog.maximized).toEqual(false);
    }));

    it('should close (maximized)', fakeAsync(() => {
        dialog.maximizable = true;<commit_msg>Dialog unit test fixed<commit_after>import { TestBed, ComponentFixture, fakeAsync, tick } from '@angular/core/testing';
import { By } from '@angular/platform-browser';
import { Dialog } from './dialog';
import { NoopAnimationsModule } from '@angular/platform-browser/animations';
import { Component } from '@angular/core';
import { Footer } from 'primeng/api';

@Component({
    template: `
    <p-dialog [(visible)]="display">
    <p-footer>
            <button type="button" pButton icon="pi pi-check" (click)="display=false" label="Yes"></button>
            <button type="button" pButton icon="pi pi-times" (click)="display=false" label="No" class="ui-button-secondary"></button>
    </p-footer>
    </p-dialog>
    <button type="button" (click)="showDialog()" pButton icon="pi pi-info-circle" label="Show"></button>
    `
  })
  class TestDialogComponent {
    display: boolean = false;

    showDialog() {
        this.display = true;
    }
  }

describe('Dialog', () => {
    
    let dialog: Dialog;
    let fixture: ComponentFixture<TestDialogComponent>;
    let testComponent: TestDialogComponent;
    
    beforeEach(() => {
        TestBed.configureTestingModule({
            imports: [
                NoopAnimationsModule    
            ],
            declarations: [
                Dialog,
                Footer,
                TestDialogComponent
            ]
        });
        
        fixture = TestBed.createComponent(TestDialogComponent);
        dialog = fixture.debugElement.children[0].componentInstance;
        testComponent = fixture.debugElement.componentInstance;
    });
    
    it('should display the header', () => {
        dialog.header = 'PrimeNG Dialog Header';
        fixture.detectChanges();
        
        const buttonEl = fixture.debugElement.query(By.css('button'));
        buttonEl.nativeElement.click();
        fixture.detectChanges();

        const headerEl = fixture.debugElement.query(By.css('.ui-dialog-title'));
        expect(headerEl.nativeElement.textContent).toContain('PrimeNG Dialog Header')
    });
    
    it('should display the close icon when closable', () => {
        const buttonEl = fixture.debugElement.query(By.css('button'));
        buttonEl.nativeElement.click();
        fixture.detectChanges();
        
        const closeEl = fixture.debugElement.query(By.css('.ui-dialog-titlebar-close'));
        expect(closeEl).not.toBeNull();
    });
    
    it('should display the resizer when resizable is true', () => {
        const buttonEl = fixture.debugElement.query(By.css('button'));
        buttonEl.nativeElement.click();
        fixture.detectChanges();

        const resizeEl = fixture.debugElement.query(By.css('.ui-resizable-handle'));
        expect(resizeEl).not.toBeNull();
    });

    it('should not create the container element by default', () => {
        fixture.detectChanges();

        expect(fixture.debugElement.children[0].nativeElement.childElementCount).toEqual(0);
        expect(dialog.visible).toEqual(false);
    });
    
    it('should add rtl class when rtl is enabled', () => {
        dialog.rtl = true;
        const buttonEl = fixture.debugElement.query(By.css('button'));
        buttonEl.nativeElement.click();
        fixture.detectChanges();

        const rtlEl = fixture.debugElement.query(By.css('.ui-dialog-rtl'));
        expect(rtlEl).toBeTruthy();
    });
    
    it('should add draggable class when dragging is enabled', () => {
        const buttonEl = fixture.debugElement.query(By.css('button'));
        buttonEl.nativeElement.click();
        fixture.detectChanges();

        const draggableEl = fixture.debugElement.query(By.css('.ui-dialog-draggable'));
        expect(draggableEl).toBeTruthy();
    });
            
    it('should update visible as false binding when close icon is clicked', () => {
        let show = true;
        const buttonEl = fixture.debugElement.query(By.css('button'));
        buttonEl.nativeElement.click();
        fixture.detectChanges();
        dialog.visibleChange.subscribe(value => show = value);
        
        const closeEl = fixture.nativeElement.querySelector('.ui-dialog-titlebar-close');
        closeEl.click();
        
        expect(show).toEqual(false);
    });

    it('should maximizable', fakeAsync(() => {
        dialog.maximizable = true;
        fixture.detectChanges();

        const buttonEl = fixture.debugElement.query(By.css('button'));
        buttonEl.nativeElement.click();
        fixture.detectChanges();
        
        tick(300);
        const maximizeSpy = spyOn(dialog,'maximize').and.callThrough();
        const maximizableEl = fixture.nativeElement.querySelector('.ui-dialog-titlebar-maximize');
        expect(maximizableEl).toBeTruthy();
        maximizableEl.click();
        fixture.detectChanges();

        const minIconEl = fixture.debugElement.query(By.css('.pi-window-minimize'));
        expect(maximizeSpy).toHaveBeenCalled();
        expect(dialog.maximized).toEqual(true);
        expect(minIconEl).toBeTruthy();
        dialog.container = fixture.debugElement.query(By.css('div')).nativeElement;
        fixture.detectChanges();

        maximizableEl.click();
        tick(350);
        fixture.detectChanges();

        expect(dialog.maximized).toEqual(false);
    }));

    it('should close (maximized)', fakeAsync(() => {
        dialog.maximizable = true;
{'fraction_non_alphanumeric': 0.14097037512611207, 'fraction_numerical': 0.0016509217646519306, 'mean_word_length': 2.7393689986282577, 'pattern_counts': {'":': 0, '<': 25, '<?xml version=': 0, '>': 49, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2876377', 'n_tokens_mistral': 3007, 'n_tokens_neox': 2985, 'n_words': 516}