diff options
author | Sean McGivern <sean@mcgivern.me.uk> | 2017-06-16 19:29:35 +0300 |
---|---|---|
committer | Sean McGivern <sean@mcgivern.me.uk> | 2017-06-16 19:29:35 +0300 |
commit | c6701d45474acab6a2d687d2e2ffdaac5c0d5491 (patch) | |
tree | 5e18ab8b3e41bed293e4e1748f780c0fad94fd79 /spec | |
parent | 451cbe1f69d65b24568a53ec7aa4a7fba2c46933 (diff) | |
parent | 0520ee44985528d3076df1208bda7c6c7ff8ec79 (diff) |
Merge branch 'issue_20900' into 'master'
Remove issuable drag and drop and sorting from milestone view
Closes #20900
See merge request !11950
Diffstat (limited to 'spec')
-rw-r--r-- | spec/features/dashboard/milestone_tabs_spec.rb | 2 | ||||
-rw-r--r-- | spec/features/milestones/milestones_spec.rb | 151 | ||||
-rw-r--r-- | spec/models/concerns/milestoneish_spec.rb | 31 | ||||
-rw-r--r-- | spec/models/milestone_spec.rb | 29 | ||||
-rw-r--r-- | spec/requests/api/milestones_spec.rb | 42 |
5 files changed, 141 insertions, 114 deletions
diff --git a/spec/features/dashboard/milestone_tabs_spec.rb b/spec/features/dashboard/milestone_tabs_spec.rb index 0c7b992c500..2c48939bf9c 100644 --- a/spec/features/dashboard/milestone_tabs_spec.rb +++ b/spec/features/dashboard/milestone_tabs_spec.rb @@ -23,7 +23,7 @@ describe 'Dashboard milestone tabs', :js, :feature do it 'loads merge requests async' do click_link 'Merge Requests' - expect(page).to have_selector('.merge_requests-sortable-list') + expect(page).to have_selector('.milestone-merge_requests-list') end it 'loads participants async' do diff --git a/spec/features/milestones/milestones_spec.rb b/spec/features/milestones/milestones_spec.rb index c8a4d23f695..9e117c8ed9f 100644 --- a/spec/features/milestones/milestones_spec.rb +++ b/spec/features/milestones/milestones_spec.rb @@ -1,109 +1,102 @@ -require 'rails_helper' +# require 'rails_helper' -describe 'Milestone draggable', feature: true, js: true do - include DragTo +# describe 'Milestone draggable', feature: true, js: true do +# include DragTo - let(:milestone) { create(:milestone, project: project, title: 8.14) } - let(:project) { create(:empty_project, :public) } - let(:user) { create(:user) } +# let(:milestone) { create(:milestone, project: project, title: 8.14) } +# let(:project) { create(:empty_project, :public) } +# let(:user) { create(:user) } - context 'issues' do - let(:issue) { page.find_by_id('issues-list-unassigned').find('li') } - let(:issue_target) { page.find_by_id('issues-list-ongoing') } +# context 'issues' do +# let(:issue) { page.find_by_id('issues-list-unassigned').find('li') } +# let(:issue_target) { page.find_by_id('issues-list-ongoing') } - it 'does not allow guest to drag issue' do - create_and_drag_issue +# it 'does not allow guest to drag issue' do +# create_and_drag_issue - expect(issue_target).not_to have_selector('.issuable-row') - end +# expect(issue_target).not_to have_selector('.issuable-row') +# end - it 'does not allow authorized user to drag issue' do - login_as(user) - create_and_drag_issue +# it 'does not allow authorized user to drag issue' do +# login_as(user) +# create_and_drag_issue - expect(issue_target).not_to have_selector('.issuable-row') - end +# expect(issue_target).not_to have_selector('.issuable-row') +# end - it 'allows author to drag issue' do - login_as(user) - create_and_drag_issue(author: user) +# it 'allows author to drag issue' do +# login_as(user) +# create_and_drag_issue(author: user) - expect(issue_target).to have_selector('.issuable-row') - end +# expect(issue_target).to have_selector('.issuable-row') +# end - it 'allows admin to drag issue' do - login_as(:admin) - create_and_drag_issue +# it 'allows admin to drag issue' do +# login_as(:admin) - expect(issue_target).to have_selector('.issuable-row') - end +# create_and_drag_issue - it 'assigns issue when it has been dragged to ongoing list' do - login_as(:admin) - create_and_drag_issue +# expect(issue_target).to have_selector('.issuable-row') +# end +# end - expect(@issue.reload.assignees).not_to be_empty - expect(page).to have_selector("#sortable_issue_#{@issue.iid} .assignee-icon img", count: 1) - end - end +# context 'merge requests' do +# let(:merge_request) { page.find_by_id('merge_requests-list-unassigned').find('li') } +# let(:merge_request_target) { page.find_by_id('merge_requests-list-ongoing') } - context 'merge requests' do - let(:merge_request) { page.find_by_id('merge_requests-list-unassigned').find('li') } - let(:merge_request_target) { page.find_by_id('merge_requests-list-ongoing') } +# it 'does not allow guest to drag merge request' do +# create_and_drag_merge_request - it 'does not allow guest to drag merge request' do - create_and_drag_merge_request +# expect(merge_request_target).not_to have_selector('.issuable-row') +# end - expect(merge_request_target).not_to have_selector('.issuable-row') - end +# it 'does not allow authorized user to drag merge request' do +# login_as(user) +# create_and_drag_merge_request - it 'does not allow authorized user to drag merge request' do - login_as(user) - create_and_drag_merge_request +# expect(merge_request_target).not_to have_selector('.issuable-row') +# end - expect(merge_request_target).not_to have_selector('.issuable-row') - end +# it 'allows author to drag merge request' do +# login_as(user) +# create_and_drag_merge_request(author: user) - it 'allows author to drag merge request' do - login_as(user) - create_and_drag_merge_request(author: user) +# expect(merge_request_target).to have_selector('.issuable-row') +# end - expect(merge_request_target).to have_selector('.issuable-row') - end +# it 'allows admin to drag merge request' do +# login_as(:admin) +# create_and_drag_merge_request - it 'allows admin to drag merge request' do - login_as(:admin) - create_and_drag_merge_request +# expect(merge_request_target).to have_selector('.issuable-row') +# end +# end - expect(merge_request_target).to have_selector('.issuable-row') - end - end +# def create_and_drag_issue(params = {}) +# create(:issue, params.merge(title: 'Foo', project: project, milestone: milestone)) - def create_and_drag_issue(params = {}) - @issue = create(:issue, params.merge(title: 'Foo', project: project, milestone: milestone)) +# visit namespace_project_milestone_path(project.namespace, project, milestone) +# scroll_into_view('.milestone-content') +# drag_to(selector: '.issues-sortable-list', list_to_index: 1) - visit namespace_project_milestone_path(project.namespace, project, milestone) - scroll_into_view('.milestone-content') - drag_to(selector: '.issues-sortable-list', list_to_index: 1) +# wait_for_requests +# end - wait_for_requests - end +# def create_and_drag_merge_request(params = {}) +# create(:merge_request, params.merge(title: 'Foo', source_project: project, target_project: project, milestone: milestone)) - def create_and_drag_merge_request(params = {}) - create(:merge_request, params.merge(title: 'Foo', source_project: project, target_project: project, milestone: milestone)) +# visit namespace_project_milestone_path(project.namespace, project, milestone) +# page.find("a[href='#tab-merge-requests']").click - visit namespace_project_milestone_path(project.namespace, project, milestone) - page.find("a[href='#tab-merge-requests']").click +# wait_for_requests - wait_for_requests +# scroll_into_view('.milestone-content') +# drag_to(selector: '.merge_requests-sortable-list', list_to_index: 1) - scroll_into_view('.milestone-content') - drag_to(selector: '.merge_requests-sortable-list', list_to_index: 1) +# wait_for_requests +# end - wait_for_requests - end - - def scroll_into_view(selector) - page.evaluate_script("document.querySelector('#{selector}').scrollIntoView();") - end -end +# def scroll_into_view(selector) +# page.evaluate_script("document.querySelector('#{selector}').scrollIntoView();") +# end +# end diff --git a/spec/models/concerns/milestoneish_spec.rb b/spec/models/concerns/milestoneish_spec.rb index 675b730c557..cefe7fb6fea 100644 --- a/spec/models/concerns/milestoneish_spec.rb +++ b/spec/models/concerns/milestoneish_spec.rb @@ -19,12 +19,43 @@ describe Milestone, 'Milestoneish' do let!(:closed_security_issue_3) { create(:issue, :confidential, :closed, project: project, author: author, milestone: milestone) } let!(:closed_security_issue_4) { create(:issue, :confidential, :closed, project: project, assignees: [assignee], milestone: milestone) } let!(:merge_request) { create(:merge_request, source_project: project, target_project: project, milestone: milestone) } + let(:label_1) { create(:label, title: 'label_1', project: project, priority: 1) } + let(:label_2) { create(:label, title: 'label_2', project: project, priority: 2) } + let(:label_3) { create(:label, title: 'label_3', project: project) } before do project.team << [member, :developer] project.team << [guest, :guest] end + describe '#sorted_issues' do + it 'sorts issues by label priority' do + issue.labels << label_1 + security_issue_1.labels << label_2 + closed_issue_1.labels << label_3 + + issues = milestone.sorted_issues(member) + + expect(issues.first).to eq(issue) + expect(issues.second).to eq(security_issue_1) + expect(issues.third).not_to eq(closed_issue_1) + end + end + + describe '#sorted_merge_requests' do + it 'sorts merge requests by label priority' do + merge_request_1 = create(:labeled_merge_request, labels: [label_2], source_project: project, source_branch: 'branch_1', milestone: milestone) + merge_request_2 = create(:labeled_merge_request, labels: [label_1], source_project: project, source_branch: 'branch_2', milestone: milestone) + merge_request_3 = create(:labeled_merge_request, labels: [label_3], source_project: project, source_branch: 'branch_3', milestone: milestone) + + merge_requests = milestone.sorted_merge_requests + + expect(merge_requests.first).to eq(merge_request_2) + expect(merge_requests.second).to eq(merge_request_1) + expect(merge_requests.third).to eq(merge_request_3) + end + end + describe '#closed_items_count' do it 'does not count confidential issues for non project members' do expect(milestone.closed_items_count(non_member)).to eq 2 diff --git a/spec/models/milestone_spec.rb b/spec/models/milestone_spec.rb index aa1ce89ffd7..20b96c08a8f 100644 --- a/spec/models/milestone_spec.rb +++ b/spec/models/milestone_spec.rb @@ -144,35 +144,6 @@ describe Milestone, models: true do end end - describe '#sort_issues' do - let(:milestone) { create(:milestone) } - - let(:issue1) { create(:issue, milestone: milestone, position: 1) } - let(:issue2) { create(:issue, milestone: milestone, position: 2) } - let(:issue3) { create(:issue, milestone: milestone, position: 3) } - let(:issue4) { create(:issue, position: 42) } - - it 'sorts the given issues' do - milestone.sort_issues([issue3.id, issue2.id, issue1.id]) - - issue1.reload - issue2.reload - issue3.reload - - expect(issue1.position).to eq(3) - expect(issue2.position).to eq(2) - expect(issue3.position).to eq(1) - end - - it 'ignores issues not part of the milestone' do - milestone.sort_issues([issue3.id, issue2.id, issue1.id, issue4.id]) - - issue4.reload - - expect(issue4.position).to eq(42) - end - end - describe '.search' do let(:milestone) { create(:milestone, title: 'foo', description: 'bar') } diff --git a/spec/requests/api/milestones_spec.rb b/spec/requests/api/milestones_spec.rb index 40934c25afc..ab5ea3e8f2c 100644 --- a/spec/requests/api/milestones_spec.rb +++ b/spec/requests/api/milestones_spec.rb @@ -5,6 +5,9 @@ describe API::Milestones do let!(:project) { create(:empty_project, namespace: user.namespace ) } let!(:closed_milestone) { create(:closed_milestone, project: project, title: 'version1', description: 'closed milestone') } let!(:milestone) { create(:milestone, project: project, title: 'version2', description: 'open milestone') } + let(:label_1) { create(:label, title: 'label_1', project: project, priority: 1) } + let(:label_2) { create(:label, title: 'label_2', project: project, priority: 2) } + let(:label_3) { create(:label, title: 'label_3', project: project) } before do project.team << [user, :developer] @@ -228,6 +231,18 @@ describe API::Milestones do expect(json_response.first['milestone']['title']).to eq(milestone.title) end + it 'returns project issues sorted by label priority' do + issue_1 = create(:labeled_issue, project: project, milestone: milestone, labels: [label_3]) + issue_2 = create(:labeled_issue, project: project, milestone: milestone, labels: [label_1]) + issue_3 = create(:labeled_issue, project: project, milestone: milestone, labels: [label_2]) + + get api("/projects/#{project.id}/milestones/#{milestone.id}/issues", user) + + expect(json_response.first['id']).to eq(issue_2.id) + expect(json_response.second['id']).to eq(issue_3.id) + expect(json_response.third['id']).to eq(issue_1.id) + end + it 'matches V4 response schema for a list of issues' do get api("/projects/#{project.id}/milestones/#{milestone.id}/issues", user) @@ -244,8 +259,8 @@ describe API::Milestones do describe 'confidential issues' do let(:public_project) { create(:empty_project, :public) } let(:milestone) { create(:milestone, project: public_project) } - let(:issue) { create(:issue, project: public_project, position: 2) } - let(:confidential_issue) { create(:issue, confidential: true, project: public_project, position: 1) } + let(:issue) { create(:issue, project: public_project) } + let(:confidential_issue) { create(:issue, confidential: true, project: public_project) } before do public_project.team << [user, :developer] @@ -285,7 +300,10 @@ describe API::Milestones do expect(json_response.map { |issue| issue['id'] }).to include(issue.id) end - it 'returns issues ordered by position asc' do + it 'returns issues ordered by label priority' do + issue.labels << label_2 + confidential_issue.labels << label_1 + get api("/projects/#{public_project.id}/milestones/#{milestone.id}/issues", user) expect(response).to have_http_status(200) @@ -299,8 +317,8 @@ describe API::Milestones do end describe 'GET /projects/:id/milestones/:milestone_id/merge_requests' do - let(:merge_request) { create(:merge_request, source_project: project, position: 2) } - let(:another_merge_request) { create(:merge_request, :simple, source_project: project, position: 1) } + let(:merge_request) { create(:merge_request, source_project: project) } + let(:another_merge_request) { create(:merge_request, :simple, source_project: project) } before do milestone.merge_requests << merge_request @@ -318,6 +336,18 @@ describe API::Milestones do expect(json_response.first['milestone']['title']).to eq(milestone.title) end + it 'returns project merge_requests sorted by label priority' do + merge_request_1 = create(:labeled_merge_request, source_branch: 'branch_1', source_project: project, milestone: milestone, labels: [label_2]) + merge_request_2 = create(:labeled_merge_request, source_branch: 'branch_2', source_project: project, milestone: milestone, labels: [label_1]) + merge_request_3 = create(:labeled_merge_request, source_branch: 'branch_3', source_project: project, milestone: milestone, labels: [label_3]) + + get api("/projects/#{project.id}/milestones/#{milestone.id}/merge_requests", user) + + expect(json_response.first['id']).to eq(merge_request_2.id) + expect(json_response.second['id']).to eq(merge_request_1.id) + expect(json_response.third['id']).to eq(merge_request_3.id) + end + it 'returns a 404 error if milestone id not found' do get api("/projects/#{project.id}/milestones/1234/merge_requests", user) @@ -339,6 +369,8 @@ describe API::Milestones do it 'returns merge_requests ordered by position asc' do milestone.merge_requests << another_merge_request + another_merge_request.labels << label_1 + merge_request.labels << label_2 get api("/projects/#{project.id}/milestones/#{milestone.id}/merge_requests", user) |