Welcome to mirror list, hosted at ThFree Co, Russian Federation.

externally_paginated_array_connection_spec.rb « pagination « graphql « gitlab « lib « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 932bcd8cd92a6b9eaf1d143588077f1bdae2afa2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
# frozen_string_literal: true

require 'spec_helper'

RSpec.describe Gitlab::Graphql::Pagination::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, { max_page_size: values.size }.merge(arguments))
  end

  describe '#nodes' do
    let(:paged_nodes) { connection.nodes }

    it_behaves_like 'connection with paged nodes' do
      let(:paged_nodes_size) { values.size }
    end

    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
  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