|
| 1 | +# coding: utf-8 |
| 2 | +require 'spec_helper' |
| 3 | +require 'activeadmin' |
| 4 | + |
| 5 | +describe 'browse the test app' do |
| 6 | + let(:password) { 'foobar•secret' } |
| 7 | + let(:email) { '[email protected]' } |
| 8 | + let(:admin_user) do |
| 9 | + AdminUser.where(email: email).first || AdminUser.create!(email: email, password: password) |
| 10 | + end |
| 11 | + let(:other_email) { '[email protected]' } |
| 12 | + let(:other_user) do |
| 13 | + AdminUser.where(email: other_email).first || AdminUser.create!(email: other_email, password: password) |
| 14 | + end |
| 15 | + |
| 16 | + before do |
| 17 | + Mongoid.purge! |
| 18 | + expect(admin_user).to be_persisted |
| 19 | + expect(other_user).to be_persisted |
| 20 | + end |
| 21 | + |
| 22 | + context 'when authorized' do |
| 23 | + before do |
| 24 | + visit '/admin' |
| 25 | + |
| 26 | + I18n.t('active_admin.devise.login.submit').should eq('Login') |
| 27 | + |
| 28 | + # Auth |
| 29 | + fill_in 'Email', with: email |
| 30 | + fill_in 'Password', with: password |
| 31 | + click_on 'Login' |
| 32 | + end |
| 33 | + |
| 34 | + context 'with 100 posts' do |
| 35 | + let(:per_page) { 30 } |
| 36 | + let(:posts_size) { 100 } |
| 37 | + |
| 38 | + before do |
| 39 | + posts_size.times { |n| |
| 40 | + Post.create!(title: "Quick Brown Fox #{n}", body: 'The quick brown fox jumps over the lazy dog.', view_count: 5, admin_user: admin_user, other_user: other_user) |
| 41 | + } |
| 42 | + |
| 43 | + click_on 'Posts' |
| 44 | + end |
| 45 | + |
| 46 | + describe "paginator" do |
| 47 | + it "must have paginator with 4 pages" do |
| 48 | + page.should have_css('.pagination > .page.current') |
| 49 | + page.all(:css, '.pagination > .page').size.should == 4 |
| 50 | + end |
| 51 | + |
| 52 | + it "must show each page correctly" do |
| 53 | + # temprorary go to page 2 |
| 54 | + page.find('.pagination > .page > a', text: '2').click |
| 55 | + |
| 56 | + nbsp = Nokogiri::HTML(" ").text |
| 57 | + |
| 58 | + (1..4).each do |page_number| |
| 59 | + page.find('.pagination > .page > a', text: page_number).click |
| 60 | + page.find('.pagination_information').should have_content('Displaying Posts') |
| 61 | + |
| 62 | + offset = (page_number - 1) * per_page |
| 63 | + collection_size = [per_page, posts_size - (page_number - 1) * per_page].min |
| 64 | + |
| 65 | + display_total_text = I18n.t 'active_admin.pagination.multiple', :model => 'Posts', :total => posts_size, |
| 66 | + :from => offset + 1, :to => offset + collection_size |
| 67 | + |
| 68 | + pagination_information = page.find('.pagination_information').native.to_s.gsub(nbsp,' ') |
| 69 | + pagination_information.should include(display_total_text.gsub(' ', ' ')) |
| 70 | + end |
| 71 | + end |
| 72 | + end |
| 73 | + |
| 74 | + end |
| 75 | + end |
| 76 | + |
| 77 | +end |
0 commit comments