Skip to content

A platform for community discussion. Free, open, simple.

FIX: group subcategories under parent in composer category chooser (#37892)

Osama Sayegh8a0aa778fd0e
diff --git a/frontend/discourse/select-kit/components/category-chooser.js b/frontend/discourse/select-kit/components/category-chooser.js
index 55cddd7e148..944e76dffe2 100644
--- a/frontend/discourse/select-kit/components/category-chooser.js
+++ b/frontend/discourse/select-kit/components/category-chooser.js
@@ -151,7 +151,7 @@ export default class CategoryChooser extends ComboBoxComponent {
prioritizedCategoryId = null,
} = {}) {
const categories = this.fixedCategoryPositionsOnCreate
- ? Category.list()
+ ? Category.sortCategories(Category.list())
: Category.listByActivity();
let { readOnlyCategoryId } = this.selectKit.options;
diff --git a/spec/system/composer_spec.rb b/spec/system/composer_spec.rb
index c3e5bf1968f..4b1ccc25c42 100644
--- a/spec/system/composer_spec.rb
+++ b/spec/system/composer_spec.rb
@@ -122,4 +122,30 @@ describe "Composer", type: :system do
expect(topic_page.topic_tags).to include(tag.name)
end
end
+
+ context "with fixed category positions" do
+ fab!(:parent_category) { Fabricate(:category, name: "Software", position: 102) }
+ fab!(:subcategory) do
+ Fabricate(:category, name: "Email", parent_category: parent_category, position: 25)
+ end
+
+ before do
+ SiteSetting.fixed_category_positions = true
+ SiteSetting.fixed_category_positions_on_create = true
+ end
+
+ it "groups subcategories immediately after their parent in the category chooser" do
+ visit "/new-topic"
+ expect(composer).to be_opened
+
+ category_chooser = composer.category_chooser
+ category_chooser.expand
+
+ option_names = category_chooser.option_names
+ parent_index = option_names.index("Software")
+ child_index = option_names.index("Email")
+
+ expect(child_index).to eq(parent_index + 1)
+ end
+ end
end
diff --git a/spec/system/page_objects/components/select_kit.rb b/spec/system/page_objects/components/select_kit.rb
index 3c38f3c80ba..2ccd5d2776c 100644
--- a/spec/system/page_objects/components/select_kit.rb
+++ b/spec/system/page_objects/components/select_kit.rb
@@ -133,6 +133,10 @@ module PageObjects
def clear
expanded_component.all(".selected-choice").each(&:click)
end
+
+ def option_names
+ expanded_component.all(".select-kit-row").map { |row| row["data-name"] }
+ end
end
end
end