2020-03-13 15:44:24 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
require 'spec_helper'
|
|
|
|
|
2020-07-28 23:09:34 +05:30
|
|
|
RSpec.describe Gitlab::Graphql::Pagination::ExternallyPaginatedArrayConnection do
|
2020-03-13 15:44:24 +05:30
|
|
|
let(:prev_cursor) { 1 }
|
|
|
|
let(:next_cursor) { 6 }
|
|
|
|
let(:values) { [2, 3, 4, 5] }
|
|
|
|
let(:all_nodes) { Gitlab::Graphql::ExternallyPaginatedArray.new(prev_cursor, next_cursor, *values) }
|
|
|
|
let(:arguments) { {} }
|
|
|
|
|
|
|
|
subject(:connection) do
|
2021-02-22 17:27:13 +05:30
|
|
|
described_class.new(all_nodes, **{ max_page_size: values.size }.merge(arguments))
|
|
|
|
end
|
|
|
|
|
|
|
|
it_behaves_like 'a connection with collection methods'
|
|
|
|
|
|
|
|
it_behaves_like 'a redactable connection' do
|
|
|
|
let(:unwanted) { 3 }
|
2020-03-13 15:44:24 +05:30
|
|
|
end
|
|
|
|
|
2020-04-22 19:07:51 +05:30
|
|
|
describe '#nodes' do
|
|
|
|
let(:paged_nodes) { connection.nodes }
|
2020-03-13 15:44:24 +05:30
|
|
|
|
2020-04-22 19:07:51 +05:30
|
|
|
it_behaves_like 'connection with paged nodes' do
|
2020-03-13 15:44:24 +05:30
|
|
|
let(:paged_nodes_size) { values.size }
|
|
|
|
end
|
2020-05-24 23:13:21 +05:30
|
|
|
|
|
|
|
context 'when after or before is specified, they are ignored' do
|
|
|
|
# after and before are not used to filter the array, as they
|
|
|
|
# were already used to directly fetch the external array
|
|
|
|
it_behaves_like 'connection with paged nodes' do
|
|
|
|
let(:arguments) { { after: next_cursor } }
|
|
|
|
let(:paged_nodes_size) { values.size }
|
|
|
|
end
|
|
|
|
|
|
|
|
it_behaves_like 'connection with paged nodes' do
|
|
|
|
let(:arguments) { { before: prev_cursor } }
|
|
|
|
let(:paged_nodes_size) { values.size }
|
|
|
|
end
|
|
|
|
end
|
2020-03-13 15:44:24 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
describe '#start_cursor' do
|
|
|
|
it 'returns the prev cursor' do
|
|
|
|
expect(connection.start_cursor).to eq(prev_cursor)
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when there is none' do
|
|
|
|
let(:prev_cursor) { nil }
|
|
|
|
|
|
|
|
it 'returns nil' do
|
|
|
|
expect(connection.start_cursor).to eq(nil)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe '#end_cursor' do
|
|
|
|
it 'returns the next cursor' do
|
|
|
|
expect(connection.end_cursor).to eq(next_cursor)
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when there is none' do
|
|
|
|
let(:next_cursor) { nil }
|
|
|
|
|
|
|
|
it 'returns nil' do
|
|
|
|
expect(connection.end_cursor).to eq(nil)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe '#has_next_page' do
|
|
|
|
it 'returns true when there is a end cursor' do
|
|
|
|
expect(connection.has_next_page).to eq(true)
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'there is no end cursor' do
|
|
|
|
let(:next_cursor) { nil }
|
|
|
|
|
|
|
|
it 'returns false' do
|
|
|
|
expect(connection.has_next_page).to eq(false)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe '#has_previous_page' do
|
|
|
|
it 'returns true when there is a start cursor' do
|
|
|
|
expect(connection.has_previous_page).to eq(true)
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'there is no start cursor' do
|
|
|
|
let(:prev_cursor) { nil }
|
|
|
|
|
|
|
|
it 'returns false' do
|
|
|
|
expect(connection.has_previous_page).to eq(false)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|