Skip to content

DEV: bring back filter spec #42

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 30, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 48 additions & 0 deletions spec/system/doc_category_sidebar_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
end

let(:sidebar) { PageObjects::Components::NavigationMenu::Sidebar.new }
let(:filter) { PageObjects::Components::Filter.new }

def docs_section_name(title)
"discourse-docs-sidebar__#{Slug.for(title)}"
Expand Down Expand Up @@ -176,6 +177,53 @@ def expect_docs_sidebar_to_be_correct
end
end

context "when filtering" do
it "suggests filtering the content when there are no results" do
SiteSetting.max_category_nesting = 3
documentation_subsubcategory =
Fabricate(:category_with_definition, parent_category_id: documentation_subcategory.id)

visit("/c/#{documentation_category.slug}/#{documentation_category.id}")

filter.filter("missing")
expect(page).to have_no_css(".sidebar-section-link-content-text")
expect(page).to have_css(".sidebar-no-results")

no_results_description = page.find(".sidebar-no-results__description")
expect(no_results_description.text).to eq(
"We couldn’t find anything matching ‘missing’.\nDo you want to perform a search on this category or a site wide search instead?",
)

suggested_category_search = page.find(".docs-sidebar-suggested-category-search")
expect(suggested_category_search[:href]).to end_with(
"/search?q=missing%20%23#{documentation_category.slug}",
)

site_wide_search = page.find(".docs-sidebar-suggested-site-search")
expect(site_wide_search[:href]).to end_with("/search?q=missing")

# for subcategories
visit(
"/c/#{documentation_category.slug}/#{documentation_subcategory.slug}/#{documentation_subcategory.id}",
)
filter.filter("missing")

suggested_category_search = page.find(".docs-sidebar-suggested-category-search")
expect(suggested_category_search[:href]).to end_with(
"/search?q=missing%20%23#{documentation_category.slug}%3A#{documentation_subcategory.slug}",
)

# for 3 levels deep
visit("/c/#{documentation_subsubcategory.id}")
filter.filter("missing")

suggested_category_search = page.find(".docs-sidebar-suggested-category-search")
expect(suggested_category_search[:href]).to end_with(
"/search?q=missing%20category%3A#{documentation_subsubcategory.id}",
)
end
end

it "links correctly back to forum" do
sign_in(admin)

Expand Down