Commit d504b0c9 authored by Brett Walker's avatar Brett Walker

Convert sort specs to use shared pagination

examples
parent 0eedf4a3
......@@ -9,7 +9,7 @@ describe Types::IssuableSortEnum do
expect(described_class.values.keys).to include(
*%w[PRIORITY_ASC PRIORITY_DESC
LABEL_PRIORITY_ASC LABEL_PRIORITY_DESC
MILESTONE_DUE_ASC MILESTONE_DUE_DESC
])
MILESTONE_DUE_ASC MILESTONE_DUE_DESC]
)
end
end
......@@ -118,9 +118,7 @@ describe 'getting an issue list for a project' do
end
describe 'sorting and pagination' do
let(:start_cursor) { graphql_data['project']['issues']['pageInfo']['startCursor'] }
let(:end_cursor) { graphql_data['project']['issues']['pageInfo']['endCursor'] }
let(:data_path) { [:project, :issues] }
let_it_be(:data_path) { [:project, :issues] }
def pagination_query(params, page_info)
graphql_query_for(
......@@ -134,136 +132,50 @@ describe 'getting an issue list for a project' do
data.map { |issue| issue.dig('node', 'iid').to_i }
end
context 'when sorting by due date' do
let_it_be(:sort_project) { create(:project, :public) }
let_it_be(:due_issue1) { create(:issue, project: sort_project, due_date: 3.days.from_now) }
let_it_be(:due_issue2) { create(:issue, project: sort_project, due_date: nil) }
let_it_be(:due_issue3) { create(:issue, project: sort_project, due_date: 2.days.ago) }
let_it_be(:due_issue4) { create(:issue, project: sort_project, due_date: nil) }
let_it_be(:due_issue5) { create(:issue, project: sort_project, due_date: 1.day.ago) }
let_it_be(:params) { 'sort: DUE_DATE_ASC' }
def query(issue_params = params)
graphql_query_for(
'project',
{ 'fullPath' => sort_project.full_path },
<<~ISSUES
issues(#{issue_params}) {
pageInfo {
endCursor
}
edges {
node {
iid
dueDate
}
}
}
ISSUES
)
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([due_issue3.iid, due_issue5.iid, due_issue1.iid, due_issue4.iid, due_issue2.iid])
end
context 'when paginating' do
let(:params) { 'sort: DUE_DATE_ASC, first: 2' }
it 'sorts issues' do
expect(grab_iids).to eq([due_issue3.iid, due_issue5.iid])
cursored_query = query("sort: DUE_DATE_ASC, after: \"#{end_cursor}\"")
post_graphql(cursored_query, current_user: current_user)
response_data = Gitlab::Json.parse(response.body)['data']['project']['issues']['edges']
expect(grab_iids(response_data)).to eq([due_issue1.iid, due_issue4.iid, due_issue2.iid])
end
it_behaves_like 'sorted paginated query' do
let(:sort_param) { 'DUE_DATE_ASC' }
let(:first_param) { 2 }
let(:expected_results) { [due_issue3.iid, due_issue5.iid, due_issue1.iid, due_issue4.iid, due_issue2.iid] }
end
end
context 'when descending' do
let(:params) { 'sort: DUE_DATE_DESC' }
it 'sorts issues' do
expect(grab_iids).to eq([due_issue1.iid, due_issue5.iid, due_issue3.iid, due_issue4.iid, due_issue2.iid])
end
context 'when paginating' do
let(:params) { 'sort: DUE_DATE_DESC, first: 2' }
it 'sorts issues' do
expect(grab_iids).to eq([due_issue1.iid, due_issue5.iid])
cursored_query = query("sort: DUE_DATE_DESC, after: \"#{end_cursor}\"")
post_graphql(cursored_query, current_user: current_user)
response_data = Gitlab::Json.parse(response.body)['data']['project']['issues']['edges']
expect(grab_iids(response_data)).to eq([due_issue3.iid, due_issue4.iid, due_issue2.iid])
end
it_behaves_like 'sorted paginated query' do
let(:sort_param) { 'DUE_DATE_DESC' }
let(:first_param) { 2 }
let(:expected_results) { [due_issue1.iid, due_issue5.iid, due_issue3.iid, due_issue4.iid, due_issue2.iid] }
end
end
end
context 'when sorting by relative position' do
let_it_be(:sort_project) { create(:project, :public) }
let_it_be(:relative_issue1) { create(:issue, project: sort_project, relative_position: 2000) }
let_it_be(:relative_issue2) { create(:issue, project: sort_project, relative_position: nil) }
let_it_be(:relative_issue3) { create(:issue, project: sort_project, relative_position: 1000) }
let_it_be(:relative_issue4) { create(:issue, project: sort_project, relative_position: nil) }
let_it_be(:relative_issue5) { create(:issue, project: sort_project, relative_position: 500) }
let_it_be(: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 = Gitlab::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
it_behaves_like 'sorted paginated query' do
let(:sort_param) { 'RELATIVE_POSITION_ASC' }
let(:first_param) { 2 }
let(:expected_results) { [relative_issue5.iid, relative_issue3.iid, relative_issue1.iid, relative_issue4.iid, relative_issue2.iid] }
end
end
end
context 'when sorting by priority' do
let_it_be(:sort_project) { create(:project, :public) }
let_it_be(:early_milestone) { create(:milestone, project: sort_project, due_date: 10.days.from_now) }
let_it_be(:late_milestone) { create(:milestone, project: sort_project, due_date: 30.days.from_now) }
let_it_be(:priority_label1) { create(:label, project: sort_project, priority: 1) }
......@@ -273,68 +185,25 @@ describe 'getting an issue list for a project' do
let_it_be(:priority_issue3) { create(:issue, project: sort_project, milestone: early_milestone) }
let_it_be(:priority_issue4) { create(:issue, project: sort_project) }
let_it_be(:params) { 'sort: PRIORITY_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([priority_issue3.iid, priority_issue1.iid, priority_issue2.iid, priority_issue4.iid])
end
context 'when paginating' do
let(:params) { 'sort: PRIORITY_ASC, first: 2' }
it 'sorts issues' do
expect(grab_iids).to eq([priority_issue3.iid, priority_issue1.iid])
cursored_query = query("sort: PRIORITY_ASC, after: \"#{end_cursor}\"")
post_graphql(cursored_query, current_user: current_user)
response_data = Gitlab::Json.parse(response.body)['data']['project']['issues']['edges']
expect(grab_iids(response_data)).to eq([priority_issue2.iid, priority_issue4.iid])
end
it_behaves_like 'sorted paginated query' do
let(:sort_param) { 'PRIORITY_ASC' }
let(:first_param) { 2 }
let(:expected_results) { [priority_issue3.iid, priority_issue1.iid, priority_issue2.iid, priority_issue4.iid] }
end
end
context 'when descending' do
let(:params) { 'sort: PRIORITY_DESC' }
it 'sorts issues' do
expect(grab_iids).to eq([priority_issue1.iid, priority_issue3.iid, priority_issue2.iid, priority_issue4.iid])
end
context 'when paginating' do
let(:params) { 'sort: PRIORITY_DESC, first: 2' }
it 'sorts issues' do
expect(grab_iids).to eq([priority_issue1.iid, priority_issue3.iid])
cursored_query = query("sort: PRIORITY_DESC, after: \"#{end_cursor}\"")
post_graphql(cursored_query, current_user: current_user)
response_data = Gitlab::Json.parse(response.body)['data']['project']['issues']['edges']
expect(grab_iids(response_data)).to eq([priority_issue2.iid, priority_issue4.iid])
end
it_behaves_like 'sorted paginated query' do
let(:sort_param) { 'PRIORITY_DESC' }
let(:first_param) { 2 }
let(:expected_results) { [priority_issue1.iid, priority_issue3.iid, priority_issue2.iid, priority_issue4.iid] }
end
end
end
context 'when sorting by label priority' do
let_it_be(:sort_project) { create(:project, :public) }
let_it_be(:label1) { create(:label, project: sort_project, priority: 1) }
let_it_be(:label2) { create(:label, project: sort_project, priority: 5) }
let_it_be(:label3) { create(:label, project: sort_project, priority: 10) }
......@@ -343,61 +212,19 @@ describe 'getting an issue list for a project' do
let_it_be(:label_issue3) { create(:issue, project: sort_project, labels: [label1, label3]) }
let_it_be(:label_issue4) { create(:issue, project: sort_project) }
let_it_be(:params) { 'sort: LABEL_PRIORITY_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 [label_issue3.iid, label_issue1.iid, label_issue2.iid, label_issue4.iid]
end
context 'when paginating' do
let(:params) { 'sort: LABEL_PRIORITY_ASC, first: 2' }
it 'sorts issues' do
expect(grab_iids).to eq [label_issue3.iid, label_issue1.iid]
cursored_query = query("sort: LABEL_PRIORITY_ASC, after: \"#{end_cursor}\"")
post_graphql(cursored_query, current_user: current_user)
response_data = Gitlab::Json.parse(response.body)['data']['project']['issues']['edges']
expect(grab_iids(response_data)).to eq [label_issue2.iid, label_issue4.iid]
end
it_behaves_like 'sorted paginated query' do
let(:sort_param) { 'LABEL_PRIORITY_ASC' }
let(:first_param) { 2 }
let(:expected_results) { [label_issue3.iid, label_issue1.iid, label_issue2.iid, label_issue4.iid] }
end
end
context 'when descending' do
let(:params) { 'sort: LABEL_PRIORITY_DESC' }
it 'sorts issues' do
expect(grab_iids).to eq [label_issue2.iid, label_issue3.iid, label_issue1.iid, label_issue4.iid]
end
context 'when paginating' do
let(:params) { 'sort: LABEL_PRIORITY_DESC, first: 2' }
it 'sorts issues' do
expect(grab_iids).to eq [label_issue2.iid, label_issue3.iid]
cursored_query = query("sort: LABEL_PRIORITY_DESC, after: \"#{end_cursor}\"")
post_graphql(cursored_query, current_user: current_user)
response_data = Gitlab::Json.parse(response.body)['data']['project']['issues']['edges']
expect(grab_iids(response_data)).to eq [label_issue1.iid, label_issue4.iid]
end
it_behaves_like 'sorted paginated query' do
let(:sort_param) { 'LABEL_PRIORITY_DESC' }
let(:first_param) { 2 }
let(:expected_results) { [label_issue2.iid, label_issue3.iid, label_issue1.iid, label_issue4.iid] }
end
end
end
......
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