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
Ruby agile-developmentangularbcfboardsbug-trackerganttgantt-chartifcissue-trackerjira-alternativekanbanopenprojectproduct-managementproject-managementproject-planningroadmaprubyscrumtimelineworkflows
feat[Op#40437]: Introduce view only reactions covered by feature specs
Kabiru Mwenjaa3d0747f4015
diff --git a/app/components/_index.sass b/app/components/_index.sassindex 5b9080f6180..2590c3e4edd 100644--- a/app/components/_index.sass+++ b/app/components/_index.sass@@ -3,6 +3,7 @@@import "work_packages/activities_tab/journals/index_component"@import "work_packages/activities_tab/journals/item_component"@import "work_packages/activities_tab/journals/item_component/details"+@import "work_packages/activities_tab/journals/item_component/reactions"@import "shares/modal_body_component"@import "shares/invite_user_form_component"@import "work_packages/details/tab_component"diff --git a/app/components/work_packages/activities_tab/journals/item_component/add_reactions.html.erb b/app/components/work_packages/activities_tab/journals/item_component/add_reactions.html.erbindex 00410f2c9b3..0161d7998a1 100644--- a/app/components/work_packages/activities_tab/journals/item_component/add_reactions.html.erb+++ b/app/components/work_packages/activities_tab/journals/item_component/add_reactions.html.erb@@ -12,7 +12,7 @@"aria-label": I18n.t("reactions.add_reaction"),title: I18n.t("reactions.add_reaction"),mr: 2,- test_selector: "add-reaction-button"+ test_selector: "add-reactions-button")d.with_body(pt: 2) dodiff --git a/app/components/work_packages/activities_tab/journals/item_component/add_reactions.rb b/app/components/work_packages/activities_tab/journals/item_component/add_reactions.rbindex 07196599919..17bf05d501e 100644--- a/app/components/work_packages/activities_tab/journals/item_component/add_reactions.rb+++ b/app/components/work_packages/activities_tab/journals/item_component/add_reactions.rb@@ -40,13 +40,16 @@ module WorkPackages@journal = journalend+ def render?+ User.current.allowed_in_work_package?(:add_work_package_notes, work_package)+ end+privateattr_reader :journal- def wrapper_uniq_by- journal.id- end+ def work_package = journal.journable+ def wrapper_uniq_by = journal.idendendenddiff --git a/app/components/work_packages/activities_tab/journals/item_component/reactions.html.erb b/app/components/work_packages/activities_tab/journals/item_component/reactions.html.erbindex 289f6a65d01..187240412d0 100644--- a/app/components/work_packages/activities_tab/journals/item_component/reactions.html.erb+++ b/app/components/work_packages/activities_tab/journals/item_component/reactions.html.erb@@ -8,10 +8,13 @@scheme: button_scheme(data[:users]),color: :default,bg: counter_color(data[:users]),- id: "#{journal.id}-#{emoji}",+ id: "#{journal.id}-#{emoji_alias(emoji)}",+ test_selector: "reaction-#{emoji_alias(emoji)}",tag: :a,- href: toggle_reaction_work_package_activity_path(journal.journable.id, id: journal.id, emoji: emoji),- data: { "turbo-stream": true, "turbo-method": :put }+ href: href(emoji:),+ data: { turbo_stream: true, turbo_method: :put },+ disabled: current_user_cannot_react?,+ classes: 'op-reactions-button')) do |button|button.with_tooltip(text: tooltip_text(emoji, data[:users]))"#{emoji} #{data[:count]}".html_safediff --git a/app/components/work_packages/activities_tab/journals/item_component/reactions.rb b/app/components/work_packages/activities_tab/journals/item_component/reactions.rbindex 537c5d7f887..d92d41617a2 100644--- a/app/components/work_packages/activities_tab/journals/item_component/reactions.rb+++ b/app/components/work_packages/activities_tab/journals/item_component/reactions.rb@@ -48,6 +48,8 @@ module WorkPackagesjournal.idend+ def work_package = journal.journable+def reacted_by_current_user?(users)users.any? { |u| u[:id] == User.current.id }end@@ -80,6 +82,22 @@ module WorkPackagesresult += I18n.t("reactions.reacted_with", emoji_shortcode: EmojiReaction.shortcode(emoji))resultend++ def href(emoji:)+ return if current_user_cannot_react?++ toggle_reaction_work_package_activity_path(journal.journable.id, id: journal.id, emoji:)+ end++ def emoji_alias(emoji)+ EmojiReaction::EMOJI_MAP.invert[emoji].to_s+ end++ def current_user_can_react?+ User.current.allowed_in_work_package?(:add_work_package_notes, work_package)+ end++ def current_user_cannot_react? = !current_user_can_react?endendenddiff --git a/app/components/work_packages/activities_tab/journals/item_component/reactions.sass b/app/components/work_packages/activities_tab/journals/item_component/reactions.sassnew file mode 100644index 00000000000..f89b8bf5371--- /dev/null+++ b/app/components/work_packages/activities_tab/journals/item_component/reactions.sass@@ -0,0 +1,2 @@+.op-reactions-button:disabled+ cursor: defaultdiff --git a/spec/factories/emoji_reactions_factory.rb b/spec/factories/emoji_reactions_factory.rbnew file mode 100644index 00000000000..56800b9a8e4--- /dev/null+++ b/spec/factories/emoji_reactions_factory.rb@@ -0,0 +1,39 @@+#-- 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.+#++++FactoryBot.define do+ factory :emoji_reaction do+ transient do+ emoji_alias { EmojiReaction::EMOJI_MAP.keys.sample }+ end++ user+ emoji { EmojiReaction::EMOJI_MAP[emoji_alias] }+ reactable factory: :work_package_journal+ end+enddiff --git a/spec/features/activities/work_package/emoji_reactions_spec.rb b/spec/features/activities/work_package/emoji_reactions_spec.rbindex 08003ebc33f..d1f8a620434 100644--- a/spec/features/activities/work_package/emoji_reactions_spec.rb+++ b/spec/features/activities/work_package/emoji_reactions_spec.rb@@ -36,6 +36,7 @@ RSpec.describe "Emoji reactions on work package activity", :js, :with_cuprite,let(:viewer) { create_user_with_view_work_packages_permission }let(:viewer_with_commenting_permission) { create_user_with_view_and_commenting_permission }+ let(:work_package) { create(:work_package, project:, author: admin) }let(:first_comment) docreate(:work_package_journal, user: admin, notes: "First comment by admin", journable: work_package,version: 2)@@ -54,18 +55,87 @@ RSpec.describe "Emoji reactions on work package activity", :js, :with_cuprite,before dofirst_comment+ create(:emoji_reaction, user: admin, reactable: first_comment, emoji_alias: :thumbs_down)++ wp_page.visit!+ wp_page.wait_for_activity_tab+ end++ it "can add emoji reactions and remove own reactions" do+ activity_tab.add_first_emoji_reaction_for_journal(first_comment, "👍")+ activity_tab.add_emoji_reaction_for_journal(first_comment, "👎")+ activity_tab.expect_emoji_reactions_for_journal(first_comment, "👍" => 1, "👎" => 2)++ activity_tab.remove_emoji_reaction_for_journal(first_comment, "👎")+ activity_tab.expect_emoji_reactions_for_journal(first_comment, "👍" => 1, "👎" => 1)+ end+ end++ context "when user only has `view_work_packages` permissions" do+ current_user { viewer }++ before do+ first_comment++ create(:emoji_reaction, user: admin, reactable: first_comment, emoji_alias: :thumbs_down)++ wp_page.visit!+ wp_page.wait_for_activity_tab+ end++ it "cannot add an emoji reactions but can view emoji reactions by other users" do+ activity_tab.expect_no_add_reactions_button++ activity_tab.expect_emoji_reactions_for_journal(first_comment, "👎" => { count: 1, disabled: true })+ end+ end++ context "when a user has `add_work_package_notes` and `edit_own_work_package_notes` permission" do+ current_user { viewer_with_commenting_permission }++ before do+ first_comment++ create(:emoji_reaction, user: admin, reactable: first_comment, emoji_alias: :rocket)+wp_page.visit!wp_page.wait_for_activity_tabend- it "can add an emoji reactions" do- activity_tab.can_add_emoji_reaction_for_journal(first_comment, "👍")+ it "can add emoji reactions and remove own reactions" do+ activity_tab.add_first_emoji_reaction_for_journal(first_comment, "😄")+ activity_tab.add_emoji_reaction_for_journal(first_comment, "🚀")+ activity_tab.expect_emoji_reactions_for_journal(first_comment, "😄" => 1, "🚀" => 2)++ activity_tab.remove_emoji_reaction_for_journal(first_comment, "🚀")+ activity_tab.expect_emoji_reactions_for_journal(first_comment, "😄" => 1, "🚀" => 1)endend- context "when user only has `view_work_packages` permissions"- context "when a user has `add_work_package_notes` and `edit_own_work_package_notes` permission"- context "with anonymouse user"+ context "when project is public", with_settings: { login_required: false } do+ let(:project) { create(:project, public: true) }+ let!(:anonymous_role) do+ create(:anonymous_role, permissions: %i[view_project view_work_packages])+ end++ context "when visited by an anonymous visitor" do+ before do+ first_comment+ create(:emoji_reaction, user: admin, reactable: first_comment, emoji_alias: :party_popper)++ login_as User.anonymous++ wp_page.visit!+ wp_page.wait_for_activity_tab+ end++ it "cannot add an emoji reactions but can view emoji reactions by other users" do+ activity_tab.expect_no_add_reactions_button++ activity_tab.expect_emoji_reactions_for_journal(first_comment, "🎉" => { count: 1, disabled: true })+ end+ end+ enddef create_user_as_project_membermember_role = create(:project_role,diff --git a/spec/support/components/work_packages/emoji_reactions.rb b/spec/support/components/work_packages/emoji_reactions.rbindex 5d4ab44134f..75afde01a65 100644--- a/spec/support/components/work_packages/emoji_reactions.rb+++ b/spec/support/components/work_packages/emoji_reactions.rb@@ -29,16 +29,22 @@module Componentsmodule WorkPackagesclass EmojiReactions < Activities- def can_add_emoji_reaction_for_journal(journal, emoji, expected_emoji_count: 1)+ def add_first_emoji_reaction_for_journal(journal, emoji)within_journal_entry(journal) doclick_on "Add reaction"click_on emoji+ end+ end+ def toggle_emoji_reaction_for_journal(journal, emoji)+ within_journal_entry(journal) dopage.within_test_selector("emoji-reactions") do- expect(page).to have_text("#{emoji} #{expected_emoji_count}")+ click_on emojiendendend+ alias add_emoji_reaction_for_journal toggle_emoji_reaction_for_journal+ alias remove_emoji_reaction_for_journal toggle_emoji_reaction_for_journaldef can_remove_emoji_reaction_for_journal(journal, emoji)within_journal_entry(journal) do@@ -49,6 +55,25 @@ module Componentsendend+ def expect_emoji_reactions_for_journal(journal, emojis_with_expected_options)+ within_journal_entry(journal) do+ page.within_test_selector("emoji-reactions") do+ emojis_with_expected_options.each do |emoji, expected_emoji_options|+ case expected_emoji_options+ when Integer+ expected_emoji_count = expected_emoji_options+ capybara_options = {}+ when Hash+ expected_emoji_count = expected_emoji_options[:count]+ capybara_options = expected_emoji_options.except(:count)+ end++ expect(page).to have_selector(:link_or_button, text: "#{emoji} #{expected_emoji_count}", **capybara_options)+ end+ end+ end+ end+def expect_add_reactions_buttonexpect(page).to have_test_selector("add-reactions-button")end