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

Switch `custom_actions_spec` to cuprite

Aaron Contreras9a3cd5d60dc7
diff --git a/spec/features/work_packages/custom_actions/custom_actions_spec.rb b/spec/features/work_packages/custom_actions/custom_actions_spec.rb
index 0c252f6b18b..caf1f664bf7 100644
--- a/spec/features/work_packages/custom_actions/custom_actions_spec.rb
+++ b/spec/features/work_packages/custom_actions/custom_actions_spec.rb
@@ -28,7 +28,10 @@
require 'spec_helper'
-RSpec.describe 'Custom actions', js: true, with_ee: %i[custom_actions] do
+RSpec.describe 'Custom actions',
+ js: true,
+ with_cuprite: true,
+ with_ee: %i[custom_actions] do
shared_let(:admin) { create(:admin) }
let(:permissions) { %i(view_work_packages edit_work_packages move_work_packages work_package_assigned) }
@@ -140,16 +143,15 @@ RSpec.describe 'Custom actions', js: true, with_ee: %i[custom_actions] do
let(:index_ca_page) { Pages::Admin::CustomActions::Index.new }
before do
- login_as(admin)
+ login_as admin
end
- it 'viewing workflow buttons' do
+ it 'viewing workflow buttons', with_cuprite: true do
# create custom action 'Unassign'
index_ca_page.visit!
new_ca_page = index_ca_page.new
retry_block do
- new_ca_page.visit!
new_ca_page.set_name('Unassign')
new_ca_page.set_description('Removes the assignee')
new_ca_page.add_action('Assignee', '-')
@@ -170,7 +172,6 @@ RSpec.describe 'Custom actions', js: true, with_ee: %i[custom_actions] do
new_ca_page = index_ca_page.new
retry_block do
- new_ca_page.visit!
new_ca_page.set_name('Close')
new_ca_page.add_action('Status', 'Close')
@@ -198,7 +199,6 @@ RSpec.describe 'Custom actions', js: true, with_ee: %i[custom_actions] do
new_ca_page = index_ca_page.new
retry_block do
- new_ca_page.visit!
new_ca_page.set_name('Escalate')
new_ca_page.add_action('Priority', immediate_priority.name)
new_ca_page.expect_action('priority', immediate_priority.id)
@@ -226,7 +226,6 @@ RSpec.describe 'Custom actions', js: true, with_ee: %i[custom_actions] do
new_ca_page = index_ca_page.new
retry_block do
- new_ca_page.visit!
new_ca_page.set_name('Reset')
new_ca_page.add_action('Priority', default_priority.name)
@@ -259,7 +258,6 @@ RSpec.describe 'Custom actions', js: true, with_ee: %i[custom_actions] do
new_ca_page = index_ca_page.new
retry_block do
- new_ca_page.visit!
new_ca_page.set_name('Other roles action')
new_ca_page.add_action('Status', default_status.name)
@@ -282,13 +280,18 @@ RSpec.describe 'Custom actions', js: true, with_ee: %i[custom_actions] do
new_ca_page = index_ca_page.new
retry_block do
- new_ca_page.visit!
new_ca_page.set_name('Move project')
# Add date custom action which has a different admin layout
- select date_custom_field.name, from: 'Add action'
- select 'on', from: date_custom_field.name
- date = (Date.today + 5.days)
+ ignore_ferrum_javascript_error do
+ select date_custom_field.name, from: 'Add action'
+ end
+
+ ignore_ferrum_javascript_error do
+ select 'on', from: date_custom_field.name
+ end
+
+ date = (Date.current + 5.days)
find("#custom_action_actions_custom_field_#{date_custom_field.id}_visible").click
datepicker = Components::Datepicker.new 'body'
datepicker.set_date date
@@ -366,7 +369,6 @@ RSpec.describe 'Custom actions', js: true, with_ee: %i[custom_actions] do
edit_ca_page = index_ca_page.edit('Reset')
retry_block do
- edit_ca_page.visit!
edit_ca_page.set_name 'Reject'
edit_ca_page.remove_action 'Priority'
edit_ca_page.set_action 'Assignee', '-'
diff --git a/spec/support/components/datepicker/datepicker.rb b/spec/support/components/datepicker/datepicker.rb
index c2898eca482..7caa6cef0c7 100644
--- a/spec/support/components/datepicker/datepicker.rb
+++ b/spec/support/components/datepicker/datepicker.rb
@@ -81,11 +81,12 @@ module Components
raise ArgumentError, "Invalid value #{value} for day, expected 1-31"
end
+ expect(flatpickr_container).to have_text(value)
+
retry_block do
flatpickr_container
.first('.flatpickr-days .flatpickr-day:not(.nextMonthDay):not(.prevMonthDay)',
- text: value,
- exact_text: true)
+ text: value)
.click
end
end
diff --git a/spec/support/pages/admin/custom_actions/form.rb b/spec/support/pages/admin/custom_actions/form.rb
index a7f4226acbd..2272dc09ce0 100644
--- a/spec/support/pages/admin/custom_actions/form.rb
+++ b/spec/support/pages/admin/custom_actions/form.rb
@@ -36,7 +36,6 @@ module Pages
include ::Components::Autocompleter::NgSelectAutocompleteHelpers
def set_name(name)
- fill_in 'Name', with: ''
fill_in 'Name', with: name
end
@@ -45,12 +44,13 @@ module Pages
end
def add_action(name, value)
- sleep 1
- select name, from: 'Add action'
- sleep 1
+ ignore_ferrum_javascript_error do
+ select name, from: 'Add action'
+ end
set_action_value(name, value)
- sleep 1
- page.assert_selector('#custom-actions-form--active-actions .form--label', text: name)
+ within '#custom-actions-form--active-actions' do
+ expect(page).to have_selector('.form--label', text: name)
+ end
end
def remove_action(name)
@@ -68,11 +68,13 @@ module Pages
def expect_action(name, value)
value = 'null' if value.nil?
- if value.is_a?(Array)
- value.each { |name| expect_selected_option(name.to_s) }
- else
- element = page.find("input[name='custom_action[actions][#{name}]']", visible: :all)
- expect(element.value).to eq value.to_s
+ within '#custom-actions-form--actions' do
+ if value.is_a?(Array)
+ value.each { |name| expect_selected_option(name.to_s) }
+ else
+ element = find("input[name='custom_action[actions][#{name}]']", visible: :all)
+ expect(element.value).to eq value.to_s
+ end
end
end
@@ -97,8 +99,6 @@ module Pages
within '#custom-actions-form--conditions' do
expect_selected_option val
end
-
- sleep 1
end
end
diff --git a/spec/support/pages/admin/custom_actions/index.rb b/spec/support/pages/admin/custom_actions/index.rb
index f02ae189b1f..2b692c840d2 100644
--- a/spec/support/pages/admin/custom_actions/index.rb
+++ b/spec/support/pages/admin/custom_actions/index.rb
@@ -50,10 +50,10 @@ module Pages
end
def delete(name)
- within_buttons_of name do
- find('.icon-delete').click
-
- accept_alert_dialog!
+ accept_alert do
+ within_buttons_of name do
+ find('.icon-delete').click
+ end
end
end
@@ -68,25 +68,25 @@ module Pages
def move_top(name)
within_row_of(name) do
- click_link 'Move to top'
+ find("a[title='Move to top']").trigger('click')
end
end
def move_bottom(name)
within_row_of(name) do
- click_link 'Move to bottom'
+ find("a[title='Move to bottom']").trigger('click')
end
end
def move_up(name)
within_row_of(name) do
- click_link 'Move up'
+ find("a[title='Move up']").trigger('click')
end
end
def move_down(name)
within_row_of(name) do
- click_link 'Move down'
+ find("a[title='Move down']").trigger('click')
end
end
diff --git a/spec/support/pages/admin/custom_actions/new.rb b/spec/support/pages/admin/custom_actions/new.rb
index 25233c34a28..4d1dac05ba6 100644
--- a/spec/support/pages/admin/custom_actions/new.rb
+++ b/spec/support/pages/admin/custom_actions/new.rb
@@ -35,7 +35,6 @@ module Pages
module CustomActions
class New < Form
def create
- sleep 2
click_button 'Create'
end
diff --git a/spec/support/shared/ferrum_patches.rb b/spec/support/shared/ferrum_patches.rb
new file mode 100644
index 00000000000..33d40739fef
--- /dev/null
+++ b/spec/support/shared/ferrum_patches.rb
@@ -0,0 +1,43 @@
+# frozen_string_literal: true
+
+# -- copyright
+# OpenProject is an open source project management software.
+# Copyright (C) 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.
+# ++
+#
+
+# A Cuprite edge-case with our use of select
+# fields causes a Ferrum::JavaScriptError to be raised
+# when an option HTMLElement is removed from its select field
+#
+# Use this as a temporary patch
+
+require 'ferrum/errors'
+
+def ignore_ferrum_javascript_error
+ yield
+rescue Ferrum::JavaScriptError
+end
diff --git a/spec/support/shared/scroll_into_view_helpers.rb b/spec/support/shared/scroll_into_view_helpers.rb
index b576d439e8e..c9e4623a6c1 100644
--- a/spec/support/shared/scroll_into_view_helpers.rb
+++ b/spec/support/shared/scroll_into_view_helpers.rb
@@ -31,7 +31,11 @@ def scroll_to_element(element)
script = <<-JS
arguments[0].scrollIntoView(true);
JS
- Capybara.current_session.driver.browser.execute_script(script, element.native)
+ if Capybara.javascript_driver == :better_cuprite_en
+ page.driver.execute_script(script, element.native)
+ else
+ Capybara.current_session.driver.browser.execute_script(script, element.native)
+ end
end
def scroll_to_and_click(element)