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 `work_packages/new/new_work_package_spec.rb` to cuprite

Christophe Bliard6f969500749a
diff --git a/spec/features/work_packages/new/new_work_package_spec.rb b/spec/features/work_packages/new/new_work_package_spec.rb
index 8ab4cf8f325..081da99fe4f 100644
--- a/spec/features/work_packages/new/new_work_package_spec.rb
+++ b/spec/features/work_packages/new/new_work_package_spec.rb
@@ -3,13 +3,13 @@ require 'support/edit_fields/edit_field'
require 'features/work_packages/work_packages_page'
require 'features/page_objects/notification'
-RSpec.describe 'new work package', js: true do
+RSpec.describe 'new work package', js: true, with_cuprite: true do
+ shared_let(:status) { create(:status, is_default: true) }
+ shared_let(:priority) { create(:priority, is_default: true) }
+ let!(:types) { [type_task, type_milestone, type_bug] }
let(:type_task) { create(:type_task) }
let(:type_milestone) { create(:type_milestone, position: type_task.position + 1) }
let(:type_bug) { create(:type_bug, position: type_milestone.position + 1) }
- let(:types) { [type_task, type_milestone, type_bug] }
- let!(:status) { create(:status, is_default: true) }
- let!(:priority) { create(:priority, is_default: true) }
let!(:project) do
create(:project, types:)
end
diff --git a/spec/support/components/datepicker/datepicker.rb b/spec/support/components/datepicker/datepicker.rb
index 7caa6cef0c7..648ca60f4db 100644
--- a/spec/support/components/datepicker/datepicker.rb
+++ b/spec/support/components/datepicker/datepicker.rb
@@ -39,11 +39,8 @@ module Components
##
# Clear all values
def clear!
- focus_start_date
- fill_in 'startDate', with: '', fill_options: { clear: :backspace }
-
- focus_due_date
- fill_in 'endDate', with: '', fill_options: { clear: :backspace }
+ set_field(container.find_field('startDate'), '', wait_for_changes_to_be_applied: false)
+ set_field(container.find_field('endDate'), '', wait_for_changes_to_be_applied: false)
end
def expect_visible
@@ -180,5 +177,26 @@ module Components
expect(page).to have_selector(".flatpickr-day:not(.flatpickr-disabled)[aria-label='#{label}']",
wait: 20)
end
+
+ protected
+
+ def focus_field(field)
+ field.click
+ end
+
+ def set_field(field, value, wait_for_changes_to_be_applied: true)
+ focus_field(field)
+ if using_cuprite?
+ clear_input_field_contents(field)
+ field.fill_in(with: value)
+ else
+ field.fill_in(with: value, fill_options: { clear: :backspace })
+ end
+
+ if wait_for_changes_to_be_applied
+ sleep 0.5 # input debounce
+ wait_for_network_idle if using_cuprite?
+ end
+ end
end
end
diff --git a/spec/support/components/datepicker/work_package_datepicker.rb b/spec/support/components/datepicker/work_package_datepicker.rb
index 51cfb431925..edb1e9e5fd3 100644
--- a/spec/support/components/datepicker/work_package_datepicker.rb
+++ b/spec/support/components/datepicker/work_package_datepicker.rb
@@ -7,8 +7,7 @@ module Components
def clear!
super
- clear_duration
- expect_duration ''
+ set_field(duration_field, '', wait_for_changes_to_be_applied: false)
end
##
@@ -46,15 +45,15 @@ module Components
end
def focus_milestone_date
- milestone_date_field.click
+ focus_field(milestone_date_field)
end
def focus_start_date
- start_date_field.click
+ focus_field(start_date_field)
end
def focus_due_date
- due_date_field.click
+ focus_field(due_date_field)
end
##
@@ -76,21 +75,15 @@ module Components
end
def set_milestone_date(value)
- focus_milestone_date
- clear_input_field_contents('date')
- fill_in 'date', with: value
+ set_field(milestone_date_field, value)
end
def set_start_date(value)
- focus_start_date
- clear_input_field_contents('startDate')
- fill_in 'startDate', with: value
+ set_field(start_date_field, value)
end
def set_due_date(value)
- focus_due_date
- clear_input_field_contents('endDate')
- fill_in 'endDate', with: value
+ set_field(due_date_field, value)
end
def expect_start_highlighted
@@ -106,7 +99,7 @@ module Components
end
def focus_duration
- duration_field.click
+ focus_field(duration_field)
end
def set_today(date)
@@ -128,9 +121,7 @@ module Components
end
def set_duration(value)
- focus_duration
- clear_input_field_contents('duration')
- fill_in 'duration', with: value
+ set_field(duration_field, value)
# Focus a different field
start_date_field.click
@@ -181,12 +172,7 @@ module Components
end
def clear_duration
- duration_field.click
- clear_input_field_contents('duration')
- fill_in 'duration', with: ''
-
- # Focus a different field
- start_date_field.click
+ set_duration('')
end
def clear_duration_with_icon
diff --git a/spec/support/edit_fields/date_edit_field.rb b/spec/support/edit_fields/date_edit_field.rb
index 46e47334a0b..8cbd5ec62b6 100644
--- a/spec/support/edit_fields/date_edit_field.rb
+++ b/spec/support/edit_fields/date_edit_field.rb
@@ -142,7 +142,6 @@ class DateEditField < EditField
datepicker.set_start_date value.first
datepicker.set_due_date value.last
- sleep 1
datepicker.expect_start_date value.first
datepicker.expect_due_date value.last
else
diff --git a/spec/support/matchers/has_focus_on.rb b/spec/support/matchers/has_focus_on.rb
index 30b705b9829..8bac11652bf 100644
--- a/spec/support/matchers/has_focus_on.rb
+++ b/spec/support/matchers/has_focus_on.rb
@@ -36,10 +36,9 @@ module Capybara
return_value = false
while !return_value && Time.now - starting_time < Capybara.default_max_wait_time
+ focused_element = evaluate_script("document.activeElement")
- focused_element = driver.browser.switch_to.active_element
-
- return_value = find(selector).native == focused_element
+ return_value = find(selector) == focused_element
end
return_value
diff --git a/spec/support/shared/cuprite_helpers.rb b/spec/support/shared/cuprite_helpers.rb
index edbbdb0bfd1..d76eaf6e16e 100644
--- a/spec/support/shared/cuprite_helpers.rb
+++ b/spec/support/shared/cuprite_helpers.rb
@@ -51,9 +51,8 @@ def clear_input_field_contents(input_element)
input_element = find_field(input_element)
end
- (input_element.value.length + 1).times do
- input_element.native.node.type(:backspace)
- end
+ backspaces = Array.new(input_element.value.length + 1, :backspace)
+ input_element.native.node.type(*backspaces)
end
def using_cuprite?