|
// Karmaşık olarak tanımlanan bileşeni sarmallayan bileşin test implementasyonu |
|
import { ComponentFixture, TestBed } from '@angular/core/testing'; |
|
import { Listbox } from 'primeng/listbox'; |
|
import { By } from '@angular/platform-browser'; |
|
import { CountrySelectorComponent } from './country-selector.component'; |
|
|
|
describe('CountrySelectorComponent', () => { |
|
let component: CountrySelectorComponent; |
|
let fixture: ComponentFixture<CountrySelectorComponent>; |
|
let listBoxComponent: Listbox; |
|
beforeEach(async () => { |
|
await TestBed.configureTestingModule({ |
|
declarations: [CountrySelectorComponent], |
|
}).compileComponents(); |
|
}); |
|
|
|
beforeEach(() => { |
|
fixture = TestBed.createComponent(CountrySelectorComponent); |
|
component = fixture.componentInstance; |
|
fixture.detectChanges(); |
|
listBoxComponent = fixture.debugElement.query( |
|
By.css('p-listbox') |
|
).componentInstance; |
|
}); |
|
|
|
it('should create', () => { |
|
expect(component).toBeTruthy(); |
|
}); |
|
|
|
it('Should set default properties of p-listbox', () => { |
|
expect(listBoxComponent.filterPlaceHolder).toBe('Ülke arayın'); |
|
expect(listBoxComponent.filterLocale).toBe('tr-TR'); |
|
expect(listBoxComponent.emptyFilterMessage).toBe( |
|
'Aradığınız ülke bulunamadı' |
|
); |
|
expect(listBoxComponent.emptyMessage).toBe('Kayıtlı ülke yok'); |
|
expect(listBoxComponent.options).toBeDefined(); |
|
expect(listBoxComponent.optionLabel).toBe('label'); |
|
expect(listBoxComponent.optionValue).toBe('value'); |
|
for (let option of listBoxComponent.options) { |
|
expect(option.label).toBeDefined(); |
|
expect(option.value).toBeDefined(); |
|
} |
|
}); |
|
|
|
it('Should be able to pass ariaFilterLabel value to p-listbox', () => { |
|
component.ariaFilterLabel = 'TestValue'; |
|
fixture.detectChanges(); |
|
expect(listBoxComponent.ariaFilterLabel).toBe('TestValue'); |
|
}); |
|
|
|
it('Should be able to pass checkbox value to p-listbox ', () => { |
|
component.checkbox = true; |
|
fixture.detectChanges(); |
|
expect(listBoxComponent.checkbox).toBe(true); |
|
}); |
|
|
|
it('Should be able to pass disabled value to p-listbox', () => { |
|
component.disabled = true; |
|
fixture.detectChanges(); |
|
expect(listBoxComponent.disabled).toBe(true); |
|
}); |
|
|
|
it('Should be able to pass filter value to p-listbox', () => { |
|
component.filter = true; |
|
fixture.detectChanges(); |
|
expect(listBoxComponent.filter).toBe(true); |
|
}); |
|
|
|
it('Should be able to pass filterMatchMode value to p-listbox', () => { |
|
component.filterMatchMode = 'eq'; |
|
fixture.detectChanges(); |
|
expect(listBoxComponent.filterMatchMode).toBe('eq'); |
|
}); |
|
|
|
it('Should be able to pass filterValue value to p-listbox', () => { |
|
component.filterValue = 'TestValue'; |
|
fixture.detectChanges(); |
|
expect(listBoxComponent.filterValue).toEqual('TestValue'); |
|
}); |
|
it('Should be able to pass listStyle value to p-listbox', () => { |
|
component.listStyle = 'TestValue'; |
|
fixture.detectChanges(); |
|
expect(listBoxComponent.listStyle).toBe('TestValue'); |
|
}); |
|
|
|
it('Should be able to pass listStyleClass value to p-listbox', () => { |
|
component.listStyleClass = 'TestValue'; |
|
fixture.detectChanges(); |
|
expect(listBoxComponent.listStyleClass).toBe('TestValue'); |
|
}); |
|
|
|
it('Should be able to pass metaKeySelection value to p-listbox', () => { |
|
component.metaKeySelection = true; |
|
fixture.detectChanges(); |
|
expect(listBoxComponent.metaKeySelection).toBe(true); |
|
}); |
|
|
|
it('Should be able to pass multiple value to p-listbox', () => { |
|
component.multiple = true; |
|
fixture.detectChanges(); |
|
expect(listBoxComponent.multiple).toBe(true); |
|
}); |
|
|
|
it('Should be able to pass readonly value to p-listbox', () => { |
|
component.readonly = true; |
|
fixture.detectChanges(); |
|
expect(listBoxComponent.readonly).toBe(true); |
|
}); |
|
|
|
it('Should be able to pass optionDisabled value to p-listbox', () => { |
|
component.optionDisabled = 'TestValue'; |
|
fixture.detectChanges(); |
|
expect(listBoxComponent.optionDisabled).toBe('TestValue'); |
|
}); |
|
|
|
it('Should be able to pass showToggleAll value to p-listbox', () => { |
|
component.showToggleAll = true; |
|
fixture.detectChanges(); |
|
expect(listBoxComponent.showToggleAll).toBe(true); |
|
}); |
|
|
|
it('Should be able to pass style value to p-listbox', () => { |
|
component.style = 'TestValue'; |
|
fixture.detectChanges(); |
|
expect(listBoxComponent.style).toBe('TestValue'); |
|
}); |
|
|
|
it('Should be able to pass styleClass value to p-listbox', () => { |
|
component.styleClass = 'TestValue'; |
|
fixture.detectChanges(); |
|
expect(listBoxComponent.styleClass).toBe('TestValue'); |
|
}); |
|
|
|
it('handleListBoxChange: Should propagete the touched, onChange events.', () => { |
|
const touchedSpy = jasmine.createSpy('TouchedSpy'); |
|
const onChangeSpy = spyOn(component.onChange, 'next'); |
|
const eventData = { value: 'TestValue' }; |
|
component.registerOnTouched(touchedSpy); |
|
component.handleListBoxChange(eventData); |
|
expect(touchedSpy).toHaveBeenCalled(); |
|
expect(onChangeSpy).toHaveBeenCalled(); |
|
expect(onChangeSpy.calls.mostRecent().args[0]).toEqual(eventData); |
|
}); |
|
|
|
it('handleListBoxDblClick: Should propagete the touched, onDblClick events.', () => { |
|
const touchedSpy = jasmine.createSpy('TouchedSpy'); |
|
const dblClickSpy = spyOn(component.onDblClick, 'next'); |
|
const eventData = { |
|
value: 'TestValue', |
|
option: { label: 'TestValue', value: 'TV' }, |
|
}; |
|
component.registerOnTouched(touchedSpy); |
|
component.handleListBoxDblClick(eventData); |
|
expect(touchedSpy).toHaveBeenCalled(); |
|
expect(dblClickSpy).toHaveBeenCalled(); |
|
expect(dblClickSpy.calls.mostRecent().args[0]).toEqual(eventData); |
|
}); |
|
|
|
it('handleListBoxClick: Should propagete the touched, onClick events.', () => { |
|
const touchedSpy = jasmine.createSpy('TouchedSpy'); |
|
const clickSpy = spyOn(component.onClick, 'next'); |
|
const eventData = { |
|
value: 'TestValue', |
|
option: { label: 'TestValue', value: 'TV' }, |
|
}; |
|
component.registerOnTouched(touchedSpy); |
|
component.handleListBoxClick(eventData); |
|
expect(touchedSpy).toHaveBeenCalled(); |
|
expect(clickSpy).toHaveBeenCalled(); |
|
expect(clickSpy.calls.mostRecent().args[0]).toEqual(eventData); |
|
}); |
|
|
|
it('writeValue: Should be able to set currentValue propert', () => { |
|
component.writeValue('TestValue'); |
|
expect(component.currentValue).toBe('TestValue'); |
|
component.writeValue(undefined); |
|
expect(component.currentValue).toBe(undefined); |
|
}); |
|
|
|
it('setDisabledState: Should be able to set disable property', () => { |
|
component.setDisabledState(true); |
|
expect(component.disabled).toBeTrue(); |
|
}); |
|
|
|
it('ngOnDestory: Should complete events',()=>{ |
|
const onClickSpy = spyOn(component.onClick, 'complete'); |
|
const onChangeSpy = spyOn(component.onChange, 'complete'); |
|
const onDblClickSpy = spyOn(component.onDblClick,'complete'); |
|
component.ngOnDestroy(); |
|
expect(onClickSpy).toHaveBeenCalled(); |
|
expect(onChangeSpy).toHaveBeenCalled(); |
|
expect(onDblClickSpy).toHaveBeenCalled(); |
|
}); |
|
}); |