-
Notifications
You must be signed in to change notification settings - Fork 56
/
pagination_spec.rb
118 lines (103 loc) · 3.21 KB
/
pagination_spec.rb
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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
# frozen_string_literal: true
require 'rails_helper'
describe Search::Pagination do
# raw_body instance data is determined by the VCR cassets in support/vcr_cassettes/search/*
context 'when page number is 1' do
let(:raw_body) do
{
'web' =>
{
'total' => 85,
'next_offset' => 10
}
}
end
subject { described_class.new(raw_body) }
it 'calculates the correct pagination object details', :aggregate_failures do
expect(subject.object).to include('current_page' => 1)
expect(subject.object).to include('per_page' => 10)
expect(subject.object).to include('total_pages' => 9)
expect(subject.object).to include('total_entries' => 85)
end
end
context 'when page number is 2' do
let(:raw_body) do
{
'web' =>
{
'total' => 85,
'next_offset' => 20
}
}
end
subject { described_class.new(raw_body) }
it 'calculates the correct pagination object details', :aggregate_failures do
expect(subject.object).to include('current_page' => 2)
expect(subject.object).to include('per_page' => 10)
expect(subject.object).to include('total_pages' => 9)
expect(subject.object).to include('total_entries' => 85)
end
end
context 'when page number is last page' do
let(:raw_body) do
{
'web' =>
{
'total' => 85,
'next_offset' => nil
}
}
end
subject { described_class.new(raw_body) }
it 'calculates the correct pagination object details', :aggregate_failures do
expect(subject.object).to include('current_page' => 9)
expect(subject.object).to include('per_page' => 10)
expect(subject.object).to include('total_pages' => 9)
expect(subject.object).to include('total_entries' => 85)
end
end
context 'when page number given is greater than total pages' do
let(:raw_body) do
{
'web' =>
{
'total' => 85,
'next_offset' => 1000
}
}
end
subject { described_class.new(raw_body) }
it 'returns the last page of results' do
expect(subject.object).to include('current_page' => 9)
end
end
context 'when Search.govs total entries exceed the OFFSET_LIMIT to view them' do
let(:raw_body) do
{
'web' =>
{
'total' => 35_123,
'next_offset' => 20
}
}
end
subject { described_class.new(raw_body) }
it 'sets total_pages to the maximum viewable number of pages' do
expect(subject.object['total_pages']).to eq 99
end
it 'sets total_entries to the maximum viewable number of entries' do
expect(subject.object['total_entries']).to eq 999
end
context 'when the ENTRIES_PER_PAGE is set to its max of 50' do
before do
stub_const('Search::Pagination::ENTRIES_PER_PAGE', 50)
end
it 'sets total_pages to the maximum viewable number of pages' do
expect(subject.object['total_pages']).to eq 19
end
it 'sets total_entries to the maximum viewable number of entries' do
expect(subject.object['total_entries']).to eq 999
end
end
end
end