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
Add feature spec to test for presence of icon
Oliver Günther5856dc733167
diff --git a/frontend/src/app/features/work-packages/routing/wp-view-base/view-services/wp-view-timestamps.service.ts b/frontend/src/app/features/work-packages/routing/wp-view-base/view-services/wp-view-timestamps.service.tsindex 4a71c2f8bd9..f570aa5f71e 100644--- a/frontend/src/app/features/work-packages/routing/wp-view-base/view-services/wp-view-timestamps.service.ts+++ b/frontend/src/app/features/work-packages/routing/wp-view-base/view-services/wp-view-timestamps.service.ts@@ -32,6 +32,7 @@ import { IsolatedQuerySpace } from 'core-app/features/work-packages/directives/qimport { States } from 'core-app/core/states/states.service';import { PathHelperService } from 'core-app/core/path-helper/path-helper.service';import { WorkPackageQueryStateService } from './wp-view-base.service';+import { ConfigurationService } from 'core-app/core/config/configuration.service';export const DEFAULT_TIMESTAMP = 'PT0S';@@ -41,11 +42,16 @@ export class WorkPackageViewTimestampsService extends WorkPackageQueryStateServiprotected readonly states:States,protected readonly querySpace:IsolatedQuerySpace,protected readonly pathHelper:PathHelperService,+ protected readonly configurationService:ConfigurationService,) {super(querySpace);}public isActive():boolean {+ if (!this.configurationService.activeFeatureFlags.includes('showChanges')) {+ return false;+ }+return this.current.length >= 1 && this.current[0] !== DEFAULT_TIMESTAMP;}diff --git a/spec/features/work_packages/table/timestamps/timestamps_rendering_spec.rb b/spec/features/work_packages/table/timestamps/timestamps_rendering_spec.rbnew file mode 100644index 00000000000..ea5abc246df--- /dev/null+++ b/spec/features/work_packages/table/timestamps/timestamps_rendering_spec.rb@@ -0,0 +1,142 @@+#-- copyright+# OpenProject is an open source project management software.+# Copyright (C) 2012-2023 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'++describe 'timestamps rendering', js: true do+ shared_let(:type_bug) { create(:type_bug) }+ shared_let(:type_task) { create(:type_task) }+ shared_let(:project) { create(:project, types: [type_bug, type_task]) }+ shared_let(:user) do+ create(:user,+ member_in_project: project,+ member_with_permissions: %i[view_work_packages edit_work_packages])+ end++ shared_let(:wp_bug) do+ create(:work_package,+ project:,+ type: type_bug,+ subject: 'A bug',+ created_at: 5.days.ago,+ updated_at: 5.days.ago)+ end++ shared_let(:wp_task) do+ create(:work_package,+ project:,+ type: type_task,+ subject: 'A task',+ created_at: 5.days.ago,+ updated_at: 5.days.ago)+ end++ shared_let(:wp_task_changed) do+ wp = Timecop.travel(5.days.ago) do+ create(:work_package, project:, type: type_task, subject: 'Old subject')+ end++ Timecop.travel(1.day.ago) do+ ::WorkPackages::UpdateService+ .new(user:, model: wp)+ .call(subject: 'New subject')+ .on_failure { |result| raise result.message }+ .result+ end+ end++ shared_let(:wp_task_was_bug) do+ wp = Timecop.travel(5.days.ago) do+ create(:work_package, project:, type: type_bug, subject: 'Bug changed to Task')+ end++ Timecop.travel(1.day.ago) do+ ::WorkPackages::UpdateService+ .new(user:, model: wp)+ .call(type: type_task)+ .on_failure { |result| raise result.message }+ .result+ end+ end++ shared_let(:wp_bug_was_task) do+ wp = Timecop.travel(5.days.ago) do+ create(:work_package, project:, type: type_task, subject: 'Task changed to Bug')+ end++ Timecop.travel(1.day.ago) do+ ::WorkPackages::UpdateService+ .new(user:, model: wp)+ .call(type: type_bug)+ .on_failure { |result| raise result.message }+ .result+ end+ end++ shared_let(:query) do+ query = create(:query,+ name: 'Timestamps Query',+ project:,+ user:)++ query.timestamps = ["P-2d", "PT0S"]+ query.add_filter('type_id', '=', [type_task.id])+ query.save!(validate: false)++ query+ end++ let(:wp_table) { Pages::WorkPackagesTable.new(project) }+ let(:timestamps) { Components::WorkPackages::Timestamps.new }++ current_user { user }++ describe 'with feature enabled', with_flag: { show_changes: true } do+ it 'does show changes' do+ wp_table.visit_query(query)+ wp_table.expect_work_package_listed wp_task, wp_task_changed, wp_task_was_bug, wp_bug_was_task+ wp_table.ensure_work_package_not_listed! wp_bug++ timestamps.expect_active+ timestamps.expect_added wp_task_was_bug+ timestamps.expect_removed wp_bug_was_task+ timestamps.expect_changed wp_task_changed+ timestamps.expect_unchanged wp_task+ end+ end++ describe 'with feature disabled', with_flag: { show_changes: false } do+ it 'does not show changes' do+ wp_table.visit_query(query)+ wp_table.expect_work_package_listed wp_task, wp_task_changed, wp_task_was_bug+ wp_table.ensure_work_package_not_listed! wp_bug, wp_bug_was_task++ timestamps.expect_inactive+ end+ end+enddiff --git a/spec/support/components/work_packages/timestamps.rb b/spec/support/components/work_packages/timestamps.rbnew file mode 100644index 00000000000..0b1e049466c--- /dev/null+++ b/spec/support/components/work_packages/timestamps.rb@@ -0,0 +1,75 @@+#-- copyright+# OpenProject is an open source project management software.+# Copyright (C) 2012-2023 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.+#++++module Components+ module WorkPackages+ class Timestamps+ include Capybara::DSL+ include Capybara::RSpecMatchers+ include RSpec::Matchers++ def expect_active+ expect(page).to have_selector('.wp-table--timestamps-th')+ end++ def expect_inactive+ expect(page).to have_no_selector('.wp-table--timestamps-th')+ expect(page).to have_no_selector('.wp-table--timestamps-cell-td')+ end++ def expect_changed(work_package)+ expect_icon(work_package, :changed)+ end++ def expect_added(work_package)+ expect_icon(work_package, :added)+ end++ def expect_removed(work_package)+ expect_icon(work_package, :removed)+ end++ def expect_unchanged(work_package)+ page.within(row_selector(work_package)) do+ expect(page).to have_no_selector(".wp-table--timestamps-cell-td *")+ end+ end++ def expect_icon(work_package, icon_type)+ page.within(row_selector(work_package)) do+ expect(page).to have_selector(".op-table-timestamps--icon-#{icon_type}")+ end+ end++ def row_selector(elem)+ id = elem.is_a?(WorkPackage) ? elem.id.to_s : elem.to_s+ ".wp-row-#{id}-table"+ end+ end+ end+end