Skip to content

Commit c0c49da

Browse files
committed
Fix/add a test case
1 parent 13bfc7e commit c0c49da

File tree

2 files changed

+74
-52
lines changed

2 files changed

+74
-52
lines changed

javascripts/discourse/components/featured-homepage-topics.gjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ export default class FeaturedHomepageTopics extends Component {
168168
}
169169

170170
get showPageArrows() {
171-
return settings.max_number_of_topics > settings.number_of_topics;
171+
return settings.max_number_of_topics > settings.number_of_topics && this.featuredTopicsAvailable > settings.number_of_topics;
172172
}
173173

174174
get showLeftArrow() {

spec/system/pagination_spec.rb

Lines changed: 73 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -2,68 +2,90 @@
22

33
RSpec.describe "Pagination", type: :system do
44
let!(:theme) { upload_theme_component }
5+
fab!(:tag) { Fabricate(:tag, name: "featured") }
6+
fab!(:upload) { Fabricate(:image_upload) }
57

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
822

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]) }
1025

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!
1330

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")
1836

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!
2440

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")
2846

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
3556

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!
4061

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")
4768

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")
5475

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")
6182

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
6890
end
6991
end

0 commit comments

Comments
 (0)