2022-01-01 13:38:12 +00:00
|
|
|
# Copyright (C) 2012-2022 Zammad Foundation, https://zammad-foundation.org/
|
2021-06-01 12:20:20 +00:00
|
|
|
|
2020-10-30 07:59:32 +00:00
|
|
|
RSpec.shared_examples 'pagination' do |model:, klass:, path:, sort_by: :name|
|
2021-06-15 06:26:52 +00:00
|
|
|
let(:model) { model }
|
|
|
|
|
|
|
|
def authenticate
|
2020-10-30 07:59:32 +00:00
|
|
|
create_list(model, 500)
|
2021-06-15 06:26:52 +00:00
|
|
|
true
|
2020-10-30 07:59:32 +00:00
|
|
|
end
|
|
|
|
|
2021-06-15 06:26:52 +00:00
|
|
|
it 'does paginate', authenticated_as: :authenticate do
|
2020-10-30 07:59:32 +00:00
|
|
|
visit path
|
2022-01-25 09:36:20 +00:00
|
|
|
expect(page).to have_css('.js-pager')
|
2020-10-30 07:59:32 +00:00
|
|
|
|
|
|
|
class_page1 = klass.order(sort_by => :asc, id: :asc).offset(50).first
|
2022-01-25 09:36:20 +00:00
|
|
|
expect(page).to have_text(class_page1.name)
|
2021-06-15 06:26:52 +00:00
|
|
|
expect(page).to have_css('.js-page.is-selected', text: '1')
|
2020-10-30 07:59:32 +00:00
|
|
|
|
2022-01-25 09:36:20 +00:00
|
|
|
page.first('.js-page', text: '2').click
|
2020-10-30 07:59:32 +00:00
|
|
|
|
|
|
|
class_page2 = klass.order(sort_by => :asc, id: :asc).offset(175).first
|
2022-01-25 09:36:20 +00:00
|
|
|
expect(page).to have_text(class_page2.name)
|
2021-06-15 06:26:52 +00:00
|
|
|
expect(page).to have_css('.js-page.is-selected', text: '2')
|
2020-10-30 07:59:32 +00:00
|
|
|
|
2022-01-25 09:36:20 +00:00
|
|
|
page.first('.js-page', text: '3').click
|
2020-10-30 07:59:32 +00:00
|
|
|
|
|
|
|
class_page3 = klass.order(sort_by => :asc, id: :asc).offset(325).first
|
2022-01-25 09:36:20 +00:00
|
|
|
expect(page).to have_text(class_page3.name)
|
2021-06-15 06:26:52 +00:00
|
|
|
expect(page).to have_css('.js-page.is-selected', text: '3')
|
2020-10-30 07:59:32 +00:00
|
|
|
|
2022-01-25 09:36:20 +00:00
|
|
|
page.first('.js-page', text: '4').click
|
2020-10-30 07:59:32 +00:00
|
|
|
|
|
|
|
class_page4 = klass.order(sort_by => :asc, id: :asc).offset(475).first
|
2022-01-25 09:36:20 +00:00
|
|
|
expect(page).to have_text(class_page4.name)
|
2021-06-15 06:26:52 +00:00
|
|
|
expect(page).to have_css('.js-page.is-selected', text: '4')
|
2020-10-30 07:59:32 +00:00
|
|
|
|
2022-01-25 09:36:20 +00:00
|
|
|
page.first('.js-page', text: '1').click
|
2020-10-30 07:59:32 +00:00
|
|
|
|
|
|
|
page.first('.js-tableHead[data-column-key=name]').click
|
2022-01-25 09:36:20 +00:00
|
|
|
expect(page).to have_text(class_page1.name)
|
2021-06-15 06:26:52 +00:00
|
|
|
expect(page).to have_css('.js-page.is-selected', text: '1')
|
2020-10-30 07:59:32 +00:00
|
|
|
|
|
|
|
page.first('.js-tableHead[data-column-key=name]').click
|
|
|
|
class_last = klass.order(sort_by => :desc).first
|
2022-01-25 09:36:20 +00:00
|
|
|
expect(page).to have_text(class_last.name)
|
2020-10-30 07:59:32 +00:00
|
|
|
end
|
|
|
|
end
|