diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-01-07 21:07:50 +0000 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-01-07 21:07:50 +0000 |
commit | d203316c80aa27cf747aa29df9f7c2d374965b5f (patch) | |
tree | aab5cde76fbf19a2639f6f9f3cb4f2acdc95f803 /spec/lib/gitlab/graphql | |
parent | 8dafc3b65aeb8f50fdfc38fb98d96c3db9e2f607 (diff) | |
download | gitlab-ce-d203316c80aa27cf747aa29df9f7c2d374965b5f.tar.gz |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/lib/gitlab/graphql')
3 files changed, 93 insertions, 2 deletions
diff --git a/spec/lib/gitlab/graphql/connections/externally_paginated_array_connection_spec.rb b/spec/lib/gitlab/graphql/connections/externally_paginated_array_connection_spec.rb new file mode 100644 index 00000000000..83c94ed6260 --- /dev/null +++ b/spec/lib/gitlab/graphql/connections/externally_paginated_array_connection_spec.rb @@ -0,0 +1,87 @@ +# frozen_string_literal: true + +require 'spec_helper' + +describe Gitlab::Graphql::Connections::ExternallyPaginatedArrayConnection do + 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 + described_class.new(all_nodes, arguments) + end + + describe '#sliced_nodes' do + let(:sliced_nodes) { connection.sliced_nodes } + + it 'returns all the nodes' do + expect(connection.sliced_nodes).to eq(values) + end + end + + describe '#paged_nodes' do + let(:paged_nodes) { connection.send(:paged_nodes) } + + it_behaves_like "connection with paged nodes" do + let(:paged_nodes_size) { values.size } + end + 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 diff --git a/spec/lib/gitlab/graphql/connections/filterable_array_connection_spec.rb b/spec/lib/gitlab/graphql/connections/filterable_array_connection_spec.rb index 20e87daa0d6..b2f0862be62 100644 --- a/spec/lib/gitlab/graphql/connections/filterable_array_connection_spec.rb +++ b/spec/lib/gitlab/graphql/connections/filterable_array_connection_spec.rb @@ -14,7 +14,9 @@ describe Gitlab::Graphql::Connections::FilterableArrayConnection do describe '#paged_nodes' do let(:paged_nodes) { subject.paged_nodes } - it_behaves_like "connection with paged nodes" + it_behaves_like "connection with paged nodes" do + let(:paged_nodes_size) { 3 } + end context 'when callback filters some nodes' do let(:callback) { proc { |nodes| nodes[1..-1] } } diff --git a/spec/lib/gitlab/graphql/connections/keyset/connection_spec.rb b/spec/lib/gitlab/graphql/connections/keyset/connection_spec.rb index bd0fcbbdeb2..f617e8b3ce7 100644 --- a/spec/lib/gitlab/graphql/connections/keyset/connection_spec.rb +++ b/spec/lib/gitlab/graphql/connections/keyset/connection_spec.rb @@ -232,7 +232,9 @@ describe Gitlab::Graphql::Connections::Keyset::Connection do let_it_be(:all_nodes) { create_list(:project, 5) } let(:paged_nodes) { subject.paged_nodes } - it_behaves_like "connection with paged nodes" + it_behaves_like "connection with paged nodes" do + let(:paged_nodes_size) { 3 } + end context 'when both are passed' do let(:arguments) { { first: 2, last: 2 } } |