mirror of
https://github.com/discourse/discourse.git
synced 2025-02-25 18:55:32 -06:00
DEV: Async category search for sidebar modal (#25686)
This commit is contained in:
committed by
GitHub
parent
716e3a4dd5
commit
13083d03ae
@@ -1483,4 +1483,31 @@ RSpec.describe Category do
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe ".ancestors_of" do
|
||||
fab!(:category)
|
||||
fab!(:subcategory) { Fabricate(:category, parent_category: category) }
|
||||
|
||||
fab!(:sub_subcategory) do
|
||||
SiteSetting.max_category_nesting = 3
|
||||
Fabricate(:category, parent_category: subcategory)
|
||||
end
|
||||
|
||||
it "finds the parent" do
|
||||
expect(Category.ancestors_of([subcategory.id]).to_a).to eq([category])
|
||||
end
|
||||
|
||||
it "finds the grandparent" do
|
||||
expect(Category.ancestors_of([sub_subcategory.id]).to_a).to contain_exactly(
|
||||
category,
|
||||
subcategory,
|
||||
)
|
||||
end
|
||||
|
||||
it "respects the relation it's called on" do
|
||||
expect(Category.where.not(id: category.id).ancestors_of([sub_subcategory.id]).to_a).to eq(
|
||||
[subcategory],
|
||||
)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -1127,6 +1127,30 @@ RSpec.describe CategoriesController do
|
||||
[category, category2, subcategory].each { |c| SearchIndexer.index(c, force: true) }
|
||||
end
|
||||
|
||||
context "without include_ancestors" do
|
||||
it "doesn't return ancestors" do
|
||||
get "/categories/search.json", params: { term: "Notfoo" }
|
||||
|
||||
expect(response.parsed_body).not_to have_key("ancestors")
|
||||
end
|
||||
end
|
||||
|
||||
context "with include_ancestors=false" do
|
||||
it "returns ancestors" do
|
||||
get "/categories/search.json", params: { term: "Notfoo", include_ancestors: false }
|
||||
|
||||
expect(response.parsed_body).not_to have_key("ancestors")
|
||||
end
|
||||
end
|
||||
|
||||
context "with include_ancestors=true" do
|
||||
it "returns ancestors" do
|
||||
get "/categories/search.json", params: { term: "Notfoo", include_ancestors: true }
|
||||
|
||||
expect(response.parsed_body).to have_key("ancestors")
|
||||
end
|
||||
end
|
||||
|
||||
context "with term" do
|
||||
it "returns categories" do
|
||||
get "/categories/search.json", params: { term: "Foo" }
|
||||
|
||||
@@ -3,10 +3,10 @@
|
||||
RSpec.describe "Editing sidebar categories navigation", type: :system do
|
||||
fab!(:user)
|
||||
|
||||
fab!(:category2) { Fabricate(:category, name: "category2") }
|
||||
fab!(:category2) { Fabricate(:category, name: "category 2") }
|
||||
|
||||
fab!(:category2_subcategory) do
|
||||
Fabricate(:category, parent_category_id: category2.id, name: "category2 subcategory")
|
||||
Fabricate(:category, parent_category_id: category2.id, name: "category 2 subcategory")
|
||||
end
|
||||
|
||||
fab!(:category) { Fabricate(:category, name: "category") }
|
||||
@@ -21,6 +21,19 @@ RSpec.describe "Editing sidebar categories navigation", type: :system do
|
||||
|
||||
let(:sidebar) { PageObjects::Components::NavigationMenu::Sidebar.new }
|
||||
|
||||
before_all do
|
||||
Jobs.with_immediate_jobs do
|
||||
SearchIndexer.with_indexing do
|
||||
category2.index_search
|
||||
category2_subcategory.index_search
|
||||
|
||||
category.index_search
|
||||
category_subcategory2.index_search
|
||||
category_subcategory.index_search
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
before { sign_in(user) }
|
||||
|
||||
shared_examples "a user can edit the sidebar categories navigation" do |mobile|
|
||||
@@ -149,9 +162,11 @@ RSpec.describe "Editing sidebar categories navigation", type: :system do
|
||||
|
||||
modal = sidebar.click_edit_categories_button
|
||||
|
||||
modal.filter("category subcategory 2")
|
||||
modal.filter("subcategory")
|
||||
|
||||
expect(modal).to have_categories([category, category_subcategory2])
|
||||
expect(modal).to have_categories(
|
||||
[category, category_subcategory, category_subcategory2, category2, category2_subcategory],
|
||||
)
|
||||
|
||||
modal.filter("2")
|
||||
|
||||
@@ -233,10 +248,20 @@ RSpec.describe "Editing sidebar categories navigation", type: :system do
|
||||
Fabricate(
|
||||
:category,
|
||||
parent_category_id: category2_subcategory.id,
|
||||
name: "category2 subcategory subcategory",
|
||||
name: "category 2 subcategory subcategory",
|
||||
)
|
||||
end
|
||||
|
||||
before_all do
|
||||
Jobs.with_immediate_jobs do
|
||||
SearchIndexer.with_indexing do
|
||||
category_subcategory_subcategory.index_search
|
||||
category_subcategory_subcategory2.index_search
|
||||
category2_subcategory_subcategory.index_search
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
it "allows a user to edit sub-subcategories to be included in the sidebar categories section" do
|
||||
visit "/latest"
|
||||
|
||||
@@ -265,10 +290,18 @@ RSpec.describe "Editing sidebar categories navigation", type: :system do
|
||||
expect(sidebar).to have_categories_section
|
||||
|
||||
modal = sidebar.click_edit_categories_button
|
||||
modal.filter("category2 subcategory subcategory")
|
||||
modal.filter("category 2 subcategory subcategory")
|
||||
|
||||
expect(modal).to have_categories(
|
||||
[category2, category2_subcategory, category2_subcategory_subcategory],
|
||||
[
|
||||
category,
|
||||
category_subcategory,
|
||||
category_subcategory_subcategory2,
|
||||
category_subcategory2,
|
||||
category2,
|
||||
category2_subcategory,
|
||||
category2_subcategory_subcategory,
|
||||
],
|
||||
)
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user