mirror of
https://github.com/discourse/discourse.git
synced 2025-05-29 22:18:08 +08:00
DEV: Better categories pagination (#26421)
Pagination is enabled only when "lazy load categories" is enabled. For those cases when it is not, the first page should return all the results.
This commit is contained in:
@ -397,6 +397,35 @@ RSpec.describe CategoriesController do
|
||||
response.parsed_body["category_list"]["categories"].map { |x| x["id"] },
|
||||
).not_to include(uncategorized.id)
|
||||
end
|
||||
|
||||
describe "with page" do
|
||||
before { sign_in(admin) }
|
||||
|
||||
let!(:category2) { Fabricate(:category, user: admin) }
|
||||
let!(:category3) { Fabricate(:category, user: admin) }
|
||||
|
||||
it "paginates results wihen lazy_load_categories is enabled" do
|
||||
SiteSetting.lazy_load_categories_groups = "#{Group::AUTO_GROUPS[:everyone]}"
|
||||
|
||||
stub_const(CategoryList, "CATEGORIES_PER_PAGE", 2) { get "/categories.json?page=1" }
|
||||
expect(response.status).to eq(200)
|
||||
expect(response.parsed_body["category_list"]["categories"].count).to eq(2)
|
||||
|
||||
stub_const(CategoryList, "CATEGORIES_PER_PAGE", 2) { get "/categories.json?page=2" }
|
||||
expect(response.status).to eq(200)
|
||||
expect(response.parsed_body["category_list"]["categories"].count).to eq(2)
|
||||
end
|
||||
|
||||
it "does not paginate results when lazy_load_categories is disabled" do
|
||||
stub_const(CategoryList, "CATEGORIES_PER_PAGE", 2) { get "/categories.json?page=1" }
|
||||
expect(response.status).to eq(200)
|
||||
expect(response.parsed_body["category_list"]["categories"].count).to eq(4)
|
||||
|
||||
stub_const(CategoryList, "CATEGORIES_PER_PAGE", 2) { get "/categories.json?page=2" }
|
||||
expect(response.status).to eq(200)
|
||||
expect(response.parsed_body["category_list"]["categories"].count).to eq(0)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe "extensibility event" do
|
||||
|
Reference in New Issue
Block a user