FIX: Better infinite scrolling on categories page (#24831)

This commit refactor CategoryList to remove usage of EmberObject,
hopefully make the code more readable and fixes various edge cases with
lazy loaded categories (third level subcategories not being visible,
subcategories not being visible on category page, requesting for more
pages even if the last one did not return any results, etc).

The problems have always been here, but were not visible because a lot
of the processing was handled by the server and then the result was
serialized. With more of these being moved to the client side for the
lazy category loading, the problems became more obvious.
This commit is contained in:
Bianca Nenciu
2023-12-18 16:46:09 +02:00
committed by GitHub
parent 092633c14f
commit 680cf443f4
6 changed files with 97 additions and 65 deletions

View File

@ -374,4 +374,18 @@ RSpec.describe CategoryList do
expect(category_list.categories[-1].custom_field_preloaded?("bob")).to be_falsey
end
end
describe "lazy_load_categories" do
fab!(:category) { Fabricate(:category, user: admin) }
fab!(:subcategory) { Fabricate(:category, user: admin, parent_category: category) }
before { SiteSetting.lazy_load_categories = true }
it "returns categories with subcategory_ids" do
expect(category_list.categories.size).to eq(3)
expect(
category_list.categories.find { |c| c.id == category.id }.subcategory_ids,
).to contain_exactly(subcategory.id)
end
end
end