diff options
author | Chantal Rollison <afspirit04@gmail.com> | 2018-10-03 08:15:00 +0000 |
---|---|---|
committer | Tim Zallmann <tzallmann@gitlab.com> | 2018-10-03 08:15:00 +0000 |
commit | 38f3d59fd0b2dd4eef5c94512ea6216a0e5d56b5 (patch) | |
tree | ce34ad0daceb0e9aed942cfbb84425b39b66ae08 /spec | |
parent | 82ece8ad4584278ce437270470b54ff9b42c653b (diff) | |
download | gitlab-ce-38f3d59fd0b2dd4eef5c94512ea6216a0e5d56b5.tar.gz |
#13650 added wip search functionality and tests
Diffstat (limited to 'spec')
6 files changed, 113 insertions, 14 deletions
diff --git a/spec/features/issues/filtered_search/dropdown_hint_spec.rb b/spec/features/issues/filtered_search/dropdown_hint_spec.rb index b99c5a7f4e3..0e296ab2109 100644 --- a/spec/features/issues/filtered_search/dropdown_hint_spec.rb +++ b/spec/features/issues/filtered_search/dropdown_hint_spec.rb @@ -15,6 +15,7 @@ describe 'Dropdown hint', :js do before do project.add_maintainer(user) create(:issue, project: project) + create(:merge_request, source_project: project, target_project: project) end context 'when user not logged in' do @@ -224,4 +225,21 @@ describe 'Dropdown hint', :js do end end end + + context 'merge request page' do + before do + sign_in(user) + visit project_merge_requests_path(project) + filtered_search.click + end + + it 'shows the WIP menu item and opens the WIP options dropdown' do + click_hint('wip') + + expect(page).to have_css(js_dropdown_hint, visible: false) + expect(page).to have_css('#js-dropdown-wip', visible: true) + expect_tokens([{ name: 'wip' }]) + expect_filtered_search_input_empty + end + end end diff --git a/spec/finders/merge_requests_finder_spec.rb b/spec/finders/merge_requests_finder_spec.rb index 35d0eeda8f6..33d01697c75 100644 --- a/spec/finders/merge_requests_finder_spec.rb +++ b/spec/finders/merge_requests_finder_spec.rb @@ -16,12 +16,18 @@ describe MergeRequestsFinder do p end let(:project4) { create(:project, :public, group: subgroup) } + let(:project5) { create(:project, :public, group: subgroup) } + let(:project6) { create(:project, :public, group: subgroup) } let!(:merge_request1) { create(:merge_request, :simple, author: user, source_project: project2, target_project: project1) } let!(:merge_request2) { create(:merge_request, :conflict, author: user, source_project: project2, target_project: project1, state: 'closed') } - let!(:merge_request3) { create(:merge_request, :simple, author: user, source_project: project2, target_project: project2, state: 'locked') } - let!(:merge_request4) { create(:merge_request, :simple, author: user, source_project: project3, target_project: project3) } - let!(:merge_request5) { create(:merge_request, :simple, author: user, source_project: project4, target_project: project4) } + let!(:merge_request3) { create(:merge_request, :simple, author: user, source_project: project2, target_project: project2, state: 'locked', title: 'thing WIP thing') } + let!(:merge_request4) { create(:merge_request, :simple, author: user, source_project: project3, target_project: project3, title: 'WIP thing') } + let!(:merge_request5) { create(:merge_request, :simple, author: user, source_project: project4, target_project: project4, title: '[WIP]') } + let!(:merge_request6) { create(:merge_request, :simple, author: user, source_project: project5, target_project: project5, title: 'WIP: thing') } + let!(:merge_request7) { create(:merge_request, :simple, author: user, source_project: project6, target_project: project6, title: 'wip thing') } + let!(:merge_request8) { create(:merge_request, :simple, author: user, source_project: project1, target_project: project1, title: '[wip] thing') } + let!(:merge_request9) { create(:merge_request, :simple, author: user, source_project: project1, target_project: project2, title: 'wip: thing') } before do project1.add_maintainer(user) @@ -29,19 +35,21 @@ describe MergeRequestsFinder do project3.add_developer(user) project2.add_developer(user2) project4.add_developer(user) + project5.add_developer(user) + project6.add_developer(user) end describe "#execute" do it 'filters by scope' do params = { scope: 'authored', state: 'opened' } merge_requests = described_class.new(user, params).execute - expect(merge_requests.size).to eq(3) + expect(merge_requests.size).to eq(7) end it 'filters by project' do params = { project_id: project1.id, scope: 'authored', state: 'opened' } merge_requests = described_class.new(user, params).execute - expect(merge_requests.size).to eq(1) + expect(merge_requests.size).to eq(2) end it 'filters by group' do @@ -49,7 +57,7 @@ describe MergeRequestsFinder do merge_requests = described_class.new(user, params).execute - expect(merge_requests.size).to eq(2) + expect(merge_requests.size).to eq(3) end it 'filters by group including subgroups', :nested_groups do @@ -57,13 +65,13 @@ describe MergeRequestsFinder do merge_requests = described_class.new(user, params).execute - expect(merge_requests.size).to eq(3) + expect(merge_requests.size).to eq(6) end it 'filters by non_archived' do params = { non_archived: true } merge_requests = described_class.new(user, params).execute - expect(merge_requests.size).to eq(4) + expect(merge_requests.size).to eq(8) end it 'filters by iid' do @@ -98,6 +106,36 @@ describe MergeRequestsFinder do expect(merge_requests).to contain_exactly(merge_request3) end + it 'filters by wip' do + params = { wip: 'yes' } + + merge_requests = described_class.new(user, params).execute + + expect(merge_requests).to contain_exactly(merge_request4, merge_request5, merge_request6, merge_request7, merge_request8, merge_request9) + end + + it 'filters by not wip' do + params = { wip: 'no' } + + merge_requests = described_class.new(user, params).execute + + expect(merge_requests).to contain_exactly(merge_request1, merge_request2, merge_request3) + end + + it 'returns all items if no valid wip param exists' do + params = { wip: '' } + + merge_requests = described_class.new(user, params).execute + + expect(merge_requests).to contain_exactly(merge_request1, merge_request2, merge_request3, merge_request4, merge_request5, merge_request6, merge_request7, merge_request8, merge_request9) + end + + it 'adds wip to scalar params' do + scalar_params = described_class.scalar_params + + expect(scalar_params).to include(:wip, :assignee_id) + end + context 'filtering by group milestone' do let!(:group) { create(:group, :public) } let(:group_milestone) { create(:milestone, group: group) } @@ -207,7 +245,7 @@ describe MergeRequestsFinder do it 'returns the number of rows for the default state' do finder = described_class.new(user) - expect(finder.row_count).to eq(3) + expect(finder.row_count).to eq(7) end it 'returns the number of rows for a given state' do diff --git a/spec/javascripts/filtered_search/dropdown_utils_spec.js b/spec/javascripts/filtered_search/dropdown_utils_spec.js index 8792e99d461..68bbbf838da 100644 --- a/spec/javascripts/filtered_search/dropdown_utils_spec.js +++ b/spec/javascripts/filtered_search/dropdown_utils_spec.js @@ -288,13 +288,13 @@ describe('Dropdown Utils', () => { describe('setDataValueIfSelected', () => { beforeEach(() => { - spyOn(FilteredSearchDropdownManager, 'addWordToInput') - .and.callFake(() => {}); + spyOn(FilteredSearchDropdownManager, 'addWordToInput').and.callFake(() => {}); }); it('calls addWordToInput when dataValue exists', () => { const selected = { getAttribute: () => 'value', + hasAttribute: () => false, }; DropdownUtils.setDataValueIfSelected(null, selected); @@ -304,6 +304,7 @@ describe('Dropdown Utils', () => { it('returns true when dataValue exists', () => { const selected = { getAttribute: () => 'value', + hasAttribute: () => false, }; const result = DropdownUtils.setDataValueIfSelected(null, selected); diff --git a/spec/javascripts/filtered_search/filtered_search_visual_tokens_spec.js b/spec/javascripts/filtered_search/filtered_search_visual_tokens_spec.js index 756a654765b..53a6d1d62b0 100644 --- a/spec/javascripts/filtered_search/filtered_search_visual_tokens_spec.js +++ b/spec/javascripts/filtered_search/filtered_search_visual_tokens_spec.js @@ -240,13 +240,17 @@ describe('Filtered Search Visual Tokens', () => { beforeEach(() => { setFixtures(` <div class="test-area"> - ${subject.createVisualTokenElementHTML()} + ${subject.createVisualTokenElementHTML('custom-token')} </div> `); tokenElement = document.querySelector('.test-area').firstElementChild; }); + it('should add class name to token element', () => { + expect(document.querySelector('.test-area .custom-token')).toBeDefined(); + }); + it('contains name div', () => { expect(tokenElement.querySelector('.name')).toEqual(jasmine.anything()); }); @@ -280,7 +284,7 @@ describe('Filtered Search Visual Tokens', () => { describe('addVisualTokenElement', () => { it('renders search visual tokens', () => { - subject.addVisualTokenElement('search term', null, true); + subject.addVisualTokenElement('search term', null, { isSearchTerm: true }); const token = tokensContainer.querySelector('.js-visual-token'); expect(token.classList.contains('filtered-search-term')).toEqual(true); diff --git a/spec/models/merge_request_spec.rb b/spec/models/merge_request_spec.rb index 48f4e53b93e..666d7e69f89 100644 --- a/spec/models/merge_request_spec.rb +++ b/spec/models/merge_request_spec.rb @@ -746,7 +746,7 @@ describe MergeRequest do end describe "#wipless_title" do - ['WIP ', 'WIP:', 'WIP: ', '[WIP]', '[WIP] ', ' [WIP] WIP [WIP] WIP: WIP '].each do |wip_prefix| + ['WIP ', 'WIP:', 'WIP: ', '[WIP]', '[WIP] ', '[WIP] WIP [WIP] WIP: WIP '].each do |wip_prefix| it "removes the '#{wip_prefix}' prefix" do wipless_title = subject.title subject.title = "#{wip_prefix}#{subject.title}" diff --git a/spec/requests/api/merge_requests_spec.rb b/spec/requests/api/merge_requests_spec.rb index e987eee6e91..07d19e3ad29 100644 --- a/spec/requests/api/merge_requests_spec.rb +++ b/spec/requests/api/merge_requests_spec.rb @@ -81,6 +81,35 @@ describe API::MergeRequests do let(:user2) { create(:user) } it 'returns an array of all merge requests except unauthorized ones' do + get api('/merge_requests', user), scope: :all + + expect(response).to have_gitlab_http_status(200) + expect(response).to include_pagination_headers + expect(json_response).to be_an Array + expect(json_response.map { |mr| mr['id'] }) + .to contain_exactly(merge_request.id, merge_request_closed.id, merge_request_merged.id, merge_request_locked.id, merge_request2.id) + end + + it "returns an array of no merge_requests when wip=yes" do + get api("/merge_requests", user), wip: 'yes' + + expect(response).to have_gitlab_http_status(200) + expect(response).to include_pagination_headers + expect(json_response).to be_an Array + expect(json_response.length).to eq(0) + end + + it "returns an array of no merge_requests when wip=no" do + get api("/merge_requests", user), wip: 'no' + + expect(response).to have_gitlab_http_status(200) + expect(response).to include_pagination_headers + expect(json_response).to be_an Array + expect(json_response.map { |mr| mr['id'] }) + .to contain_exactly(merge_request.id, merge_request_closed.id, merge_request_merged.id, merge_request_locked.id, merge_request2.id) + end + + it 'does not return unauthorized merge requests' do private_project = create(:project, :private) merge_request3 = create(:merge_request, :simple, source_project: private_project, target_project: private_project, source_branch: 'other-branch') @@ -244,6 +273,15 @@ describe API::MergeRequests do expect(response).to have_gitlab_http_status(404) end + it "returns an array of no merge_requests when wip=yes" do + get api("/projects/#{project.id}/merge_requests", user), wip: 'yes' + + expect(response).to have_gitlab_http_status(200) + expect(response).to include_pagination_headers + expect(json_response).to be_an Array + expect(json_response.length).to eq(0) + end + it 'returns merge_request by "iids" array' do get api(endpoint_path, user), iids: [merge_request.iid, merge_request_closed.iid] |