summaryrefslogtreecommitdiff
path: root/spec/frontend/frequent_items/components/frequent_items_search_input_spec.js
diff options
context:
space:
mode:
Diffstat (limited to 'spec/frontend/frequent_items/components/frequent_items_search_input_spec.js')
-rw-r--r--spec/frontend/frequent_items/components/frequent_items_search_input_spec.js62
1 files changed, 8 insertions, 54 deletions
diff --git a/spec/frontend/frequent_items/components/frequent_items_search_input_spec.js b/spec/frontend/frequent_items/components/frequent_items_search_input_spec.js
index cdd8b127676..0280fdb0ca2 100644
--- a/spec/frontend/frequent_items/components/frequent_items_search_input_spec.js
+++ b/spec/frontend/frequent_items/components/frequent_items_search_input_spec.js
@@ -1,8 +1,8 @@
+import { GlSearchBoxByType } from '@gitlab/ui';
import { shallowMount } from '@vue/test-utils';
import { mockTracking, unmockTracking } from 'helpers/tracking_helper';
import searchComponent from '~/frequent_items/components/frequent_items_search_input.vue';
import { createStore } from '~/frequent_items/store';
-import eventHub from '~/frequent_items/event_hub';
describe('FrequentItemsSearchInputComponent', () => {
let wrapper;
@@ -16,6 +16,8 @@ describe('FrequentItemsSearchInputComponent', () => {
propsData: { namespace },
});
+ const findSearchBoxByType = () => wrapper.find(GlSearchBoxByType);
+
beforeEach(() => {
store = createStore({ dropdownType: 'project' });
jest.spyOn(store, 'dispatch').mockImplementation(() => {});
@@ -33,59 +35,13 @@ describe('FrequentItemsSearchInputComponent', () => {
vm.$destroy();
});
- describe('methods', () => {
- describe('setFocus', () => {
- it('should set focus to search input', () => {
- jest.spyOn(vm.$refs.search, 'focus').mockImplementation(() => {});
-
- vm.setFocus();
-
- expect(vm.$refs.search.focus).toHaveBeenCalled();
- });
- });
- });
-
- describe('mounted', () => {
- it('should listen `dropdownOpen` event', (done) => {
- jest.spyOn(eventHub, '$on').mockImplementation(() => {});
- const vmX = createComponent().vm;
-
- vmX.$nextTick(() => {
- expect(eventHub.$on).toHaveBeenCalledWith(
- `${vmX.namespace}-dropdownOpen`,
- expect.any(Function),
- );
- done();
- });
- });
- });
-
- describe('beforeDestroy', () => {
- it('should unbind event listeners on eventHub', (done) => {
- const vmX = createComponent().vm;
- jest.spyOn(eventHub, '$off').mockImplementation(() => {});
-
- vmX.$mount();
- vmX.$destroy();
-
- vmX.$nextTick(() => {
- expect(eventHub.$off).toHaveBeenCalledWith(
- `${vmX.namespace}-dropdownOpen`,
- expect.any(Function),
- );
- done();
- });
- });
- });
-
describe('template', () => {
it('should render component element', () => {
expect(wrapper.classes()).toContain('search-input-container');
- expect(wrapper.find('input.form-control').exists()).toBe(true);
- expect(wrapper.find('.search-icon').exists()).toBe(true);
- expect(wrapper.find('input.form-control').attributes('placeholder')).toBe(
- 'Search your projects',
- );
+ expect(findSearchBoxByType().exists()).toBe(true);
+ expect(findSearchBoxByType().attributes()).toMatchObject({
+ placeholder: 'Search your projects',
+ });
});
});
@@ -96,9 +52,7 @@ describe('FrequentItemsSearchInputComponent', () => {
const value = 'my project';
- const input = wrapper.find('input');
- input.setValue(value);
- input.trigger('input');
+ findSearchBoxByType().vm.$emit('input', value);
await wrapper.vm.$nextTick();