diff --git a/client/core/src/components/icon-menu/icon-menu.spec.js b/client/core/src/components/icon-menu/icon-menu.spec.js new file mode 100644 index 000000000..7db2a3e8c --- /dev/null +++ b/client/core/src/components/icon-menu/icon-menu.spec.js @@ -0,0 +1,53 @@ +import './icon-menu.js'; + +describe('Component vnIconMenu', () => { + let $componentController; + let controller; + let $element; + + beforeEach(() => { + angular.mock.module('ticket'); + }); + + beforeEach(angular.mock.inject(_$componentController_ => { + $componentController = _$componentController_; + $element = angular.element(`
`); + controller = $componentController('vnIconMenu', {$element: $element, $transclude: null}); + })); + + describe('getFields()', () => { + it(`should return an array with the fields selectables`, () => { + let fields = controller.getFields(); + + expect(fields).toEqual(['id', 'name']); + }); + }); + + describe('onClick(event)', () => { + it(`should call preventDefault, onOpen and showDropdown`, () => { + let event = {preventDefault: () => {}}; + controller.onOpen = () => {}; + spyOn(event, 'preventDefault'); + spyOn(controller, 'showDropDown'); + spyOn(controller, 'onOpen'); + + controller.onClick(event); + + expect(event.preventDefault).toHaveBeenCalledWith(); + expect(controller.showDropDown).toHaveBeenCalledWith(); + expect(controller.onOpen).toHaveBeenCalledWith(); + }); + }); + + describe('onDropDownSelect(value)', () => { + it(`should set field to a given value and call onChange`, () => { + controller.onChange = () => {}; + spyOn(controller, 'onChange'); + + controller.onDropDownSelect('mariano'); + + expect(controller.field).toBe('mariano'); + expect(controller.onChange).toHaveBeenCalledWith({value: 'mariano'}); + }); + }); +});