diff --git a/app/views/header/projects/index.html.erb b/app/views/header/projects/index.html.erb
index 7f3a8455ca93..a45b5de1ca6c 100644
--- a/app/views/header/projects/index.html.erb
+++ b/app/views/header/projects/index.html.erb
@@ -34,13 +34,21 @@ See COPYRIGHT and LICENSE files for more details.
test_selector: "op-header-project-select--list" }
)
) do |tree| %>
- <% @tree.each do |node| %>
- <%= render Header::Projects::NodeComponent.new(
- component: tree,
- node:,
- current_project_id: @current_project_id,
- favorited_ids: @favorited_ids,
- jump: @jump
- ) %>
+ <% if @tree.empty? && params[:filter_mode] == "favorited" && params[:query].blank? %>
+ <% tree.with_leaf(
+ label: t("header.project_select_component.no_favorite_projects"),
+ disabled: true,
+ data: { test_selector: "op-header-project-select--no-favourites" }
+ ) %>
+ <% else %>
+ <% @tree.each do |node| %>
+ <%= render Header::Projects::NodeComponent.new(
+ component: tree,
+ node:,
+ current_project_id: @current_project_id,
+ favorited_ids: @favorited_ids,
+ jump: @jump
+ ) %>
+ <% end %>
<% end %>
<% end %>
diff --git a/config/locales/en.yml b/config/locales/en.yml
index aea3d9e537ff..c100ce467f00 100644
--- a/config/locales/en.yml
+++ b/config/locales/en.yml
@@ -3608,6 +3608,7 @@ en:
all_projects: "All projects"
favorites: "Favorites"
leave_project: "Leave project"
+ no_favorite_projects: "You have no favorite projects."
title: "Projects"
toggle_switch:
diff --git a/spec/controllers/header/projects_controller_spec.rb b/spec/controllers/header/projects_controller_spec.rb
index 90f5711efa24..981b9aa42683 100644
--- a/spec/controllers/header/projects_controller_spec.rb
+++ b/spec/controllers/header/projects_controller_spec.rb
@@ -38,6 +38,7 @@
end
describe "#index" do
+ render_views
shared_let(:parent_project) { create(:project, name: "Alpha Parent") }
shared_let(:child_project) { create(:project, name: "Beta Child", parent: parent_project) }
shared_let(:other_project) { create(:project, name: "Gamma Other") }
@@ -117,6 +118,20 @@
make_request
expect(assigns(:projects)).to be_empty
end
+
+ it "renders the no-favourites placeholder" do
+ make_request
+ expect(response.body).to include("op-header-project-select--no-favourites")
+ end
+
+ context "when a query is present" do
+ subject(:make_request) { get :index, params: { filter_mode: "favorited", query: "Alpha" } }
+
+ it "does not render the no-favourites placeholder" do
+ make_request
+ expect(response.body).not_to include("op-header-project-select--no-favourites")
+ end
+ end
end
context "when the user is anonymous" do