Skip to content

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

FIX: don't error when no filter is set in discovery heading (#32516)

Penar Musaraj4e760f7b7957
diff --git a/app/assets/javascripts/discourse/app/components/discovery/accessible-discovery-heading.gjs b/app/assets/javascripts/discourse/app/components/discovery/accessible-discovery-heading.gjs
index d24d1fa80f6..2cdfacac35c 100644
--- a/app/assets/javascripts/discourse/app/components/discovery/accessible-discovery-heading.gjs
+++ b/app/assets/javascripts/discourse/app/components/discovery/accessible-discovery-heading.gjs
@@ -5,7 +5,7 @@ export default class AccessibleDiscoveryHeading extends Component {
get filterKey() {
const filter = this.args.filter;
- if (filter === "categories") {
+ if (!filter || filter === "categories") {
return null;
}
@@ -89,6 +89,8 @@ export default class AccessibleDiscoveryHeading extends Component {
}
<template>
- <h1 id="topic-list-heading" class="sr-only">{{this.label}}</h1>
+ {{#if @filter}}
+ <h1 id="topic-list-heading" class="sr-only">{{this.label}}</h1>
+ {{/if}}
</template>
}
diff --git a/app/assets/javascripts/discourse/tests/integration/components/accessible-discovery-heading-test.gjs b/app/assets/javascripts/discourse/tests/integration/components/accessible-discovery-heading-test.gjs
new file mode 100644
index 00000000000..d7e7508d959
--- /dev/null
+++ b/app/assets/javascripts/discourse/tests/integration/components/accessible-discovery-heading-test.gjs
@@ -0,0 +1,63 @@
+import { render } from "@ember/test-helpers";
+import { setupRenderingTest } from "ember-qunit";
+import hbs from "htmlbars-inline-precompile";
+import { module, test } from "qunit";
+
+module("Component | discovery/accessible-discovery-heading", function (hooks) {
+ setupRenderingTest(hooks);
+
+ test("it renders the correct label for categories filter", async function (assert) {
+ this.set("filter", "categories");
+
+ await render(
+ hbs`<Discovery::AccessibleDiscoveryHeading @filter={{this.filter}} />`
+ );
+
+ assert
+ .dom("#topic-list-heading")
+ .hasText("All categories", "The label is correct for categories filter");
+ });
+
+ test("it renders the correct label for a single tag", async function (assert) {
+ this.setProperties({
+ filter: "tag",
+ tag: { id: "javascript" },
+ });
+
+ await render(
+ hbs`<Discovery::AccessibleDiscoveryHeading @filter={{this.filter}} @tag={{this.tag}} />`
+ );
+
+ assert
+ .dom("#topic-list-heading")
+ .hasText(
+ "topics tagged with javascript",
+ "The label is correct for a single tag"
+ );
+ });
+
+ test("it renders the correct label for a category and tag", async function (assert) {
+ this.setProperties({
+ filter: "tag",
+ category: { name: "Development" },
+ tag: { id: "javascript" },
+ });
+
+ await render(
+ hbs`<Discovery::AccessibleDiscoveryHeading @filter={{this.filter}} @category={{this.category}} @tag={{this.tag}} />`
+ );
+
+ assert
+ .dom("#topic-list-heading")
+ .hasText(
+ "topics in Development tagged with javascript",
+ "The label is correct for a category and tag"
+ );
+ });
+
+ test("it renders nothing for no filter", async function (assert) {
+ await render(hbs`<Discovery::AccessibleDiscoveryHeading />`);
+
+ assert.dom("#topic-list-heading").doesNotExist("The label is not shown");
+ });
+});
diff --git a/config/locales/client.en.yml b/config/locales/client.en.yml
index d5ddbb83a73..c43da5890bb 100644
--- a/config/locales/client.en.yml
+++ b/config/locales/client.en.yml
@@ -5217,7 +5217,7 @@ en:
bookmarks: "Topics in %{category} without tags you've bookmarked"
single_tag:
- default: "%{filter} topics tagged %{tag}"
+ default: "%{filter} topics tagged with %{tag}"
posted: "Topics tagged %{tag} you've posted in"
bookmarks: "Topics tagged %{tag} you’ve bookmarked"
@@ -5227,7 +5227,7 @@ en:
bookmarks: "Topics tagged %{tags} you’ve bookmarked"
category_tag:
- default: "%{filter} topics in %{category} tagged %{tag}"
+ default: "%{filter} topics in %{category} tagged with %{tag}"
posted: "Topics in %{category} tagged %{tag} you’ve posted in"
bookmarks: "Topics in %{category} tagged %{tag} you’ve bookmarked"
@@ -5599,7 +5599,7 @@ en:
modal_title: "Search anything in admin"
title: "Search"
instructions: "Type to search for pages, settings, reports, themes, components, and more..."
- no_results: 'We couldn’t find anything matching ‘%{filter}’.'
+ no_results: "We couldn’t find anything matching ‘%{filter}’."
result_types:
page:
one: "Page"
diff --git a/spec/system/discovery_h1_accessibility_spec.rb b/spec/system/discovery_h1_accessibility_spec.rb
index 6780ad4f31f..730ad3b2dbf 100644
--- a/spec/system/discovery_h1_accessibility_spec.rb
+++ b/spec/system/discovery_h1_accessibility_spec.rb
@@ -17,12 +17,12 @@ describe "Discovery heading accessibility", type: :system do
it "shows correct heading for tagged view" do
visit "/tags/#{tag.name}"
- expect(page).to have_selector("h1", text: "Latest topics tagged help")
+ expect(page).to have_selector("h1", text: "Latest topics tagged with help")
end
it "shows correct heading for category + tag view" do
visit "/tags/c/#{category.slug}/#{category.id}/#{tag.name}"
- expect(page).to have_selector("h1", text: "Latest topics in General tagged help")
+ expect(page).to have_selector("h1", text: "Latest topics in General tagged with help")
end
it "shows correct heading for no tags view" do