Commit 8d94a488 authored by Yogi's avatar Yogi Committed by Nicolò Maria Mezzopera

Apply new GitLab UI for search in "frequent items search" dropdown

parent 41f7a751
<script> <script>
import { debounce } from 'lodash'; import { debounce } from 'lodash';
import { mapActions, mapState } from 'vuex'; import { mapActions, mapState } from 'vuex';
import { GlIcon } from '@gitlab/ui'; import { GlSearchBoxByType } from '@gitlab/ui';
import Tracking from '~/tracking'; import Tracking from '~/tracking';
import frequentItemsMixin from './frequent_items_mixin'; import frequentItemsMixin from './frequent_items_mixin';
...@@ -9,7 +9,7 @@ const trackingMixin = Tracking.mixin(); ...@@ -9,7 +9,7 @@ const trackingMixin = Tracking.mixin();
export default { export default {
components: { components: {
GlIcon, GlSearchBoxByType,
}, },
mixins: [frequentItemsMixin, trackingMixin], mixins: [frequentItemsMixin, trackingMixin],
data() { data() {
...@@ -33,22 +33,15 @@ export default { ...@@ -33,22 +33,15 @@ export default {
}, },
methods: { methods: {
...mapActions(['setSearchQuery']), ...mapActions(['setSearchQuery']),
setFocus() {
this.$refs.search.focus();
},
}, },
}; };
</script> </script>
<template> <template>
<div class="search-input-container d-none d-sm-block"> <div class="search-input-container d-none d-sm-block">
<input <gl-search-box-by-type
ref="search"
v-model="searchQuery" v-model="searchQuery"
:placeholder="translations.searchInputPlaceholder" :placeholder="translations.searchInputPlaceholder"
type="search"
class="form-control"
/> />
<gl-icon v-if="!searchQuery" name="search" class="search-icon" />
</div> </div>
</template> </template>
---
title: Apply new GitLab UI for search in frequent items search
merge_request: 53368
author: Yogi (@yo)
type: other
import { shallowMount } from '@vue/test-utils'; import { shallowMount } from '@vue/test-utils';
import { GlSearchBoxByType } from '@gitlab/ui';
import { mockTracking, unmockTracking } from 'helpers/tracking_helper'; import { mockTracking, unmockTracking } from 'helpers/tracking_helper';
import searchComponent from '~/frequent_items/components/frequent_items_search_input.vue'; import searchComponent from '~/frequent_items/components/frequent_items_search_input.vue';
import { createStore } from '~/frequent_items/store'; import { createStore } from '~/frequent_items/store';
...@@ -15,6 +16,8 @@ describe('FrequentItemsSearchInputComponent', () => { ...@@ -15,6 +16,8 @@ describe('FrequentItemsSearchInputComponent', () => {
propsData: { namespace }, propsData: { namespace },
}); });
const findSearchBoxByType = () => wrapper.find(GlSearchBoxByType);
beforeEach(() => { beforeEach(() => {
store = createStore({ dropdownType: 'project' }); store = createStore({ dropdownType: 'project' });
jest.spyOn(store, 'dispatch').mockImplementation(() => {}); jest.spyOn(store, 'dispatch').mockImplementation(() => {});
...@@ -32,26 +35,13 @@ describe('FrequentItemsSearchInputComponent', () => { ...@@ -32,26 +35,13 @@ describe('FrequentItemsSearchInputComponent', () => {
vm.$destroy(); 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('template', () => { describe('template', () => {
it('should render component element', () => { it('should render component element', () => {
expect(wrapper.classes()).toContain('search-input-container'); expect(wrapper.classes()).toContain('search-input-container');
expect(wrapper.find('input.form-control').exists()).toBe(true); expect(findSearchBoxByType().exists()).toBe(true);
expect(wrapper.find('.search-icon').exists()).toBe(true); expect(findSearchBoxByType().attributes()).toMatchObject({
expect(wrapper.find('input.form-control').attributes('placeholder')).toBe( placeholder: 'Search your projects',
'Search your projects', });
);
}); });
}); });
...@@ -62,9 +52,7 @@ describe('FrequentItemsSearchInputComponent', () => { ...@@ -62,9 +52,7 @@ describe('FrequentItemsSearchInputComponent', () => {
const value = 'my project'; const value = 'my project';
const input = wrapper.find('input'); findSearchBoxByType().vm.$emit('input', value);
input.setValue(value);
input.trigger('input');
await wrapper.vm.$nextTick(); await wrapper.vm.$nextTick();
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment