describe('Component vnButtonMenu', () => {
    let controller;
    let $element;

    beforeEach(ngModule('vnCore'));

    beforeEach(inject(($compile, $rootScope) => {
        $element = $compile(`<vn-icon-menu></vn-icon-menu>`)($rootScope);
        controller = $element.controller('vnIconMenu');
        controller.valueField = 'name';
    }));

    afterEach(() => {
        $element.remove();
    });

    describe('onButtonClick(event)', () => {
        it(`should emit the open event`, () => {
            jest.spyOn(controller, 'emit');

            let event = new MouseEvent('click', {
                view: controller.element.window,
                bubbles: true,
                cancelable: true
            });
            controller.onButtonClick(event);

            expect(controller.emit).toHaveBeenCalledWith('open');
        });
    });

    describe('onDropDownSelect(value)', () => {
        it(`should set field to the given value and emit the change event`, () => {
            jest.spyOn(controller, 'emit');
            controller.onDropDownSelect({name: 'Item name'});

            expect(controller.field).toBe('Item name');
            expect(controller.emit).toHaveBeenCalledWith('change', {value: 'Item name'});
        });
    });
});