FIX: Make category-drop work with lazy_load_categories (#24187)

The category drop was rerendered after every category async change
because it updated the categories list. This is not necessary and
categories can be referenced indirectly by ID instead.
This commit is contained in:
Bianca Nenciu
2023-11-28 17:58:47 +02:00
committed by GitHub
parent 21d614215b
commit e85a81f33c
17 changed files with 165 additions and 63 deletions

View File

@@ -1298,6 +1298,8 @@ RSpec.describe Category do
let(:guardian) { Guardian.new(admin) }
fab!(:category)
before { Category.clear_parent_ids }
describe "when category is uncategorized" do
it "should return the reason" do
category = Category.find(SiteSetting.uncategorized_category_id)

View File

@@ -79,10 +79,7 @@
"items": {}
},
"has_children": {
"type": [
"string",
"null"
]
"type": "boolean"
},
"sort_order": {
"type": [

View File

@@ -82,10 +82,7 @@
"items": {}
},
"has_children": {
"type": [
"string",
"null"
]
"type": "boolean"
},
"sort_order": {
"type": [

View File

@@ -1040,6 +1040,31 @@ RSpec.describe CategoriesController do
end
end
describe "#find" do
fab!(:category) { Fabricate(:category, name: "Foo") }
fab!(:subcategory) { Fabricate(:category, name: "Foobar", parent_category: category) }
it "returns the category" do
get "/categories/find.json",
params: {
category_slug_path_with_id: "#{category.slug}/#{category.id}",
}
expect(response.parsed_body["category"]["id"]).to eq(category.id)
expect(response.parsed_body["ancestors"]).to eq([])
end
it "returns the subcategory and ancestors" do
get "/categories/find.json",
params: {
category_slug_path_with_id: "#{subcategory.slug}/#{subcategory.id}",
}
expect(response.parsed_body["category"]["id"]).to eq(subcategory.id)
expect(response.parsed_body["ancestors"].map { |c| c["id"] }).to eq([category.id])
end
end
describe "#search" do
fab!(:category) { Fabricate(:category, name: "Foo") }
fab!(:subcategory) { Fabricate(:category, name: "Foobar", parent_category: category) }
@@ -1066,9 +1091,8 @@ RSpec.describe CategoriesController do
it "returns categories" do
get "/categories/search.json", params: { parent_category_id: category.id }
expect(response.parsed_body["categories"].size).to eq(2)
expect(response.parsed_body["categories"].size).to eq(1)
expect(response.parsed_body["categories"].map { |c| c["name"] }).to contain_exactly(
"Foo",
"Foobar",
)
end