2021-06-01 12:20:20 +00:00
|
|
|
# Copyright (C) 2012-2021 Zammad Foundation, http://zammad-foundation.org/
|
|
|
|
|
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
|
|
|
|
expect(page).to have_css('.js-pager', wait: 10)
|
|
|
|
|
|
|
|
class_page1 = klass.order(sort_by => :asc, id: :asc).offset(50).first
|
|
|
|
expect(page).to have_text(class_page1.name, wait: 10)
|
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
|
|
|
|
2021-06-15 06:26:52 +00:00
|
|
|
page.first('.js-page', text: '2', wait: 10).click
|
2020-10-30 07:59:32 +00:00
|
|
|
|
|
|
|
class_page2 = klass.order(sort_by => :asc, id: :asc).offset(175).first
|
|
|
|
expect(page).to have_text(class_page2.name, wait: 10)
|
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
|
|
|
|
2021-06-15 06:26:52 +00:00
|
|
|
page.first('.js-page', text: '3', wait: 10).click
|
2020-10-30 07:59:32 +00:00
|
|
|
|
|
|
|
class_page3 = klass.order(sort_by => :asc, id: :asc).offset(325).first
|
|
|
|
expect(page).to have_text(class_page3.name, wait: 10)
|
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
|
|
|
|
2021-06-15 06:26:52 +00:00
|
|
|
page.first('.js-page', text: '4', wait: 10).click
|
2020-10-30 07:59:32 +00:00
|
|
|
|
|
|
|
class_page4 = klass.order(sort_by => :asc, id: :asc).offset(475).first
|
|
|
|
expect(page).to have_text(class_page4.name, wait: 10)
|
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
|
|
|
|
2021-06-15 06:26:52 +00:00
|
|
|
page.first('.js-page', text: '1', wait: 10).click
|
2020-10-30 07:59:32 +00:00
|
|
|
|
|
|
|
page.first('.js-tableHead[data-column-key=name]').click
|
|
|
|
expect(page).to have_text(class_page1.name, wait: 10)
|
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
|
|
|
|
expect(page).to have_text(class_last.name, wait: 10)
|
|
|
|
end
|
|
|
|
end
|