Skip to content

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

FIX: hide header search for certain routes (#34294)

Yuriy Kurant57ae1b86df54
diff --git a/app/assets/javascripts/discourse/app/components/header/contents.gjs b/app/assets/javascripts/discourse/app/components/header/contents.gjs
index e673db467d2..a74425be427 100644
--- a/app/assets/javascripts/discourse/app/components/header/contents.gjs
+++ b/app/assets/javascripts/discourse/app/components/header/contents.gjs
@@ -41,12 +41,17 @@ export default class Contents extends Component {
}
get showHeaderSearch() {
+ const hideForRoutes = [
+ "signup",
+ "login",
+ "invites.show",
+ "activate-account",
+ ];
+
if (
this.site.mobileView ||
this.args.narrowDesktop ||
- this.router.currentURL?.match(
- /\/(signup|login|invites|activate-account)/
- ) ||
+ hideForRoutes.some((name) => name === this.router.currentRouteName) ||
this.search.welcomeBannerSearchInViewport
) {
return false;
diff --git a/app/assets/javascripts/discourse/tests/integration/components/header-contents-test.gjs b/app/assets/javascripts/discourse/tests/integration/components/header-contents-test.gjs
index e89d1051c54..c8546a7785c 100644
--- a/app/assets/javascripts/discourse/tests/integration/components/header-contents-test.gjs
+++ b/app/assets/javascripts/discourse/tests/integration/components/header-contents-test.gjs
@@ -8,24 +8,74 @@ import { setupRenderingTest } from "discourse/tests/helpers/component-test";
module("Integration | Component | Header | Contents", function (hooks) {
setupRenderingTest(hooks);
- test("showHeaderSearch", async function (assert) {
- const site = getOwner(this).lookup("service:site");
- const toggleNavigationMenu = () => {};
-
- sinon.stub(site, "mobileView").value(true);
-
- await render(
- <template>
- <Contents
- @sidebarEnabled={{true}}
- @toggleNavigationMenu={{toggleNavigationMenu}}
- @showSidebar={{true}}
- >test</Contents>
- </template>
- );
-
- assert
- .dom(".floating-search-input-wrapper")
- .doesNotExist("it does not display when the site is in mobile view");
+ hooks.beforeEach(function () {
+ this.router = getOwner(this).lookup("service:router");
+ const search = getOwner(this).lookup("service:search");
+ sinon.stub(search, "searchExperience").value("search_field");
+ });
+
+ hooks.afterEach(function () {
+ sinon.restore(); // clean up all stubs
+ });
+
+ module("header search", function () {
+ test("is hidden in mobile view", async function (assert) {
+ const site = getOwner(this).lookup("service:site");
+ sinon.stub(site, "mobileView").value(true);
+
+ await render(<template><Contents /></template>);
+
+ assert.dom(".floating-search-input-wrapper").doesNotExist();
+ });
+
+ module("routes handling", function () {
+ test('is hidden in route "signup"', async function (assert) {
+ sinon.stub(this.router, "currentRouteName").value("signup");
+
+ await render(<template><Contents /></template>);
+
+ assert.dom(".floating-search-input-wrapper").doesNotExist();
+ });
+
+ test('is hidden in route "login"', async function (assert) {
+ sinon.stub(this.router, "currentRouteName").value("login");
+
+ await render(<template><Contents /></template>);
+
+ assert.dom(".floating-search-input-wrapper").doesNotExist();
+ });
+
+ test('is hidden in route "invites.show"', async function (assert) {
+ sinon.stub(this.router, "currentRouteName").value("invites.show");
+
+ await render(<template><Contents /></template>);
+
+ assert.dom(".floating-search-input-wrapper").doesNotExist();
+ });
+
+ test('is hidden in route "activate-account"', async function (assert) {
+ sinon.stub(this.router, "currentRouteName").value("activate-account");
+
+ await render(<template><Contents /></template>);
+
+ assert.dom(".floating-search-input-wrapper").doesNotExist();
+ });
+
+ test('is shown in route "login-preferences"', async function (assert) {
+ sinon.stub(this.router, "currentRouteName").value("login-preferences");
+
+ await render(<template><Contents /></template>);
+
+ assert.dom(".floating-search-input-wrapper").exists();
+ });
+
+ test('is shown in route "badges.show"', async function (assert) {
+ sinon.stub(this.router, "currentRouteName").value("badges.show");
+
+ await render(<template><Contents /></template>);
+
+ assert.dom(".floating-search-input-wrapper").exists();
+ });
+ });
});
});