import 'reflect-metadata'; import DropdownSelectBoxComponent from './dropdown-select-box.component'; const initDropdownSelectBoxComponent = () => { return new DropdownSelectBoxComponent(); }; describe('ngOnInit', () => { // tslint:disable-next-line test('Calls updateDisplayValue', () => { const dropdownSelectBoxComponent = initDropdownSelectBoxComponent(); dropdownSelectBoxComponent.updateDisplayValue = jest.fn(); dropdownSelectBoxComponent.ngOnInit(); expect( dropdownSelectBoxComponent.updateDisplayValue, ).toHaveBeenCalled(); }); }); describe('updateDisplayValue', () => { // tslint:disable-next-line test('Sets displayValue to the correct value', () => { const dropdownSelectBoxComponent = initDropdownSelectBoxComponent(); dropdownSelectBoxComponent.value = 'test'; dropdownSelectBoxComponent.displayValue = null; dropdownSelectBoxComponent.options = { test: '123', }; dropdownSelectBoxComponent.updateDisplayValue(); expect(dropdownSelectBoxComponent.displayValue) .toBe('123'); }); }); describe('toggleOptions', () => { // tslint:disable-next-line test('Sets areOptionsVisible to false if areOptionsVisible is true', () => { const dropdownSelectBoxComponent = initDropdownSelectBoxComponent(); dropdownSelectBoxComponent.areOptionsVisible = true; dropdownSelectBoxComponent.toggleOptions(); expect( dropdownSelectBoxComponent.areOptionsVisible, ).toBe(false); }); // tslint:disable-next-line test('Sets areOptionsVisible to false if areOptionsVisible is true', () => { const dropdownSelectBoxComponent = initDropdownSelectBoxComponent(); dropdownSelectBoxComponent.areOptionsVisible = false; dropdownSelectBoxComponent.toggleOptions(); expect( dropdownSelectBoxComponent.areOptionsVisible, ).toBe(true); }); }); describe('optionSelected', () => { // tslint:disable-next-line test('Sets value to optionKey used as argument', () => { const dropdownSelectBoxComponent = initDropdownSelectBoxComponent(); dropdownSelectBoxComponent.value = null; dropdownSelectBoxComponent.updateDisplayValue = jest.fn(); dropdownSelectBoxComponent.optionSelected('test'); expect( dropdownSelectBoxComponent.value, ).toBe('test'); }); // tslint:disable-next-line test('Calls updateDisplayValue', () => { const dropdownSelectBoxComponent = initDropdownSelectBoxComponent(); dropdownSelectBoxComponent.updateDisplayValue = jest.fn(); dropdownSelectBoxComponent.updateDisplayValue(); expect(dropdownSelectBoxComponent.updateDisplayValue) .toHaveBeenCalled(); }); // tslint:disable-next-line test('Calls onChange.emit with the argument passed to the function', () => { const dropdownSelectBoxComponent = initDropdownSelectBoxComponent(); dropdownSelectBoxComponent.onChange.emit = jest.fn(); dropdownSelectBoxComponent.updateDisplayValue = jest.fn(); dropdownSelectBoxComponent.optionSelected('test'); expect( dropdownSelectBoxComponent.onChange.emit, ).toHaveBeenCalledWith('test'); }); });