salix/front/core/components/button-menu/index.spec.js

44 lines
1.3 KiB
JavaScript
Raw Normal View History

2018-11-08 08:32:41 +00:00
describe('Component vnButtonMenu', () => {
2018-11-06 13:27:16 +00:00
let controller;
let $element;
2019-09-13 14:09:14 +00:00
beforeEach(angular.mock.module('vnCore', $translateProvider => {
$translateProvider.translations('en', {});
}));
2018-10-18 18:48:21 +00:00
beforeEach(inject(($compile, $rootScope) => {
$element = $compile(`<vn-icon-menu></vn-icon-menu>`)($rootScope);
2018-11-06 13:27:16 +00:00
controller = $element.controller('vnIconMenu');
controller.valueField = 'name';
}));
2018-10-18 18:48:21 +00:00
afterEach(() => {
$element.remove();
});
describe('onClick(event)', () => {
2018-10-18 18:48:21 +00:00
it(`should emit the open event`, () => {
2018-11-06 13:27:16 +00:00
spyOn(controller, 'emit');
2018-10-18 18:48:21 +00:00
let event = new MouseEvent('click', {
2018-11-06 13:27:16 +00:00
view: controller.element.window,
2018-10-18 18:48:21 +00:00
bubbles: true,
cancelable: true
});
2018-11-06 13:27:16 +00:00
controller.onClick(event);
2018-10-18 18:48:21 +00:00
2018-11-06 13:27:16 +00:00
expect(controller.emit).toHaveBeenCalledWith('open');
});
});
describe('onDropDownSelect(value)', () => {
2018-10-18 18:48:21 +00:00
it(`should set field to the given value and emit the change event`, () => {
2018-11-06 13:27:16 +00:00
spyOn(controller, 'emit');
controller.onDropDownSelect({name: 'Item name'});
expect(controller.field).toBe('Item name');
expect(controller.emit).toHaveBeenCalledWith('change', {value: 'Item name'});
});
});
});