pagination_examples.rb 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. # Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. RSpec.shared_examples 'pagination' do |model:, klass:, path:, sort_by: :name|
  3. let(:model) { model }
  4. def authenticate
  5. create_list(model, 500)
  6. true
  7. end
  8. it 'does paginate', authenticated_as: :authenticate do
  9. visit path
  10. expect(page).to have_css('.js-pager')
  11. class_page1 = klass.reorder(sort_by => :asc, id: :asc).offset(50).first
  12. expect(page).to have_text(class_page1.name)
  13. expect(page).to have_css('.js-page.is-selected', text: '1')
  14. page.first('.js-page', text: '2').click
  15. class_page2 = klass.reorder(sort_by => :asc, id: :asc).offset(175).first
  16. expect(page).to have_text(class_page2.name)
  17. expect(page).to have_css('.js-page.is-selected', text: '2')
  18. page.first('.js-page', text: '3').click
  19. class_page3 = klass.reorder(sort_by => :asc, id: :asc).offset(325).first
  20. expect(page).to have_text(class_page3.name)
  21. expect(page).to have_css('.js-page.is-selected', text: '3')
  22. page.first('.js-page', text: '4').click
  23. class_page4 = klass.reorder(sort_by => :asc, id: :asc).offset(475).first
  24. expect(page).to have_text(class_page4.name)
  25. expect(page).to have_css('.js-page.is-selected', text: '4')
  26. page.first('.js-page', text: '1').click
  27. page.first('.js-tableHead[data-column-key=name]').click
  28. expect(page).to have_text(class_page1.name)
  29. expect(page).to have_css('.js-page.is-selected', text: '1')
  30. page.first('.js-tableHead[data-column-key=name]').click
  31. class_last = klass.reorder(sort_by => :desc).first
  32. expect(page).to have_text(class_last.name)
  33. end
  34. end