summaryrefslogtreecommitdiff
path: root/spec/helpers/keyset_helper_spec.rb
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2021-06-16 18:25:58 +0000
committerGitLab Bot <gitlab-bot@gitlab.com>2021-06-16 18:25:58 +0000
commita5f4bba440d7f9ea47046a0a561d49adf0a1e6d4 (patch)
treefb69158581673816a8cd895f9d352dcb3c678b1e /spec/helpers/keyset_helper_spec.rb
parentd16b2e8639e99961de6ddc93909f3bb5c1445ba1 (diff)
downloadgitlab-ce-a5f4bba440d7f9ea47046a0a561d49adf0a1e6d4.tar.gz
Add latest changes from gitlab-org/gitlab@14-0-stable-eev14.0.0-rc42
Diffstat (limited to 'spec/helpers/keyset_helper_spec.rb')
-rw-r--r--spec/helpers/keyset_helper_spec.rb94
1 files changed, 94 insertions, 0 deletions
diff --git a/spec/helpers/keyset_helper_spec.rb b/spec/helpers/keyset_helper_spec.rb
new file mode 100644
index 00000000000..2e4bf537e2f
--- /dev/null
+++ b/spec/helpers/keyset_helper_spec.rb
@@ -0,0 +1,94 @@
+# frozen_string_literal: true
+require 'spec_helper'
+
+RSpec.describe KeysetHelper, type: :controller do
+ controller(Admin::UsersController) do
+ def index
+ @users = User
+ .where(admin: false)
+ .order(id: :desc)
+ .keyset_paginate(cursor: params[:cursor], per_page: 2)
+
+ render inline: "<%= keyset_paginate @users %>", layout: false # rubocop: disable Rails/RenderInline
+ end
+ end
+
+ render_views
+
+ let(:admin) { create(:admin) }
+
+ before do
+ sign_in(admin)
+ end
+
+ context 'with admin mode', :enable_admin_mode do
+ context 'when no users are present' do
+ it 'does not render pagination links' do
+ get :index
+
+ expect(response.body).not_to include(s_('Pagination|First'))
+ expect(response.body).not_to include(s_('Pagination|Prev'))
+ expect(response.body).not_to include(s_('Pagination|Next'))
+ expect(response.body).not_to include(s_('Pagination|Last'))
+ end
+ end
+
+ context 'when one user is present' do
+ before do
+ create(:user)
+ end
+
+ it 'does not render pagination links' do
+ get :index
+
+ expect(response.body).not_to include(s_('Pagination|First'))
+ expect(response.body).not_to include(s_('Pagination|Prev'))
+ expect(response.body).not_to include(s_('Pagination|Next'))
+ expect(response.body).not_to include(s_('Pagination|Last'))
+ end
+ end
+
+ context 'when more users are present' do
+ let_it_be(:users) { create_list(:user, 5) }
+
+ let(:paginator) { User.where(admin: false).order(id: :desc).keyset_paginate(per_page: 2) }
+
+ context 'when on the first page' do
+ it 'renders the next and last links' do
+ get :index
+
+ expect(response.body).not_to include(s_('Pagination|First'))
+ expect(response.body).not_to include(s_('Pagination|Prev'))
+ expect(response.body).to include(s_('Pagination|Next'))
+ expect(response.body).to include(s_('Pagination|Last'))
+ end
+ end
+
+ context 'when at the last page' do
+ it 'renders the prev and first links' do
+ cursor = paginator.cursor_for_last_page
+
+ get :index, params: { cursor: cursor }
+
+ expect(response.body).to include(s_('Pagination|First'))
+ expect(response.body).to include(s_('Pagination|Prev'))
+ expect(response.body).not_to include(s_('Pagination|Next'))
+ expect(response.body).not_to include(s_('Pagination|Last'))
+ end
+ end
+
+ context 'when at the second page' do
+ it 'renders all links' do
+ cursor = paginator.cursor_for_next_page
+
+ get :index, params: { cursor: cursor }
+
+ expect(response.body).to include(s_('Pagination|First'))
+ expect(response.body).to include(s_('Pagination|Prev'))
+ expect(response.body).to include(s_('Pagination|Next'))
+ expect(response.body).to include(s_('Pagination|Last'))
+ end
+ end
+ end
+ end
+end