|
// Basit olarak tanımlanan bileşeni sarmallayan bileşin test implementasyonu |
|
import { ComponentFixture, TestBed } from '@angular/core/testing'; |
|
import { By } from '@angular/platform-browser'; |
|
import { Button, ButtonModule } from 'primeng/button'; |
|
import { SaveButtonComponent } from './save-button.component'; |
|
|
|
describe('SaveButtonComponent', () => { |
|
let component: SaveButtonComponent; |
|
let fixture: ComponentFixture<SaveButtonComponent>; |
|
let buttonComponent: Button; |
|
beforeEach(async () => { |
|
await TestBed.configureTestingModule({ |
|
imports:[ButtonModule], |
|
declarations: [ SaveButtonComponent ] |
|
}) |
|
.compileComponents(); |
|
}); |
|
|
|
beforeEach(() => { |
|
fixture = TestBed.createComponent(SaveButtonComponent); |
|
component = fixture.componentInstance; |
|
fixture.detectChanges(); |
|
buttonComponent = fixture.debugElement.query(By.css('p-button')).componentInstance; |
|
}); |
|
|
|
it('should create', () => { |
|
expect(component).toBeTruthy(); |
|
}); |
|
|
|
it('Should set default properties of p-button',()=>{ |
|
expect(buttonComponent.type).toEqual('submit'); |
|
expect(buttonComponent.icon).toEqual('pi pi-save'); |
|
expect(buttonComponent.iconPos).toEqual('left'); |
|
expect(buttonComponent.loadingIcon).toEqual('pi pi-spinner pi-spin'); |
|
}); |
|
|
|
it('Should be able to pass badge value to p-button.',()=>{ |
|
component.badge = 'TestValue'; |
|
fixture.detectChanges(); |
|
expect(buttonComponent.badge).toEqual('TestValue'); |
|
}); |
|
|
|
it('Should be able to pass badgeClass value to p-button.',()=>{ |
|
component.badgeClass = 'TestValue'; |
|
fixture.detectChanges(); |
|
expect(buttonComponent.badgeClass).toEqual('TestValue'); |
|
}); |
|
|
|
it('Should be able to pass disable value to p-button.',()=>{ |
|
component.disabled = true; |
|
fixture.detectChanges(); |
|
expect(buttonComponent.disabled).toBeTrue(); |
|
component.disabled = false; |
|
fixture.detectChanges(); |
|
expect(buttonComponent.disabled).toBeFalse(); |
|
}); |
|
|
|
it('Should be able to pass style value to p-button',()=>{ |
|
component.style = 'TestValue'; |
|
fixture.detectChanges(); |
|
expect(buttonComponent.style).toEqual('TestValue'); |
|
}); |
|
|
|
it('Should be able to pass styleClass value to p-button',()=>{ |
|
component.styleClass = 'TestValue'; |
|
fixture.detectChanges(); |
|
expect(buttonComponent.styleClass).toEqual('TestValue'); |
|
}); |
|
|
|
it('Should be able to emit onClick event from p-button',()=>{ |
|
const onClickSpy = spyOn(component.onClick,'next'); |
|
buttonComponent.onClick.next(); |
|
expect(onClickSpy).toHaveBeenCalled(); |
|
}); |
|
|
|
it('Should be able to emit onFocus event from p-button',()=>{ |
|
const onFocusSpy = spyOn(component.onFocus,'next'); |
|
buttonComponent.onFocus.next(); |
|
expect(onFocusSpy).toHaveBeenCalled(); |
|
}); |
|
|
|
it('Should be able to emit onBlur event from p-button',()=>{ |
|
const onBlurSpy = spyOn(component.onBlur,'next'); |
|
buttonComponent.onBlur.next(); |
|
expect(onBlurSpy).toHaveBeenCalled(); |
|
}); |
|
|
|
it('Should complete events when destroying',()=>{ |
|
const onClickCompleteSpy = spyOn(component.onClick,'complete'); |
|
const onFocusCompleteSpy = spyOn(component.onFocus,'complete'); |
|
const onBlurCompleteSpy = spyOn(component.onBlur,'complete'); |
|
component.ngOnDestroy(); |
|
expect(onClickCompleteSpy).toHaveBeenCalled(); |
|
expect(onFocusCompleteSpy).toHaveBeenCalled(); |
|
expect(onBlurCompleteSpy).toHaveBeenCalled(); |
|
}); |
|
|
|
}); |