|
2 | 2 |
|
3 | 3 | RSpec.describe "Pagination", type: :system do |
4 | 4 | let!(:theme) { upload_theme_component } |
| 5 | + fab!(:tag) { Fabricate(:tag, name: "featured") } |
| 6 | + fab!(:upload) { Fabricate(:image_upload) } |
5 | 7 |
|
6 | | - fab!(:admin) |
7 | | - fab!(:user) |
| 8 | + describe "without enough topics to page" do |
| 9 | + fab!(:topics) { Fabricate.times(3, :topic_with_op, image_upload: upload, tags: [tag]) } |
| 10 | + it "should not allow pagination even if max_number_of_topics > number_of_topics" do |
| 11 | + theme.update_setting(:number_of_topics, 3) |
| 12 | + theme.update_setting(:max_number_of_topics, 6) |
| 13 | + theme.save! |
| 14 | + |
| 15 | + visit("/") |
| 16 | + expect(page).to have_css(".featured-topics .featured-topic", count: 3) |
| 17 | + expect(page).not_to have_css(".featured-topics-controls .page-button-container") |
| 18 | + expect(page).not_to have_css(".featured-topics-controls .left-page-button") |
| 19 | + expect(page).not_to have_css(".featured-topics-controls .right-page-button") |
| 20 | + end |
| 21 | + end |
8 | 22 |
|
9 | | - fab!(:tag) { Fabricate(:tag, name: "featured") } |
| 23 | + describe "with plenty of topics to page" do |
| 24 | + fab!(:topics) { Fabricate.times(8, :topic_with_op, image_upload: upload, tags: [tag]) } |
10 | 25 |
|
11 | | - fab!(:upload) { Fabricate(:image_upload) } |
12 | | - fab!(:topics) { Fabricate.times(8, :topic_with_op, image_upload: upload, tags: [tag]) } |
| 26 | + it "should not allow pagination if max_number_of_topics <= number_of_topics" do |
| 27 | + theme.update_setting(:number_of_topics, 3) |
| 28 | + theme.update_setting(:max_number_of_topics, 3) |
| 29 | + theme.save! |
13 | 30 |
|
14 | | - it "should not allow pagination if max_number_of_topics <= number_of_topics" do |
15 | | - theme.update_setting(:number_of_topics, 3) |
16 | | - theme.update_setting(:max_number_of_topics, 3) |
17 | | - theme.save! |
| 31 | + visit("/") |
| 32 | + expect(page).to have_css(".featured-topics .featured-topic", count: 3) |
| 33 | + expect(page).not_to have_css(".featured-topics-controls .page-button-container") |
| 34 | + expect(page).not_to have_css(".featured-topics-controls .left-page-button") |
| 35 | + expect(page).not_to have_css(".featured-topics-controls .right-page-button") |
18 | 36 |
|
19 | | - visit("/") |
20 | | - expect(page).to have_css(".featured-topics .featured-topic", count: 3) |
21 | | - expect(page).not_to have_css(".featured-topics-controls .page-button-container") |
22 | | - expect(page).not_to have_css(".featured-topics-controls .left-page-button") |
23 | | - expect(page).not_to have_css(".featured-topics-controls .right-page-button") |
| 37 | + # max_number_of_topics lower than number_of_topics should have no effect |
| 38 | + theme.update_setting(:max_number_of_topics, 2) |
| 39 | + theme.save! |
24 | 40 |
|
25 | | - # max_number_of_topics lower than number_of_topics should have no effect |
26 | | - theme.update_setting(:max_number_of_topics, 2) |
27 | | - theme.save! |
| 41 | + visit("/") |
| 42 | + expect(page).to have_css(".featured-topics .featured-topic", count: 3) |
| 43 | + expect(page).not_to have_css(".featured-topics-controls .page-button-container") |
| 44 | + expect(page).not_to have_css(".featured-topics-controls .left-page-button") |
| 45 | + expect(page).not_to have_css(".featured-topics-controls .right-page-button") |
28 | 46 |
|
29 | | - visit("/") |
30 | | - expect(page).to have_css(".featured-topics .featured-topic", count: 2) |
31 | | - expect(page).not_to have_css(".featured-topics-controls .page-button-container") |
32 | | - expect(page).not_to have_css(".featured-topics-controls .left-page-button") |
33 | | - expect(page).not_to have_css(".featured-topics-controls .right-page-button") |
34 | | - end |
| 47 | + theme.update_setting(:max_number_of_topics, 0) |
| 48 | + theme.save! |
| 49 | + |
| 50 | + visit("/") |
| 51 | + expect(page).to have_css(".featured-topics .featured-topic", count: 3) |
| 52 | + expect(page).not_to have_css(".featured-topics-controls .page-button-container") |
| 53 | + expect(page).not_to have_css(".featured-topics-controls .left-page-button") |
| 54 | + expect(page).not_to have_css(".featured-topics-controls .right-page-button") |
| 55 | + end |
35 | 56 |
|
36 | | - it "should allow pagination if max_number_of_topics > number_of_topics" do |
37 | | - theme.update_setting(:number_of_topics, 3) |
38 | | - theme.update_setting(:max_number_of_topics, 8) |
39 | | - theme.save! |
| 57 | + it "should allow pagination if max_number_of_topics > number_of_topics" do |
| 58 | + theme.update_setting(:number_of_topics, 3) |
| 59 | + theme.update_setting(:max_number_of_topics, 8) |
| 60 | + theme.save! |
40 | 61 |
|
41 | | - # First page should have no left arrow |
42 | | - visit("/") |
43 | | - expect(page).to have_css(".featured-topics .featured-topic", count: 3) |
44 | | - expect(page).to have_css(".featured-topics-controls .page-button-container") |
45 | | - expect(page).to have_css(".featured-topics-controls .right-page-button") |
46 | | - expect(page).not_to have_css(".featured-topics-controls .left-page-button") |
| 62 | + # First page should have no left arrow |
| 63 | + visit("/") |
| 64 | + expect(page).to have_css(".featured-topics .featured-topic", count: 3) |
| 65 | + expect(page).to have_css(".featured-topics-controls .page-button-container") |
| 66 | + expect(page).to have_css(".featured-topics-controls .right-page-button") |
| 67 | + expect(page).not_to have_css(".featured-topics-controls .left-page-button") |
47 | 68 |
|
48 | | - # Second page should have both arrows |
49 | | - find(".featured-topics-controls .right-page-button").click |
50 | | - expect(page).to have_css(".featured-topics .featured-topic", count: 3) |
51 | | - expect(page).to have_css(".featured-topics-controls .page-button-container") |
52 | | - expect(page).to have_css(".featured-topics-controls .right-page-button") |
53 | | - expect(page).to have_css(".featured-topics-controls .left-page-button") |
| 69 | + # Second page should have both arrows |
| 70 | + find(".featured-topics-controls .right-page-button").click |
| 71 | + expect(page).to have_css(".featured-topics .featured-topic", count: 3) |
| 72 | + expect(page).to have_css(".featured-topics-controls .page-button-container") |
| 73 | + expect(page).to have_css(".featured-topics-controls .right-page-button") |
| 74 | + expect(page).to have_css(".featured-topics-controls .left-page-button") |
54 | 75 |
|
55 | | - #Third page should have no right arrow, and only 2 featured topics |
56 | | - find(".featured-topics-controls .right-page-button").click |
57 | | - expect(page).to have_css(".featured-topics .featured-topic", count: 2) |
58 | | - expect(page).to have_css(".featured-topics-controls .page-button-container") |
59 | | - expect(page).not_to have_css(".featured-topics-controls .right-page-button") |
60 | | - expect(page).to have_css(".featured-topics-controls .left-page-button") |
| 76 | + #Third page should have no right arrow, and only 2 featured topics |
| 77 | + find(".featured-topics-controls .right-page-button").click |
| 78 | + expect(page).to have_css(".featured-topics .featured-topic", count: 2) |
| 79 | + expect(page).to have_css(".featured-topics-controls .page-button-container") |
| 80 | + expect(page).not_to have_css(".featured-topics-controls .right-page-button") |
| 81 | + expect(page).to have_css(".featured-topics-controls .left-page-button") |
61 | 82 |
|
62 | | - # Back to second page |
63 | | - find(".featured-topics-controls .left-page-button").click |
64 | | - expect(page).to have_css(".featured-topics .featured-topic", count: 3) |
65 | | - expect(page).to have_css(".featured-topics-controls .page-button-container") |
66 | | - expect(page).to have_css(".featured-topics-controls .right-page-button") |
67 | | - expect(page).to have_css(".featured-topics-controls .left-page-button") |
| 83 | + # Back to second page |
| 84 | + find(".featured-topics-controls .left-page-button").click |
| 85 | + expect(page).to have_css(".featured-topics .featured-topic", count: 3) |
| 86 | + expect(page).to have_css(".featured-topics-controls .page-button-container") |
| 87 | + expect(page).to have_css(".featured-topics-controls .right-page-button") |
| 88 | + expect(page).to have_css(".featured-topics-controls .left-page-button") |
| 89 | + end |
68 | 90 | end |
69 | 91 | end |
0 commit comments