Commit 7c981da1 authored by Nick Thomas's avatar Nick Thomas

Merge branch '29713-graphql-add-issue-relative-position-sort-2' into 'master'

Graphql: Sort issues by relative_position

See merge request gitlab-org/gitlab!19713
parents c0df79c1 3e94a58d
......@@ -8,6 +8,7 @@ module Types
value 'DUE_DATE_ASC', 'Due date by ascending order', value: 'due_date_asc'
value 'DUE_DATE_DESC', 'Due date by descending order', value: 'due_date_desc'
value 'RELATIVE_POSITION_ASC', 'Relative position by ascending order', value: 'relative_position_asc'
end
# rubocop: enable Graphql/AuthorizeTypes
end
---
title: 'Graphql query for issues can now be sorted by relative_position'
merge_request: 19713
author:
type: added
......@@ -2517,6 +2517,11 @@ enum IssueSort {
"""
DUE_DATE_DESC
"""
Relative position by ascending order
"""
RELATIVE_POSITION_ASC
"""
Created at ascending order
"""
......
......@@ -13680,6 +13680,12 @@
"description": "Due date by descending order",
"isDeprecated": false,
"deprecationReason": null
},
{
"name": "RELATIVE_POSITION_ASC",
"description": "Relative position by ascending order",
"isDeprecated": false,
"deprecationReason": null
}
],
"possibleTypes": null
......
......@@ -99,6 +99,19 @@ describe Resolvers::IssuesResolver do
expect(resolve_issues(sort: :due_date_desc)).to eq [due_issue1, due_issue3, due_issue4, due_issue2]
end
end
context 'when sorting by relative position' do
let(:project) { create(:project) }
let!(:relative_issue1) { create(:issue, project: project, relative_position: 2000) }
let!(:relative_issue2) { create(:issue, project: project, relative_position: nil) }
let!(:relative_issue3) { create(:issue, project: project, relative_position: 1000) }
let!(:relative_issue4) { create(:issue, project: project, relative_position: nil) }
it 'sorts issues ascending' do
expect(resolve_issues(sort: :relative_position_asc)).to eq [relative_issue3, relative_issue1, relative_issue4, relative_issue2]
end
end
end
it 'returns issues user can see' do
......
......@@ -8,6 +8,6 @@ describe GitlabSchema.types['IssueSort'] do
it_behaves_like 'common sort values'
it 'exposes all the existing issue sort values' do
expect(described_class.values.keys).to include(*%w[DUE_DATE_ASC DUE_DATE_DESC])
expect(described_class.values.keys).to include(*%w[DUE_DATE_ASC DUE_DATE_DESC RELATIVE_POSITION_ASC])
end
end
......@@ -200,6 +200,52 @@ describe 'getting an issue list for a project' do
end
end
end
context 'when sorting by relative position' do
let(:sort_project) { create(:project, :public) }
let!(:relative_issue1) { create(:issue, project: sort_project, relative_position: 2000) }
let!(:relative_issue2) { create(:issue, project: sort_project, relative_position: nil) }
let!(:relative_issue3) { create(:issue, project: sort_project, relative_position: 1000) }
let!(:relative_issue4) { create(:issue, project: sort_project, relative_position: nil) }
let!(:relative_issue5) { create(:issue, project: sort_project, relative_position: 500) }
let(:params) { 'sort: RELATIVE_POSITION_ASC' }
def query(issue_params = params)
graphql_query_for(
'project',
{ 'fullPath' => sort_project.full_path },
"issues(#{issue_params}) { pageInfo { endCursor} edges { node { iid dueDate } } }"
)
end
before do
post_graphql(query, current_user: current_user)
end
it_behaves_like 'a working graphql query'
context 'when ascending' do
it 'sorts issues' do
expect(grab_iids).to eq [relative_issue5.iid, relative_issue3.iid, relative_issue1.iid, relative_issue4.iid, relative_issue2.iid]
end
context 'when paginating' do
let(:params) { 'sort: RELATIVE_POSITION_ASC, first: 2' }
it 'sorts issues' do
expect(grab_iids).to eq [relative_issue5.iid, relative_issue3.iid]
cursored_query = query("sort: RELATIVE_POSITION_ASC, after: \"#{end_cursor}\"")
post_graphql(cursored_query, current_user: current_user)
response_data = JSON.parse(response.body)['data']['project']['issues']['edges']
expect(grab_iids(response_data)).to eq [relative_issue1.iid, relative_issue4.iid, relative_issue2.iid]
end
end
end
end
end
def grab_iids(data = issues_data)
......
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