diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-03-23 12:09:42 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-03-23 12:09:42 +0300 |
commit | e4bf776a8829e5186a0f63603c0be627b891d80e (patch) | |
tree | 537fe714bd336bfee9f30b101a5072950a04a62a /spec | |
parent | 1635eacd2a9293cd04d21e82def6e2c14ed01242 (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec')
-rw-r--r-- | spec/frontend/fixtures/search.rb | 15 | ||||
-rw-r--r-- | spec/frontend/pages/search/show/highlight_blob_search_result_spec.js | 15 | ||||
-rw-r--r-- | spec/frontend/search_spec.js | 44 |
3 files changed, 60 insertions, 14 deletions
diff --git a/spec/frontend/fixtures/search.rb b/spec/frontend/fixtures/search.rb index 025cc53c745..cbe3e373986 100644 --- a/spec/frontend/fixtures/search.rb +++ b/spec/frontend/fixtures/search.rb @@ -16,4 +16,19 @@ describe SearchController, '(JavaScript fixtures)', type: :controller do expect(response).to be_successful end + + context 'search within a project' do + let(:namespace) { create(:namespace, name: 'frontend-fixtures') } + let(:project) { create(:project, :public, :repository, namespace: namespace, path: 'search-project') } + + it 'search/blob_search_result.html' do + get :show, params: { + search: 'Send', + project_id: project.id, + scope: :blobs + } + + expect(response).to be_successful + end + end end diff --git a/spec/frontend/pages/search/show/highlight_blob_search_result_spec.js b/spec/frontend/pages/search/show/highlight_blob_search_result_spec.js new file mode 100644 index 00000000000..4083a65df75 --- /dev/null +++ b/spec/frontend/pages/search/show/highlight_blob_search_result_spec.js @@ -0,0 +1,15 @@ +import setHighlightClass from '~/pages/search/show/highlight_blob_search_result'; + +const fixture = 'search/blob_search_result.html'; + +describe('pages/search/show/highlight_blob_search_result', () => { + preloadFixtures(fixture); + + beforeEach(() => loadFixtures(fixture)); + + it('highlights lines with search term occurrence', () => { + setHighlightClass(); + + expect(document.querySelectorAll('.blob-result .hll').length).toBe(11); + }); +}); diff --git a/spec/frontend/search_spec.js b/spec/frontend/search_spec.js index af93fa88f72..1573365538c 100644 --- a/spec/frontend/search_spec.js +++ b/spec/frontend/search_spec.js @@ -1,8 +1,10 @@ import $ from 'jquery'; import Api from '~/api'; import Search from '~/pages/search/show/search'; +import setHighlightClass from '~/pages/search/show/highlight_blob_search_result'; jest.mock('~/api'); +jest.mock('~/pages/search/show/highlight_blob_search_result'); describe('Search', () => { const fixturePath = 'search/show.html'; @@ -16,27 +18,41 @@ describe('Search', () => { preloadFixtures(fixturePath); - beforeEach(() => { - loadFixtures(fixturePath); - new Search(); // eslint-disable-line no-new + describe('constructor side effects', () => { + afterEach(() => { + jest.restoreAllMocks(); + }); + + it('highlights lines with search terms in blob search results', () => { + new Search(); // eslint-disable-line no-new + + expect(setHighlightClass).toHaveBeenCalled(); + }); }); - it('requests groups from backend when filtering', () => { - jest.spyOn(Api, 'groups').mockImplementation(term => { - expect(term).toBe(searchTerm); + describe('dropdown behavior', () => { + beforeEach(() => { + loadFixtures(fixturePath); + new Search(); // eslint-disable-line no-new }); - const inputElement = fillDropdownInput('.js-search-group-dropdown'); + it('requests groups from backend when filtering', () => { + jest.spyOn(Api, 'groups').mockImplementation(term => { + expect(term).toBe(searchTerm); + }); - $(inputElement).trigger('input'); - }); + const inputElement = fillDropdownInput('.js-search-group-dropdown'); - it('requests projects from backend when filtering', () => { - jest.spyOn(Api, 'projects').mockImplementation(term => { - expect(term).toBe(searchTerm); + $(inputElement).trigger('input'); }); - const inputElement = fillDropdownInput('.js-search-project-dropdown'); - $(inputElement).trigger('input'); + it('requests projects from backend when filtering', () => { + jest.spyOn(Api, 'projects').mockImplementation(term => { + expect(term).toBe(searchTerm); + }); + const inputElement = fillDropdownInput('.js-search-project-dropdown'); + + $(inputElement).trigger('input'); + }); }); }); |