Commit c308510a authored by Phil Hughes's avatar Phil Hughes

Merge branch '349398' into 'master'

349398 - Update search field in Global Search

See merge request gitlab-org/gitlab!80916
parents ad51aba1 c7720cb3
<script> <script>
import { GlForm, GlSearchBoxByType, GlButton } from '@gitlab/ui'; import { GlSearchBoxByClick } from '@gitlab/ui';
import { mapState, mapActions } from 'vuex'; import { mapState, mapActions } from 'vuex';
import { s__ } from '~/locale';
import GroupFilter from './group_filter.vue'; import GroupFilter from './group_filter.vue';
import ProjectFilter from './project_filter.vue'; import ProjectFilter from './project_filter.vue';
export default { export default {
name: 'GlobalSearchTopbar', name: 'GlobalSearchTopbar',
i18n: {
searchPlaceholder: s__(`GlobalSearch|Search for projects, issues, etc.`),
searchLabel: s__(`GlobalSearch|What are you searching for?`),
},
components: { components: {
GlForm, GlSearchBoxByClick,
GlSearchBoxByType,
GroupFilter, GroupFilter,
ProjectFilter, ProjectFilter,
GlButton,
}, },
props: { props: {
groupInitialData: { groupInitialData: {
...@@ -49,28 +52,24 @@ export default { ...@@ -49,28 +52,24 @@ export default {
</script> </script>
<template> <template>
<gl-form class="search-page-form" @submit.prevent="applyQuery"> <section class="search-page-form gl-lg-display-flex gl-align-items-flex-end">
<section class="gl-lg-display-flex gl-align-items-flex-end"> <div class="gl-flex-grow-1 gl-mb-4 gl-lg-mb-0 gl-lg-mr-2">
<div class="gl-flex-grow-1 gl-mb-4 gl-lg-mb-0 gl-lg-mr-2"> <label>{{ $options.i18n.searchLabel }}</label>
<label>{{ __('What are you searching for?') }}</label> <gl-search-box-by-click
<gl-search-box-by-type id="dashboard_search"
id="dashboard_search" v-model="search"
v-model="search" name="search"
name="search" :placeholder="$options.i18n.searchPlaceholder"
:placeholder="__(`Search for projects, issues, etc.`)" @submit="applyQuery"
/> />
</div> </div>
<div v-if="showFilters" class="gl-mb-4 gl-lg-mb-0 gl-lg-mx-2"> <div v-if="showFilters" class="gl-mb-4 gl-lg-mb-0 gl-lg-mx-2">
<label class="gl-display-block">{{ __('Group') }}</label> <label class="gl-display-block">{{ __('Group') }}</label>
<group-filter :initial-data="groupInitialData" /> <group-filter :initial-data="groupInitialData" />
</div> </div>
<div v-if="showFilters" class="gl-mb-4 gl-lg-mb-0 gl-lg-mx-2"> <div v-if="showFilters" class="gl-mb-4 gl-lg-mb-0 gl-lg-mx-2">
<label class="gl-display-block">{{ __('Project') }}</label> <label class="gl-display-block">{{ __('Project') }}</label>
<project-filter :initial-data="projectInitialData" /> <project-filter :initial-data="projectInitialData" />
</div> </div>
<gl-button class="btn-search gl-lg-ml-2" category="primary" variant="confirm" type="submit" </section>
>{{ __('Search') }}
</gl-button>
</section>
</gl-form>
</template> </template>
...@@ -10,7 +10,7 @@ RSpec.describe 'User searches for epics', :js do ...@@ -10,7 +10,7 @@ RSpec.describe 'User searches for epics', :js do
def search_for_epic(search) def search_for_epic(search)
fill_in('dashboard_search', with: search) fill_in('dashboard_search', with: search)
find('.btn-search').click find('.gl-search-box-by-click-search-button').click
select_search_scope('Epics') select_search_scope('Epics')
end end
......
...@@ -16840,6 +16840,9 @@ msgstr "" ...@@ -16840,6 +16840,9 @@ msgstr ""
msgid "GlobalSearch|Search GitLab" msgid "GlobalSearch|Search GitLab"
msgstr "" msgstr ""
msgid "GlobalSearch|Search for projects, issues, etc."
msgstr ""
msgid "GlobalSearch|Search results are loading" msgid "GlobalSearch|Search results are loading"
msgstr "" msgstr ""
...@@ -16852,6 +16855,9 @@ msgstr "" ...@@ -16852,6 +16855,9 @@ msgstr ""
msgid "GlobalSearch|Type for new suggestions to appear below." msgid "GlobalSearch|Type for new suggestions to appear below."
msgstr "" msgstr ""
msgid "GlobalSearch|What are you searching for?"
msgstr ""
msgid "GlobalSearch|in all GitLab" msgid "GlobalSearch|in all GitLab"
msgstr "" msgstr ""
...@@ -41416,9 +41422,6 @@ msgstr "" ...@@ -41416,9 +41422,6 @@ msgstr ""
msgid "What are project audit events?" msgid "What are project audit events?"
msgstr "" msgstr ""
msgid "What are you searching for?"
msgstr ""
msgid "What does this command do?" msgid "What does this command do?"
msgstr "" msgstr ""
......
...@@ -42,7 +42,7 @@ RSpec.describe 'User searches for code' do ...@@ -42,7 +42,7 @@ RSpec.describe 'User searches for code' do
it 'finds code and links to blob' do it 'finds code and links to blob' do
fill_in('dashboard_search', with: 'rspec') fill_in('dashboard_search', with: 'rspec')
find('.btn-search').click find('.gl-search-box-by-click-search-button').click
expect(page).to have_selector('.results', text: 'Update capybara, rspec-rails, poltergeist to recent versions') expect(page).to have_selector('.results', text: 'Update capybara, rspec-rails, poltergeist to recent versions')
...@@ -52,7 +52,7 @@ RSpec.describe 'User searches for code' do ...@@ -52,7 +52,7 @@ RSpec.describe 'User searches for code' do
it 'finds code and links to blame' do it 'finds code and links to blame' do
fill_in('dashboard_search', with: 'rspec') fill_in('dashboard_search', with: 'rspec')
find('.btn-search').click find('.gl-search-box-by-click-search-button').click
expect(page).to have_selector('.results', text: 'Update capybara, rspec-rails, poltergeist to recent versions') expect(page).to have_selector('.results', text: 'Update capybara, rspec-rails, poltergeist to recent versions')
...@@ -65,7 +65,7 @@ RSpec.describe 'User searches for code' do ...@@ -65,7 +65,7 @@ RSpec.describe 'User searches for code' do
search = 'for naming files' search = 'for naming files'
fill_in('dashboard_search', with: search) fill_in('dashboard_search', with: search)
find('.btn-search').click find('.gl-search-box-by-click-search-button').click
expect(page).to have_selector('.results', text: expected_result) expect(page).to have_selector('.results', text: expected_result)
...@@ -94,7 +94,7 @@ RSpec.describe 'User searches for code' do ...@@ -94,7 +94,7 @@ RSpec.describe 'User searches for code' do
expect(find('.js-project-refs-dropdown')).to have_text(ref_name) expect(find('.js-project-refs-dropdown')).to have_text(ref_name)
end end
it 'persists branch name across search' do it 'persists branch name across search' do
find('.btn-search').click find('.gl-search-box-by-click-search-button').click
expect(find('.js-project-refs-dropdown')).to have_text(ref_name) expect(find('.js-project-refs-dropdown')).to have_text(ref_name)
end end
......
...@@ -10,7 +10,7 @@ RSpec.describe 'User searches for issues', :js do ...@@ -10,7 +10,7 @@ RSpec.describe 'User searches for issues', :js do
def search_for_issue(search) def search_for_issue(search)
fill_in('dashboard_search', with: search) fill_in('dashboard_search', with: search)
find('.btn-search').click find('.gl-search-box-by-click-search-button').click
select_search_scope('Issues') select_search_scope('Issues')
end end
......
...@@ -10,7 +10,7 @@ RSpec.describe 'User searches for merge requests', :js do ...@@ -10,7 +10,7 @@ RSpec.describe 'User searches for merge requests', :js do
def search_for_mr(search) def search_for_mr(search)
fill_in('dashboard_search', with: search) fill_in('dashboard_search', with: search)
find('.btn-search').click find('.gl-search-box-by-click-search-button').click
select_search_scope('Merge requests') select_search_scope('Merge requests')
end end
......
...@@ -20,7 +20,7 @@ RSpec.describe 'User searches for milestones', :js do ...@@ -20,7 +20,7 @@ RSpec.describe 'User searches for milestones', :js do
it 'finds a milestone' do it 'finds a milestone' do
fill_in('dashboard_search', with: milestone1.title) fill_in('dashboard_search', with: milestone1.title)
find('.btn-search').click find('.gl-search-box-by-click-search-button').click
select_search_scope('Milestones') select_search_scope('Milestones')
page.within('.results') do page.within('.results') do
...@@ -40,7 +40,7 @@ RSpec.describe 'User searches for milestones', :js do ...@@ -40,7 +40,7 @@ RSpec.describe 'User searches for milestones', :js do
end end
fill_in('dashboard_search', with: milestone1.title) fill_in('dashboard_search', with: milestone1.title)
find('.btn-search').click find('.gl-search-box-by-click-search-button').click
select_search_scope('Milestones') select_search_scope('Milestones')
page.within('.results') do page.within('.results') do
......
...@@ -28,7 +28,7 @@ RSpec.describe 'User searches for wiki pages', :js do ...@@ -28,7 +28,7 @@ RSpec.describe 'User searches for wiki pages', :js do
end end
fill_in('dashboard_search', with: search_term) fill_in('dashboard_search', with: search_term)
find('.btn-search').click find('.gl-search-box-by-click-search-button').click
select_search_scope('Wiki') select_search_scope('Wiki')
page.within('.results') do page.within('.results') do
......
import { GlForm, GlSearchBoxByType, GlButton } from '@gitlab/ui'; import { GlSearchBoxByClick } from '@gitlab/ui';
import { shallowMount } from '@vue/test-utils'; import { shallowMount } from '@vue/test-utils';
import Vue from 'vue'; import Vue from 'vue';
import Vuex from 'vuex'; import Vuex from 'vuex';
...@@ -36,40 +36,19 @@ describe('GlobalSearchTopbar', () => { ...@@ -36,40 +36,19 @@ describe('GlobalSearchTopbar', () => {
wrapper.destroy(); wrapper.destroy();
}); });
const findTopbarForm = () => wrapper.find(GlForm); const findGlSearchBox = () => wrapper.find(GlSearchBoxByClick);
const findGlSearchBox = () => wrapper.find(GlSearchBoxByType);
const findGroupFilter = () => wrapper.find(GroupFilter); const findGroupFilter = () => wrapper.find(GroupFilter);
const findProjectFilter = () => wrapper.find(ProjectFilter); const findProjectFilter = () => wrapper.find(ProjectFilter);
const findSearchButton = () => wrapper.find(GlButton);
describe('template', () => { describe('template', () => {
beforeEach(() => { beforeEach(() => {
createComponent(); createComponent();
}); });
it('renders Topbar Form always', () => {
expect(findTopbarForm().exists()).toBe(true);
});
describe('Search box', () => { describe('Search box', () => {
it('renders always', () => { it('renders always', () => {
expect(findGlSearchBox().exists()).toBe(true); expect(findGlSearchBox().exists()).toBe(true);
}); });
describe('onSearch', () => {
const testSearch = 'test search';
beforeEach(() => {
findGlSearchBox().vm.$emit('input', testSearch);
});
it('calls setQuery when input event is fired from GlSearchBoxByType', () => {
expect(actionSpies.setQuery).toHaveBeenCalledWith(expect.any(Object), {
key: 'search',
value: testSearch,
});
});
});
}); });
describe.each` describe.each`
...@@ -92,10 +71,6 @@ describe('GlobalSearchTopbar', () => { ...@@ -92,10 +71,6 @@ describe('GlobalSearchTopbar', () => {
expect(findProjectFilter().exists()).toBe(showFilters); expect(findProjectFilter().exists()).toBe(showFilters);
}); });
}); });
it('renders SearchButton always', () => {
expect(findSearchButton().exists()).toBe(true);
});
}); });
describe('actions', () => { describe('actions', () => {
...@@ -103,8 +78,8 @@ describe('GlobalSearchTopbar', () => { ...@@ -103,8 +78,8 @@ describe('GlobalSearchTopbar', () => {
createComponent(); createComponent();
}); });
it('clicking SearchButton calls applyQuery', () => { it('clicking search button inside search box calls applyQuery', () => {
findTopbarForm().vm.$emit('submit', { preventDefault: () => {} }); findGlSearchBox().vm.$emit('submit', { preventDefault: () => {} });
expect(actionSpies.applyQuery).toHaveBeenCalled(); expect(actionSpies.applyQuery).toHaveBeenCalled();
}); });
......
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