Skip to content

OpenProject is the leading open source project management software for product, project and portfolio management. A powerful Jira alternative with agile planning, issue tracking, roadmaps, Gantt charts, time tracking, collaboration features, and more. Available on premises or in the cloud. ⭐ Star us on GitHub

HoverCardComponent unit tests

Tobias Dillmann991ce6b21677
diff --git a/app/components/projects/phases/hover_card_component.rb b/app/components/projects/phases/hover_card_component.rb
index 8db06c31de3..6751c2ea158 100644
--- a/app/components/projects/phases/hover_card_component.rb
+++ b/app/components/projects/phases/hover_card_component.rb
@@ -38,8 +38,12 @@ module Projects
def initialize(id:, gate: "start")
super
- @id = id
- @phase = Project::Phase.joins(:definition).includes(:definition).find(id)
+ @phase = Project::Phase
+ .joins(:definition)
+ .includes(:definition)
+ .where(active: true)
+ .find_by(id: id)
+
@gate = gate.to_sym
end
diff --git a/spec/components/projects/phases/hover_card_component_spec.rb b/spec/components/projects/phases/hover_card_component_spec.rb
new file mode 100644
index 00000000000..c124a628dd4
--- /dev/null
+++ b/spec/components/projects/phases/hover_card_component_spec.rb
@@ -0,0 +1,96 @@
+# frozen_string_literal: true
+
+#-- copyright
+# OpenProject is an open source project management software.
+# Copyright (C) the OpenProject GmbH
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License version 3.
+#
+# OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows:
+# Copyright (C) 2006-2013 Jean-Philippe Lang
+# Copyright (C) 2010-2013 the ChiliProject Team
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License
+# as published by the Free Software Foundation; either version 2
+# of the License, or (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+#
+# See COPYRIGHT and LICENSE files for more details.
+#++
+
+require "rails_helper"
+
+RSpec.describe Projects::Phases::HoverCardComponent, type: :component do
+ include Rails.application.routes.url_helpers
+
+ let(:phase) { create(:project_phase, :with_gated_definition) }
+ let(:phase_id) { phase.id }
+ let(:gate) { "start" }
+
+ subject { described_class.new(id: phase_id, gate:) }
+
+ before do
+ render_inline(subject)
+ page.extend TestSelectorFinders
+ end
+
+ context "for start" do
+ it "renders successfully" do
+ page.find_test_selector("phase-gate-hover-card-name", text: phase.definition.start_gate_name)
+ page.find_test_selector("phase-gate-hover-card-date", text: phase.start_date.strftime("%m/%d/%Y"))
+ end
+
+ context "without a definition" do
+ let(:phase) { create(:project_phase) }
+
+ it "renders, but has no content" do
+ page.find_test_selector("phase-gate-hover-card-name", text: "")
+ page.find_test_selector("phase-gate-hover-card-date", text: "")
+ end
+ end
+ end
+
+ context "for finish" do
+ let(:gate) { "finish" }
+
+ it "renders successfully" do
+ page.find_test_selector("phase-gate-hover-card-name", text: phase.definition.finish_gate_name)
+ page.find_test_selector("phase-gate-hover-card-date", text: phase.finish_date.strftime("%m/%d/%Y"))
+ end
+
+ context "without a definition" do
+ let(:phase) { create(:project_phase) }
+
+ it "renders, but has no content" do
+ page.find_test_selector("phase-gate-hover-card-name", text: "")
+ page.find_test_selector("phase-gate-hover-card-date", text: "")
+ end
+ end
+ end
+
+ context "when inactive" do
+ let(:phase) { create(:project_phase, active: false) }
+
+ it "renders a generic error message" do
+ expect(page).to have_text(I18n.t("http.response.unexpected"))
+ end
+ end
+
+ context "when phase cannot be found in database" do
+ let(:phase_id) { :does_not_exist }
+
+ it "renders a generic error message" do
+ expect(page).to have_text(I18n.t("http.response.unexpected"))
+ end
+ end
+end