From 07eca6d8cde1b8b5eb4eba7a239ad9f4679b2d00 Mon Sep 17 00:00:00 2001 From: Tomas Hykel Date: Wed, 10 Jun 2026 20:46:10 +0000 Subject: [PATCH] [STC-337] Fix rendered date of edited comments --- .../activities_tab/shared_helpers.rb | 6 +- .../journals/item_component_spec.rb | 68 +++++++++++++++++++ 2 files changed, 71 insertions(+), 3 deletions(-) create mode 100644 spec/components/work_packages/activities_tab/journals/item_component_spec.rb diff --git a/app/components/work_packages/activities_tab/shared_helpers.rb b/app/components/work_packages/activities_tab/shared_helpers.rb index 0a935004560..57944a96092 100644 --- a/app/components/work_packages/activities_tab/shared_helpers.rb +++ b/app/components/work_packages/activities_tab/shared_helpers.rb @@ -57,13 +57,13 @@ module WorkPackages "#{auto_scrolling_controller}-anchor-name-param": activity_anchor_name } )) do - journal_updated_at_formatted_time(journal) + journal_created_at_formatted_time(journal) end end - def journal_updated_at_formatted_time(journal) + def journal_created_at_formatted_time(journal) render(Primer::Beta::Text.new(font_size: :small, color: :subtle, mt: 1)) do - format_time(journal.updated_at) + format_time(journal.created_at) end end diff --git a/spec/components/work_packages/activities_tab/journals/item_component_spec.rb b/spec/components/work_packages/activities_tab/journals/item_component_spec.rb new file mode 100644 index 00000000000..87d4e8b1d02 --- /dev/null +++ b/spec/components/work_packages/activities_tab/journals/item_component_spec.rb @@ -0,0 +1,68 @@ +# 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 "spec_helper" + +# Minimal wrapper to test SharedHelpers#journal_created_at_formatted_time +# without the routing dependencies of the full ItemComponent template. +class JournalCreatedAtFormattedTimeTestComponent < ApplicationComponent + include ApplicationHelper + include WorkPackages::ActivitiesTab::SharedHelpers + + def initialize(journal) + super(nil) + @journal = journal + end + + def call + journal_created_at_formatted_time(@journal) + end +end + +RSpec.describe WorkPackages::ActivitiesTab::Journals::ItemComponent, type: :component do + include Redmine::I18n + + describe "activity anchor link date" do + let(:created_at) { 3.days.ago.beginning_of_minute } + let(:updated_at) { 1.day.ago.beginning_of_minute } + let(:journal) { build_stubbed(:work_package_journal, created_at:, updated_at:) } + + context "when a journal has been edited (updated_at differs from created_at)" do + it "shows created_at rather than updated_at in the header link" do + expect(format_time(created_at)).not_to eq(format_time(updated_at)) + + render_inline(JournalCreatedAtFormattedTimeTestComponent.new(journal)) + + expect(page).to have_text(format_time(created_at)) + expect(page).to have_no_text(format_time(updated_at)) + end + end + end +end