2018-11-08 19:23:39 +05:30
|
|
|
import Vue from 'vue';
|
|
|
|
import searchComponent from '~/frequent_items/components/frequent_items_search_input.vue';
|
|
|
|
import eventHub from '~/frequent_items/event_hub';
|
2019-05-30 16:15:17 +05:30
|
|
|
import mountComponent from 'spec/helpers/vue_mount_component_helper';
|
2018-11-08 19:23:39 +05:30
|
|
|
|
|
|
|
const createComponent = (namespace = 'projects') => {
|
|
|
|
const Component = Vue.extend(searchComponent);
|
|
|
|
|
2019-05-30 16:15:17 +05:30
|
|
|
return mountComponent(Component, { namespace });
|
2018-11-08 19:23:39 +05:30
|
|
|
};
|
|
|
|
|
|
|
|
describe('FrequentItemsSearchInputComponent', () => {
|
|
|
|
let vm;
|
|
|
|
|
|
|
|
beforeEach(() => {
|
2019-05-30 16:15:17 +05:30
|
|
|
vm = createComponent();
|
2018-11-08 19:23:39 +05:30
|
|
|
});
|
|
|
|
|
|
|
|
afterEach(() => {
|
|
|
|
vm.$destroy();
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('methods', () => {
|
|
|
|
describe('setFocus', () => {
|
|
|
|
it('should set focus to search input', () => {
|
|
|
|
spyOn(vm.$refs.search, 'focus');
|
|
|
|
|
|
|
|
vm.setFocus();
|
2018-12-13 13:39:08 +05:30
|
|
|
|
2018-11-08 19:23:39 +05:30
|
|
|
expect(vm.$refs.search.focus).toHaveBeenCalled();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('mounted', () => {
|
|
|
|
it('should listen `dropdownOpen` event', done => {
|
|
|
|
spyOn(eventHub, '$on');
|
2019-05-30 16:15:17 +05:30
|
|
|
const vmX = createComponent();
|
2018-11-08 19:23:39 +05:30
|
|
|
|
|
|
|
Vue.nextTick(() => {
|
|
|
|
expect(eventHub.$on).toHaveBeenCalledWith(
|
|
|
|
`${vmX.namespace}-dropdownOpen`,
|
|
|
|
jasmine.any(Function),
|
|
|
|
);
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('beforeDestroy', () => {
|
|
|
|
it('should unbind event listeners on eventHub', done => {
|
2019-05-30 16:15:17 +05:30
|
|
|
const vmX = createComponent();
|
2018-11-08 19:23:39 +05:30
|
|
|
spyOn(eventHub, '$off');
|
|
|
|
|
|
|
|
vmX.$mount();
|
|
|
|
vmX.$destroy();
|
|
|
|
|
|
|
|
Vue.nextTick(() => {
|
|
|
|
expect(eventHub.$off).toHaveBeenCalledWith(
|
|
|
|
`${vmX.namespace}-dropdownOpen`,
|
|
|
|
jasmine.any(Function),
|
|
|
|
);
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('template', () => {
|
|
|
|
it('should render component element', () => {
|
2019-05-30 16:15:17 +05:30
|
|
|
const inputEl = vm.$el.querySelector('input.form-control');
|
|
|
|
|
|
|
|
expect(vm.$el.classList.contains('search-input-container')).toBeTruthy();
|
|
|
|
expect(inputEl).not.toBe(null);
|
|
|
|
expect(inputEl.getAttribute('placeholder')).toBe('Search your projects');
|
|
|
|
expect(vm.$el.querySelector('.search-icon')).toBeDefined();
|
2018-11-08 19:23:39 +05:30
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|