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

refactor project attributes activity feature spec

Ivan Kuchin4eb8c44a2993
diff --git a/spec/features/activities/project_attributes_activity_spec.rb b/spec/features/activities/project_attributes_activity_spec.rb
index 329490826d6..8877fb52538 100644
--- a/spec/features/activities/project_attributes_activity_spec.rb
+++ b/spec/features/activities/project_attributes_activity_spec.rb
@@ -88,96 +88,101 @@ RSpec.describe "Project attributes activity", :js do
project.update!(new_project_attributes)
end
- it "tracks the projects activities" do
- previous_project_attributes = project.attributes.dup
- generate_trackable_activity_on_project(project)
-
- visit project_activity_index_path(project)
-
- check "Project details"
-
- click_on "Apply"
-
- within("li.op-activity-list--item", match: :first) do
- expect(page)
- .to have_link("Project: #{project.name}")
-
- # own fields
- expect(page).to have_css("li", text: "Name changed from #{previous_project_attributes['name']} to #{project.name}")
- expect(page).to have_css("li", text: "Description set (Details)")
- expect(page).to have_css("li", text: "Project status set to On track")
- expect(page).to have_css("li", text: "Project status description set (Details)")
- expect(page).to have_css("li", text: "Visibility set to public")
- expect(page).to have_css("li", text: "No longer subproject of #{parent_project.name}")
- expect(page).to have_css("li", text: "Project unarchived")
- expect(page).to have_css("li", text: "Identifier changed from #{previous_project_attributes['identifier']} " \
- "to #{project.identifier}")
- expect(page).to have_css("li", text: "Project marked as template")
-
- # custom fields
- expect(page).to have_css("li", text: "#{list_project_custom_field.name} " \
- "set to #{project.send(list_project_custom_field.attribute_getter)}")
- expect(page).to have_css("li", text: "#{version_project_custom_field.name} " \
- "set to #{old_version[project].name}, #{next_version[project].name}")
- expect(page).to have_css("li", text: "#{bool_project_custom_field.name} set to Yes")
- expect(page).to have_css("li", text: "#{user_project_custom_field.name} set to #{current_user.name}")
- expect(page).to have_css("li", text: "#{int_project_custom_field.name} set to 42")
- expect(page).to have_css("li", text: "#{float_project_custom_field.name} set to 3.14159")
- expect(page).to have_css("li", text: "#{text_project_custom_field.name} set (Details)")
- expect(page).to have_css("li", text: "#{string_project_custom_field.name} set to a new string CF value")
- expect(page).to have_css("li", text: "#{date_project_custom_field.name} set to 01/31/2023")
+ describe "the project activities page" do
+ let(:activity_page) { Pages::Projects::Activity.new(project) }
+
+ let!(:project_was) { project.dup }
+
+ before do
+ generate_trackable_activity_on_project(project)
+ end
+
+ it "tracks the projects activities" do
+ activity_page.visit!
+
+ activity_page.show_details
+
+ activity_page.within_journal(number: 1) do
+ activity_page.expect_link_to_project(project)
+
+ # own fields
+ activity_page.expect_activity("Name changed from #{project_was.name} to #{project.name}")
+ activity_page.expect_activity("Description set (Details)")
+ activity_page.expect_activity("Project status set to On track")
+ activity_page.expect_activity("Project status description set (Details)")
+ activity_page.expect_activity("Visibility set to public")
+ activity_page.expect_activity("No longer subproject of #{parent_project.name}")
+ activity_page.expect_activity("Project unarchived")
+ activity_page.expect_activity("Identifier changed from #{project_was.identifier} " \
+ "to #{project.identifier}")
+ activity_page.expect_activity("Project marked as template")
+
+ # custom fields
+ activity_page.expect_activity("#{list_project_custom_field.name} " \
+ "set to #{project.send(list_project_custom_field.attribute_getter)}")
+ activity_page.expect_activity("#{version_project_custom_field.name} " \
+ "set to #{old_version[project].name}, #{next_version[project].name}")
+ activity_page.expect_activity("#{bool_project_custom_field.name} set to Yes")
+ activity_page.expect_activity("#{user_project_custom_field.name} set to #{current_user.name}")
+ activity_page.expect_activity("#{int_project_custom_field.name} set to 42")
+ activity_page.expect_activity("#{float_project_custom_field.name} set to 3.14159")
+ activity_page.expect_activity("#{text_project_custom_field.name} set (Details)")
+ activity_page.expect_activity("#{string_project_custom_field.name} set to a new string CF value")
+ activity_page.expect_activity("#{date_project_custom_field.name} set to 01/31/2023")
+ end
end
end
describe "the general activities page" do
- it "is expected to not show disabled attribute only on the project it was disabled on" do
- previous_project_attributes = project.attributes.dup
+ let(:activity_page) { Pages::Activity.new }
+
+ let!(:project_was) { project.dup }
+
+ before do
generate_trackable_activity_on_project(project)
generate_trackable_activity_on_project(project2)
# Disable all custom fields on the project
project.project_custom_field_project_mappings.destroy_all
+ end
- visit activity_index_path
-
- check "Project details"
+ it "is expected to not show disabled attribute only on the project it was disabled on" do
+ activity_page.visit!
- click_on "Apply"
+ activity_page.show_details
- within("li.op-activity-list--item:nth-child(2)") do
- expect(page)
- .to have_link("Project: #{project.name}")
+ activity_page.within_journal(number: 2) do
+ activity_page.expect_link_to_project(project)
# own fields
- expect(page).to have_css("li", text: "Name changed from #{previous_project_attributes['name']} to #{project.name}")
- expect(page).to have_css("li", text: "Description set (Details)")
- expect(page).to have_css("li", text: "Project status set to On track")
- expect(page).to have_css("li", text: "Project status description set (Details)")
- expect(page).to have_css("li", text: "Visibility set to public")
- expect(page).to have_css("li", text: "No longer subproject of #{parent_project.name}")
- expect(page).to have_css("li", text: "Project unarchived")
- expect(page).to have_css("li", text: "Identifier changed from #{previous_project_attributes['identifier']} " \
- "to #{project.identifier}")
- expect(page).to have_css("li", text: "Project marked as template")
+ activity_page.expect_activity("Name changed from #{project_was.name} to #{project.name}")
+ activity_page.expect_activity("Description set (Details)")
+ activity_page.expect_activity("Project status set to On track")
+ activity_page.expect_activity("Project status description set (Details)")
+ activity_page.expect_activity("Visibility set to public")
+ activity_page.expect_activity("No longer subproject of #{parent_project.name}")
+ activity_page.expect_activity("Project unarchived")
+ activity_page.expect_activity("Identifier changed from #{project_was.identifier} " \
+ "to #{project.identifier}")
+ activity_page.expect_activity("Project marked as template")
# custom fields
- expect(page).to have_no_css("li", text: "#{list_project_custom_field.name} " \
- "set to #{project.send(list_project_custom_field.attribute_getter)}")
- expect(page).to have_no_css("li", text: "#{version_project_custom_field.name} " \
- "set to #{old_version[project].name}, #{next_version[project].name}")
- expect(page).to have_no_css("li", text: "#{bool_project_custom_field.name} set to Yes")
- expect(page).to have_no_css("li", text: "#{user_project_custom_field.name} set to #{current_user.name}")
- expect(page).to have_no_css("li", text: "#{int_project_custom_field.name} set to 42")
- expect(page).to have_no_css("li", text: "#{float_project_custom_field.name} set to 3.14159")
- expect(page).to have_no_css("li", text: "#{text_project_custom_field.name} set to\na new text CF value")
- expect(page).to have_no_css("li", text: "#{string_project_custom_field.name} set to a new string CF value")
- expect(page).to have_no_css("li", text: "#{date_project_custom_field.name} set to 01/31/2023")
+ activity_page.expect_no_activity("#{list_project_custom_field.name} " \
+ "set to #{project.send(list_project_custom_field.attribute_getter)}")
+ activity_page.expect_no_activity("#{version_project_custom_field.name} " \
+ "set to #{old_version[project].name}, #{next_version[project].name}")
+ activity_page.expect_no_activity("#{bool_project_custom_field.name} set to Yes")
+ activity_page.expect_no_activity("#{user_project_custom_field.name} set to #{current_user.name}")
+ activity_page.expect_no_activity("#{int_project_custom_field.name} set to 42")
+ activity_page.expect_no_activity("#{float_project_custom_field.name} set to 3.14159")
+ activity_page.expect_no_activity("#{text_project_custom_field.name} set to\na new text CF value")
+ activity_page.expect_no_activity("#{string_project_custom_field.name} set to a new string CF value")
+ activity_page.expect_no_activity("#{date_project_custom_field.name} set to 01/31/2023")
end
- within("li.op-activity-list--item:nth-child(1)") do
- expect(page)
- .to have_link("Project: #{project2.name}")
+ activity_page.within_journal(number: 1) do
+ activity_page.expect_link_to_project(project2)
- expect(page).to have_css("li", text: "#{int_project_custom_field.name} set to 42")
+ activity_page.expect_activity("#{int_project_custom_field.name} set to 42")
end
end
end
diff --git a/spec/support/pages/activity.rb b/spec/support/pages/activity.rb
new file mode 100644
index 00000000000..9811bb9300d
--- /dev/null
+++ b/spec/support/pages/activity.rb
@@ -0,0 +1,63 @@
+# frozen_string_literal: true
+
+# -- copyright
+# OpenProject is an open source project management software.
+# Copyright (C) 2010-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 "support/pages/page"
+
+module Pages
+ class Activity < Pages::Page
+ def path
+ activity_index_path
+ end
+
+ def show_details
+ within "#activity_menu" do
+ check "Project details"
+
+ click_on "Apply"
+ end
+ end
+
+ def within_journal(number:, &)
+ within("li.op-activity-list--item:nth-child(#{number})", &)
+ end
+
+ def expect_link_to_project(project)
+ expect(page).to have_link("Project: #{project.name}", href: project_path(project))
+ end
+
+ def expect_activity(text)
+ expect(page).to have_css("li", text:)
+ end
+
+ def expect_no_activity(text)
+ expect(page).to have_no_css("li", text:)
+ end
+ end
+end
diff --git a/spec/support/pages/projects/activity.rb b/spec/support/pages/projects/activity.rb
new file mode 100644
index 00000000000..e1ed7ba2948
--- /dev/null
+++ b/spec/support/pages/projects/activity.rb
@@ -0,0 +1,49 @@
+# frozen_string_literal: true
+
+# -- copyright
+# OpenProject is an open source project management software.
+# Copyright (C) 2010-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 "support/pages/page"
+
+module Pages
+ module Projects
+ class Activity < Pages::Activity
+ attr_reader :project
+
+ def initialize(project)
+ super()
+
+ @project = project
+ end
+
+ def path
+ project_activity_index_path(project)
+ end
+ end
+ end
+end