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

added first specs for primerized workpackage activities

Jonas Jabarif8915bfe764b
diff --git a/app/components/work_packages/activities_tab/index_component.rb b/app/components/work_packages/activities_tab/index_component.rb
index 00295568de8..e957fcb19f4 100644
--- a/app/components/work_packages/activities_tab/index_component.rb
+++ b/app/components/work_packages/activities_tab/index_component.rb
@@ -48,6 +48,7 @@ module WorkPackages
def wrapper_data_attributes
{
+ test_selector: "op-wp-activity-tab",
controller: "work-packages--activities-tab--index",
"application-target": "dynamic",
"work-packages--activities-tab--index-update-streams-url-value": update_streams_work_package_activities_url(work_package),
@@ -55,13 +56,17 @@ module WorkPackages
"work-packages--activities-tab--index-filter-value": filter,
"work-packages--activities-tab--index-user-id-value": User.current.id,
"work-packages--activities-tab--index-work-package-id-value": work_package.id,
- "work-packages--activities-tab--index-polling-interval-in-ms-value": 10000 # protoypical implementation
+ "work-packages--activities-tab--index-polling-interval-in-ms-value": polling_interval # protoypical implementation
}
end
def journal_sorting
User.current.preference&.comments_sorting || "desc"
end
+
+ def polling_interval
+ ENV["WORK_PACKAGES_ACTIVITIES_TAB_POLLING_INTERVAL_IN_MS"] || 10000
+ end
end
end
end
diff --git a/app/components/work_packages/activities_tab/journals/filter_and_sorting_component.html.erb b/app/components/work_packages/activities_tab/journals/filter_and_sorting_component.html.erb
index 298b2fe31de..e237db62596 100644
--- a/app/components/work_packages/activities_tab/journals/filter_and_sorting_component.html.erb
+++ b/app/components/work_packages/activities_tab/journals/filter_and_sorting_component.html.erb
@@ -3,7 +3,10 @@
flex_layout(justify_content: :space_between) do |container|
container.with_column do
- render(Primer::Alpha::ActionMenu.new(select_variant: :single, dynamic_label: true)) do |menu|
+ render(Primer::Alpha::ActionMenu.new(
+ select_variant: :single, dynamic_label: true,
+ data: { "test_selector": "op-wp-journals-filter-menu" }
+ )) do |menu|
menu.with_show_button do |button|
button.with_trailing_action_icon(icon: :"triangle-down")
end
@@ -11,7 +14,10 @@
label: t("activities.work_packages.activity_tab.label_activity_show_all"),
href: update_filter_work_package_activities_path(work_package),
content_arguments: {
- data: { "turbo-stream": true, "action": "click->work-packages--activities-tab--index#unsetFilter" }
+ data: {
+ "turbo-stream": true, "action": "click->work-packages--activities-tab--index#unsetFilter",
+ "test_selector": "op-wp-journals-filter-show-all"
+ }
},
active: show_all?
)
@@ -19,7 +25,10 @@
label: t("activities.work_packages.activity_tab.label_activity_show_only_changes"),
href: update_filter_work_package_activities_path(work_package, filter: :only_changes),
content_arguments: {
- data: { "turbo-stream": true, "action": "click->work-packages--activities-tab--index#setFilterToOnlyChanges" }
+ data: {
+ "turbo-stream": true, "action": "click->work-packages--activities-tab--index#setFilterToOnlyChanges",
+ "test_selector": "op-wp-journals-filter-show-only-changes"
+ }
},
active: show_only_changes?
)
@@ -27,7 +36,10 @@
label: t("activities.work_packages.activity_tab.label_activity_show_only_comments"),
href: update_filter_work_package_activities_path(work_package, filter: :only_comments),
content_arguments: {
- data: { "turbo-stream": true, "action": "click->work-packages--activities-tab--index#setFilterToOnlyComments" }
+ data: {
+ "turbo-stream": true, "action": "click->work-packages--activities-tab--index#setFilterToOnlyComments",
+ "test_selector": "op-wp-journals-filter-show-only-comments"
+ }
},
active: show_only_comments?
)
@@ -35,7 +47,7 @@
end
container.with_column do
render(Primer::Alpha::ActionMenu.new(select_variant: :single, dynamic_label: true)) do |menu|
- menu.with_show_button(scheme: :invisible) do |button|
+ menu.with_show_button(scheme: :invisible, data: { "test_selector": "op-wp-journals-sorting-menu" }) do |button|
button.with_trailing_action_icon(icon: :"triangle-down")
end
menu.with_item(
@@ -43,7 +55,7 @@
href: update_sorting_work_package_activities_path(work_package, sorting: :desc, filter:),
form_arguments: { method: :put },
content_arguments: {
- data: { "turbo-stream": true }
+ data: { "turbo-stream": true, "test_selector": "op-wp-journals-sorting-desc" }
},
active: desc_sorting?
)
@@ -52,7 +64,7 @@
href: update_sorting_work_package_activities_path(work_package, sorting: :asc, filter:),
form_arguments: { method: :put },
content_arguments: {
- data: { "turbo-stream": true }
+ data: { "turbo-stream": true, "test_selector": "op-wp-journals-sorting-asc" }
},
active: asc_sorting?
)
diff --git a/app/components/work_packages/activities_tab/journals/index_component.html.erb b/app/components/work_packages/activities_tab/journals/index_component.html.erb
index 6eed26bc545..78abb395ebf 100644
--- a/app/components/work_packages/activities_tab/journals/index_component.html.erb
+++ b/app/components/work_packages/activities_tab/journals/index_component.html.erb
@@ -1,6 +1,6 @@
<%=
component_wrapper do
- flex_layout(id: insert_target_modifier_id) do |journals_index_container|
+ flex_layout(id: insert_target_modifier_id, data: { "test_selector": "op-wp-journals-container" }) do |journals_index_container|
if journals_grouped_by_day.any?
journals_grouped_by_day.each do |day, journals|
journals_index_container.with_row do
diff --git a/app/components/work_packages/activities_tab/journals/item_component.html.erb b/app/components/work_packages/activities_tab/journals/item_component.html.erb
index 50613ac1021..b602ca21b9b 100644
--- a/app/components/work_packages/activities_tab/journals/item_component.html.erb
+++ b/app/components/work_packages/activities_tab/journals/item_component.html.erb
@@ -1,10 +1,13 @@
<%=
component_wrapper(data: wrapper_data_attributes, class: "work-packages-activities-tab-journals-item-component") do
- flex_layout do |journal_container|
+ flex_layout(data: { "test_selector": "op-wp-journal-entry-#{journal.id}" }) do |journal_container|
if show_comment_container?
- journal_container.with_row(classes: "comment-border-box") do
- render(border_box_container(id: "activity-#{journal.version}", padding: :condensed)) do |border_box_component|
- border_box_component.with_header(px: 2, py: 0) do
+ journal_container.with_row(classes: "journal-notes-border-box") do
+ render(border_box_container(
+ id: "activity-#{journal.version}",
+ padding: :condensed
+ )) do |border_box_component|
+ border_box_component.with_header(px: 2, py: 0, classes: "journal-notes-header") do
flex_layout(align_items: :center, justify_content: :space_between) do |header_container|
header_container.with_column(flex_layout: true) do |header_start_container|
header_start_container.with_column(mr: 2) do
@@ -66,7 +69,7 @@
end
end
end
- border_box_component.with_body do
+ border_box_component.with_body(classes: "journal-notes-body") do
content
end
end
diff --git a/app/components/work_packages/activities_tab/journals/item_component/details.html.erb b/app/components/work_packages/activities_tab/journals/item_component/details.html.erb
index 561ee79a863..5d142053342 100644
--- a/app/components/work_packages/activities_tab/journals/item_component/details.html.erb
+++ b/app/components/work_packages/activities_tab/journals/item_component/details.html.erb
@@ -1,7 +1,7 @@
<%=
component_wrapper(class: "work-packages-activities-tab-journals-item-component-details") do
if journal.details.any? && filter != :only_comments
- flex_layout(my: 0, border: :left, classes: "details-container") do |details_container|
+ flex_layout(my: 0, border: :left, classes: "journal-details-container") do |details_container|
if journal.notes.present? && filter != :only_changes
render_details(details_container)
else
@@ -11,13 +11,13 @@
end
elsif journal.details.empty?
unless filter == :only_changes
- flex_layout(my: 0, border: :left, classes: "details-container details-container--empty--#{journal_sorting}") do |details_container|
+ flex_layout(my: 0, border: :left, classes: "journal-details-container journal-details-container--empty--#{journal_sorting}") do |details_container|
# empty row to render the flex layout with its minimal height
render_empty_line(details_container)
end
end
else
- flex_layout(my: 0, border: :left, classes: "details-container details-container--empty--#{journal_sorting}") do |details_container|
+ flex_layout(my: 0, border: :left, classes: "journal-details-container journal-details-container--empty--#{journal_sorting}") do |details_container|
# empty row to render the flex layout with its minimal height
render_empty_line(details_container)
end
diff --git a/app/components/work_packages/activities_tab/journals/item_component/details.rb b/app/components/work_packages/activities_tab/journals/item_component/details.rb
index 93931b5799b..ff8a8794b64 100644
--- a/app/components/work_packages/activities_tab/journals/item_component/details.rb
+++ b/app/components/work_packages/activities_tab/journals/item_component/details.rb
@@ -54,8 +54,9 @@ module WorkPackages
def render_details_header(details_container)
details_container.with_row(flex_layout: true, align_items: :center,
- justify_content: :space_between, classes: "details-header-container") do |header_container|
- header_container.with_column(flex_layout: true, align_items: :center) do |header_start_container|
+ justify_content: :space_between, classes: "journal-details-header-container") do |header_container|
+ header_container.with_column(flex_layout: true, align_items: :center,
+ classes: "journal-details-header") do |header_start_container|
header_start_container.with_column(mr: 2, classes: "timeline-icon") do
if journal.initial?
render Primer::Beta::Octicon.new(icon: "diff-added", size: :small, "aria-label": "Add", color: :subtle)
@@ -122,9 +123,9 @@ module WorkPackages
else
journal.details.each do |detail|
details_container_inner.with_row(flex_layout: true, my: 1, align_items: :flex_start) do |detail_container|
- detail_container.with_column(classes: "detail-stem-line")
+ detail_container.with_column(classes: "journal-detail-stem-line")
detail_container.with_column(pl: 1, font_size: :small) do
- render(Primer::Beta::Text.new(classes: "detail-description")) { journal.render_detail(detail) }
+ render(Primer::Beta::Text.new(classes: "journal-detail-description")) { journal.render_detail(detail) }
end
end
end
diff --git a/app/components/work_packages/activities_tab/journals/item_component/details.sass b/app/components/work_packages/activities_tab/journals/item_component/details.sass
index d6d5884747a..c949752129e 100644
--- a/app/components/work_packages/activities_tab/journals/item_component/details.sass
+++ b/app/components/work_packages/activities_tab/journals/item_component/details.sass
@@ -1,10 +1,10 @@
.work-packages-activities-tab-journals-item-component-details
- .details-container
+ .journal-details-container
margin-left: 19px
min-height: 20px
- .details-container--empty--last--asc
+ .journal-details-container--empty--last--asc
display: none!important
- .details-header-container
+ .journal-details-header-container
margin-left: -14px
.timeline-icon
background-color: var(--bgColor-muted)
@@ -16,10 +16,10 @@
.empty-line
margin-top: 0px!important
margin-bottom: 0px!important
- .detail-stem-line
+ .journal-detail-stem-line
position: relative
width: 20px
- .detail-stem-line::before
+ .journal-detail-stem-line::before
content: ""
position: absolute
top: 10px
@@ -28,7 +28,7 @@
height: var(--borderWidth-thin, 1px)
background-color: var(--borderColor-default)
transform: translateY(-50%)
- .detail-description
+ .journal-detail-description
// quick hack to adapt the current detail rendering to desired primerised design
i
font-style: normal
diff --git a/app/components/work_packages/activities_tab/journals/new_component.html.erb b/app/components/work_packages/activities_tab/journals/new_component.html.erb
index 42ff11c03bc..267ce19a7c2 100644
--- a/app/components/work_packages/activities_tab/journals/new_component.html.erb
+++ b/app/components/work_packages/activities_tab/journals/new_component.html.erb
@@ -7,6 +7,7 @@
flex_layout(justify_content: :space_between) do |button_row|
button_row.with_column(id: "input-trigger-column", mr: 2) do
render(Primer::Beta::Button.new(
+ id: "open-work-package-journal-form",
text_align: :left,
scheme: :default,
size: :medium,
@@ -48,7 +49,8 @@
scheme: :default,
icon: :"paper-airplane",
"aria-label": t("activities.work_packages.activity_tab.label_submit_comment"),
- type: :submit
+ type: :submit,
+ data: { "test_selector": "op-submit-work-package-journal-form" }
))
end
end
diff --git a/spec/features/activities/work_package/activities_spec.rb b/spec/features/activities/work_package/activities_spec.rb
new file mode 100644
index 00000000000..5e8d0ad7ef6
--- /dev/null
+++ b/spec/features/activities/work_package/activities_spec.rb
@@ -0,0 +1,368 @@
+#-- copyright
+# OpenProject is an open source project management software.
+# Copyright (C) 2012-2024 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"
+
+RSpec.describe "Work package activity", :js, :with_cuprite do
+ let(:project) { create(:project) }
+ let(:admin) { create(:admin) }
+ let(:member_role) do
+ create(:project_role,
+ permissions: %i[view_work_packages edit_work_packages add_work_packages work_package_assigned])
+ end
+ let(:member) do
+ create(:user,
+ firstname: "A",
+ lastname: "Member",
+ member_with_roles: { project => member_role })
+ end
+
+ let(:wp_page) { Pages::FullWorkPackage.new(work_package, project) }
+ let(:activity_tab) { Components::WorkPackages::Activities.new(work_package) }
+
+ context "when a workpackage is created and visited by the same user" do
+ current_user { admin }
+ let(:work_package) { create(:work_package, project:, author: admin) }
+
+ before do
+ # for some reason the journal is set to the "Anonymous"
+ # although the work_package is created by the admin
+ # so we need to update the journal to the admin manually to simulate the real world case
+ work_package.journals.first.update!(user: admin)
+
+ wp_page.visit!
+ wp_page.wait_for_activity_tab
+ end
+
+ it "shows and merges activities and comments correctly", :aggregate_failures do
+ first_journal = work_package.journals.first
+
+ # initial journal entry is shown without changeset or comment
+ activity_tab.within_journal_entry(first_journal) do
+ activity_tab.expect_journal_details_header(text: "created")
+ activity_tab.expect_journal_details_header(text: admin.name)
+ activity_tab.expect_no_journal_notes
+ activity_tab.expect_no_journal_changed_attribute
+ end
+
+ wp_page.update_attributes(subject: "A new subject") # rubocop:disable Rails/ActiveRecordAliases
+ wp_page.expect_and_dismiss_toaster(message: "Successful update.")
+
+ # even when attributes are changed, the initial journal entry is still not showing any changeset
+ activity_tab.within_journal_entry(first_journal) do
+ activity_tab.expect_no_journal_changed_attribute
+ end
+
+ # merges the initial journal entry with the first comment when a comment is added right after the work package is created
+ activity_tab.add_comment(text: "First comment")
+
+ activity_tab.within_journal_entry(first_journal) do
+ activity_tab.expect_no_journal_details_header
+ activity_tab.expect_journal_notes_header(text: "created")
+ activity_tab.expect_journal_notes_header(text: admin.name)
+ activity_tab.expect_journal_notes(text: "First comment")
+ activity_tab.expect_no_journal_changed_attribute
+ end
+
+ # changing the work package attributes after the first comment is added
+ wp_page.update_attributes(subject: "A new subject!!!") # rubocop:disable Rails/ActiveRecordAliases
+ wp_page.expect_and_dismiss_toaster(message: "Successful update.")
+
+ # the changeset is still not shown in the journal entry
+ activity_tab.within_journal_entry(first_journal) do
+ activity_tab.expect_no_journal_changed_attribute
+ end
+
+ # adding a second comment
+ activity_tab.add_comment(text: "Second comment")
+
+ second_journal = work_package.journals.second
+
+ activity_tab.within_journal_entry(second_journal) do
+ activity_tab.expect_no_journal_changed_attribute
+ end
+
+ # changing the work package attributes after the first comment is added
+ wp_page.update_attributes(subject: "A new subject") # rubocop:disable Rails/ActiveRecordAliases
+ wp_page.expect_and_dismiss_toaster(message: "Successful update.")
+
+ # the changeset is shown for the second journal entry (all but initial)
+ activity_tab.within_journal_entry(second_journal) do
+ activity_tab.expect_journal_changed_attribute(text: "Subject")
+ end
+
+ wp_page.update_attributes(assignee: member.name) # rubocop:disable Rails/ActiveRecordAliases
+ wp_page.expect_and_dismiss_toaster(message: "Successful update.")
+
+ # the changeset is merged for the second journal entry
+ activity_tab.within_journal_entry(second_journal) do
+ activity_tab.expect_journal_changed_attribute(text: "Subject")
+ activity_tab.expect_journal_changed_attribute(text: "Assignee")
+ end
+ end
+ end
+
+ context "when a workpackage is created and visited by different users" do
+ current_user { member }
+ let(:work_package) { create(:work_package, project:, author: admin) }
+
+ before do
+ # for some reason the journal is set to the "Anonymous"
+ # although the work_package is created by the admin
+ # so we need to update the journal to the admin manually to simulate the real world case
+ work_package.journals.first.update!(user: admin)
+
+ wp_page.visit!
+ wp_page.wait_for_activity_tab
+ end
+
+ it "shows and merges activities and comments correctly", :aggregate_failures do
+ first_journal = work_package.journals.first
+
+ # initial journal entry is shown without changeset or comment
+ activity_tab.within_journal_entry(first_journal) do
+ activity_tab.expect_journal_details_header(text: "created")
+ activity_tab.expect_journal_details_header(text: admin.name)
+ activity_tab.expect_no_journal_notes
+ activity_tab.expect_no_journal_changed_attribute
+ end
+
+ wp_page.update_attributes(subject: "A new subject") # rubocop:disable Rails/ActiveRecordAliases
+ wp_page.expect_and_dismiss_toaster(message: "Successful update.")
+
+ second_journal = work_package.journals.second
+ # even when attributes are changed, the initial journal entry is still not showing any changeset
+ activity_tab.within_journal_entry(second_journal) do
+ activity_tab.expect_journal_details_header(text: "change")
+ activity_tab.expect_journal_details_header(text: member.name)
+ activity_tab.expect_journal_changed_attribute(text: "Subject")
+ end
+
+ # merges the second journal entry with the comment made by the user right afterwards
+ activity_tab.add_comment(text: "First comment")
+
+ activity_tab.within_journal_entry(second_journal) do
+ activity_tab.expect_no_journal_details_header
+ activity_tab.expect_journal_notes_header(text: "commented")
+ activity_tab.expect_journal_notes_header(text: member.name)
+ activity_tab.expect_journal_notes(text: "First comment")
+ end
+
+ travel_to 1.hour.from_now
+
+ # the journals will not be merged due to the time difference
+
+ wp_page.update_attributes(subject: "A new subject!!!") # rubocop:disable Rails/ActiveRecordAliases
+
+ third_journal = work_package.journals.third
+
+ activity_tab.within_journal_entry(third_journal) do
+ activity_tab.expect_journal_details_header(text: "change")
+ activity_tab.expect_journal_details_header(text: member.name)
+ activity_tab.expect_journal_changed_attribute(text: "Subject")
+ end
+ end
+ end
+
+ context "when multiple users are commenting on a workpackage" do
+ current_user { admin }
+ let(:work_package) { create(:work_package, project:, author: admin) }
+
+ before do
+ # set WORK_PACKAGES_ACTIVITIES_TAB_POLLING_INTERVAL_IN_MS to 1000
+ # to speed up the polling interval for test duration
+ ENV["WORK_PACKAGES_ACTIVITIES_TAB_POLLING_INTERVAL_IN_MS"] = "1000"
+
+ # for some reason the journal is set to the "Anonymous"
+ # although the work_package is created by the admin
+ # so we need to update the journal to the admin manually to simulate the real world case
+ work_package.journals.first.update!(user: admin)
+
+ wp_page.visit!
+ wp_page.wait_for_activity_tab
+ end
+
+ after do
+ ENV.delete("WORK_PACKAGES_ACTIVITIES_TAB_POLLING_INTERVAL_IN_MS")
+ end
+
+ it "shows the comment of another user without browser reload", :aggregate_failures do
+ # simulate member creating a comment
+ sleep 1 # the comment needs to be created after the component is mounted
+ first_journal = create(:work_package_journal, user: member, notes: "First comment by member", journable: work_package,
+ version: 2)
+
+ # the comment is shown without browser reload
+ activity_tab.expect_journal_notes(text: "First comment by member")
+
+ # simulate comments made within the polling interval
+ create(:work_package_journal, user: member, notes: "Second comment by member", journable: work_package, version: 3)
+ create(:work_package_journal, user: member, notes: "Third comment by member", journable: work_package, version: 4)
+
+ activity_tab.add_comment(text: "First comment by admin")
+
+ expect(activity_tab.get_all_comments_as_arrary).to eq([
+ "First comment by member",
+ "Second comment by member",
+ "Third comment by member",
+ "First comment by admin"
+ ])
+
+ first_journal.update!(notes: "First comment by member updated")
+
+ # properly updates the comment when the comment is updated
+ activity_tab.expect_journal_notes(text: "First comment by member updated")
+ end
+ end
+
+ describe "filtering" do
+ current_user { admin }
+ let(:work_package) { create(:work_package, project:, author: admin) }
+
+ before do
+ # for some reason the journal is set to the "Anonymous"
+ # although the work_package is created by the admin
+ # so we need to update the journal to the admin manually to simulate the real world case
+ work_package.journals.first.update!(user: admin)
+
+ create(:work_package_journal, user: admin, notes: "First comment by admin", journable: work_package, version: 2)
+ create(:work_package_journal, user: admin, notes: "Second comment by admin", journable: work_package, version: 3)
+
+ wp_page.visit!
+ wp_page.wait_for_activity_tab
+ end
+
+ it "filters the activities based on type", :aggregate_failures do
+ # add a non-comment journal entry by changing the work package attributes
+ wp_page.update_attributes(subject: "A new subject") # rubocop:disable Rails/ActiveRecordAliases
+ wp_page.expect_and_dismiss_toaster(message: "Successful update.")
+
+ # expect all journal entries
+ activity_tab.expect_journal_notes(text: "First comment by admin")
+ activity_tab.expect_journal_notes(text: "Second comment by admin")
+ activity_tab.expect_journal_changed_attribute(text: "Subject")
+
+ activity_tab.filter_journals(:only_comments)
+
+ # expect only the comments
+ activity_tab.expect_journal_notes(text: "First comment by admin")
+ activity_tab.expect_journal_notes(text: "Second comment by admin")
+ activity_tab.expect_no_journal_changed_attribute(text: "Subject")
+
+ activity_tab.filter_journals(:only_changes)
+
+ # expect only the changes
+ activity_tab.expect_no_journal_notes(text: "First comment by admin")
+ activity_tab.expect_no_journal_notes(text: "Second comment by admin")
+ activity_tab.expect_journal_changed_attribute(text: "Subject")
+
+ activity_tab.filter_journals(:all)
+
+ # expect all journal entries
+ activity_tab.expect_journal_notes(text: "First comment by admin")
+ activity_tab.expect_journal_notes(text: "Second comment by admin")
+ activity_tab.expect_journal_changed_attribute(text: "Subject")
+
+ # strip journal entries with comments and changesets down to the comments
+
+ # creating a journal entry with both a comment and a changeset
+ activity_tab.add_comment(text: "Third comment by admin")
+ wp_page.update_attributes(subject: "A new subject!!!") # rubocop:disable Rails/ActiveRecordAliases
+ wp_page.expect_and_dismiss_toaster(message: "Successful update.")
+
+ latest_journal = work_package.journals.last
+
+ activity_tab.within_journal_entry(latest_journal) do
+ activity_tab.expect_journal_notes_header(text: "commented")
+ activity_tab.expect_journal_notes_header(text: admin.name)
+ activity_tab.expect_journal_notes(text: "Third comment by admin")
+ activity_tab.expect_journal_changed_attribute(text: "Subject")
+ activity_tab.expect_no_journal_details_header
+ end
+
+ activity_tab.filter_journals(:only_comments)
+
+ activity_tab.within_journal_entry(latest_journal) do
+ activity_tab.expect_journal_notes_header(text: "commented")
+ activity_tab.expect_journal_notes_header(text: admin.name)
+ activity_tab.expect_journal_notes(text: "Third comment by admin")
+ activity_tab.expect_no_journal_changed_attribute
+ activity_tab.expect_no_journal_details_header
+ end
+
+ activity_tab.filter_journals(:only_changes)
+
+ activity_tab.within_journal_entry(latest_journal) do
+ activity_tab.expect_no_journal_notes_header
+ activity_tab.expect_no_journal_notes
+ activity_tab.expect_journal_details_header(text: "change")
+ activity_tab.expect_journal_details_header(text: admin.name)
+ activity_tab.expect_journal_changed_attribute(text: "Subject")
+ end
+ end
+ end
+
+ describe "sorting" do
+ current_user { admin }
+ let(:work_package) { create(:work_package, project:, author: admin) }
+
+ before do
+ # for some reason the journal is set to the "Anonymous"
+ # although the work_package is created by the admin
+ # so we need to update the journal to the admin manually to simulate the real world case
+ work_package.journals.first.update!(user: admin)
+
+ create(:work_package_journal, user: admin, notes: "First comment by admin", journable: work_package, version: 2)
+ create(:work_package_journal, user: admin, notes: "Second comment by admin", journable: work_package, version: 3)
+
+ wp_page.visit!
+ wp_page.wait_for_activity_tab
+ end
+
+ it "sorts the activities based on the sorting preference", :aggregate_failures do
+ # expect the default sorting to be asc
+ expect(activity_tab.get_all_comments_as_arrary).to eq([
+ "First comment by admin",
+ "Second comment by admin"
+ ])
+ activity_tab.set_journal_sorting(:desc)
+
+ expect(activity_tab.get_all_comments_as_arrary).to eq([
+ "Second comment by admin",
+ "First comment by admin"
+ ])
+
+ activity_tab.set_journal_sorting(:asc)
+
+ expect(activity_tab.get_all_comments_as_arrary).to eq([
+ "First comment by admin",
+ "Second comment by admin"
+ ])
+ end
+ end
+end
diff --git a/spec/support/components/work_packages/activities.rb b/spec/support/components/work_packages/activities.rb
index 0757b07b1da..e62a1a52c8c 100644
--- a/spec/support/components/work_packages/activities.rb
+++ b/spec/support/components/work_packages/activities.rb
@@ -68,6 +68,96 @@ module Components
end
end
end
+
+ # helpers for new primerized activities
+
+ def within_journal_entry(journal, &)
+ page.within_test_selector("op-wp-journal-entry-#{journal.id}", &)
+ end
+
+ def expect_journal_changed_attribute(text:)
+ expect(page).to have_css(".journal-detail-description", text:)
+ end
+
+ def expect_no_journal_changed_attribute(text: nil)
+ expect(page).to have_no_css(".journal-detail-description", text:)
+ end
+
+ def expect_no_journal_notes(text: nil)
+ expect(page).to have_no_css(".journal-notes-body", text:)
+ end
+
+ def expect_journal_details_header(text: nil)
+ expect(page).to have_css(".journal-details-header", text:)
+ end
+
+ def expect_no_journal_details_header(text: nil)
+ expect(page).to have_no_css(".journal-details-header", text:)
+ end
+
+ def expect_journal_notes_header(text: nil)
+ expect(page).to have_css(".journal-notes-header", text:)
+ end
+
+ def expect_no_journal_notes_header(text: nil)
+ expect(page).to have_no_css(".journal-notes-header", text:)
+ end
+
+ def expect_journal_notes(text: nil)
+ expect(page).to have_css(".journal-notes-body", text:)
+ end
+
+ def add_comment(text: nil)
+ # TODO: get rid of static sleep
+ sleep 1 # otherwise the stimulus component is not mounted yet and the click does not work
+
+ if page.has_css?("#open-work-package-journal-form")
+ page.find_by_id("open-work-package-journal-form").click
+ else
+ expect(page).to have_css("#work-package-journal-form")
+ end
+
+ within("#work-package-journal-form") do
+ FormFields::Primerized::EditorFormField.new("notes", selector: "#work-package-journal-form").set_value(text)
+ page.find_test_selector("op-submit-work-package-journal-form").click
+ end
+
+ page.within_test_selector("op-wp-journals-container") do
+ expect(page).to have_text(text)
+ end
+ end
+
+ def get_all_comments_as_arrary
+ page.all(".journal-notes-body").map(&:text)
+ end
+
+ def filter_journals(filter)
+ page.find_test_selector("op-wp-journals-filter-menu").click
+
+ case filter
+ when :all
+ page.find_test_selector("op-wp-journals-filter-show-all").click
+ when :only_comments
+ page.find_test_selector("op-wp-journals-filter-show-only-comments").click
+ when :only_changes
+ page.find_test_selector("op-wp-journals-filter-show-only-changes").click
+ end
+
+ sleep 1 # wait for the journals to be reloaded, TODO: get rid of static sleep
+ end
+
+ def set_journal_sorting(sorting)
+ page.find_test_selector("op-wp-journals-sorting-menu").click
+
+ case sorting
+ when :asc
+ page.find_test_selector("op-wp-journals-sorting-asc").click
+ when :desc
+ page.find_test_selector("op-wp-journals-sorting-desc").click
+ end
+
+ sleep 1 # wait for the journals to be reloaded, TODO: get rid of static sleep
+ end
end
end
end
diff --git a/spec/support/pages/work_packages/full_work_package.rb b/spec/support/pages/work_packages/full_work_package.rb
index a235fc0bead..4dfc2239fd6 100644
--- a/spec/support/pages/work_packages/full_work_package.rb
+++ b/spec/support/pages/work_packages/full_work_package.rb
@@ -56,6 +56,10 @@ module Pages
end
end
+ def wait_for_activity_tab
+ expect(page).to have_test_selector("op-wp-activity-tab", wait: 10)
+ end
+
private
def container