salix/client/core/src/components/icon-menu/icon-menu.spec.js

54 lines
1.7 KiB
JavaScript
Raw Normal View History

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(`<div class="shown"></div>`);
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'});
});
});
});