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:
Bianca Nenciu
2024-03-28 18:19:09 +02:00
committed by GitHub
parent 5835d4e5ed
commit 3b9e9354d6
2 changed files with 34 additions and 1 deletions

View File

@ -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