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

Add specs for project phase datepicker interaction

Dombi Attila30ca0f860d9f
diff --git a/spec/features/projects/life_cycle/overview_page/dialog/update_spec.rb b/spec/features/projects/life_cycle/overview_page/dialog/update_spec.rb
index 104cc941415..8b5645c8a4f 100644
--- a/spec/features/projects/life_cycle/overview_page/dialog/update_spec.rb
+++ b/spec/features/projects/life_cycle/overview_page/dialog/update_spec.rb
@@ -64,8 +64,9 @@ RSpec.describe "Edit project phases on project overview page", :js, with_flag: {
it "shows all the Project::Phases without a value" do
project_life_cycles.each do |life_cycle|
dialog = overview_page.open_edit_dialog_for_life_cycle(life_cycle)
+
dialog.expect_title(life_cycle.name)
- dialog.expect_input("Start date", value: "")
+ dialog.expect_input("Start date", value: "", disabled: false)
dialog.expect_input("Finish date", value: "")
dialog.expect_input("Duration", value: "", disabled: true)
@@ -79,6 +80,83 @@ RSpec.describe "Edit project phases on project overview page", :js, with_flag: {
end
end
end
+
+ describe "the datepicker interaction" do
+ # Start date is already defined in the included context
+ let(:finish_date) { start_date + 1.day }
+ let(:new_start_date) { start_date - 1.week }
+ let(:new_finish_date) { start_date }
+
+ it "interconnects the calendar with the date input fields" do
+ dialog = overview_page.open_edit_dialog_for_life_cycle(life_cycle_initiating, wait_angular: true)
+
+ # Set date input fields by choosing a range in the calendar
+ dialog.set_date_for(values: [start_date, finish_date])
+
+ dialog.expect_input("Start date", value: start_date.strftime("%Y-%m-%d"))
+ dialog.expect_input("Finish date", value: finish_date.strftime("%Y-%m-%d"))
+ dialog.expect_input("Duration", value: 2, disabled: true)
+
+ # Set a new finish date by focusing the finish date field
+ dialog.activate_field("Finish date")
+ dialog.set_date_for(values: [new_finish_date])
+
+ dialog.expect_input("Start date", value: start_date.strftime("%Y-%m-%d"))
+ dialog.expect_input("Finish date", value: new_finish_date.strftime("%Y-%m-%d"), active: true)
+ dialog.expect_input("Duration", value: 1, disabled: true)
+
+ # Set a new start date by focusing the start date field
+ dialog.activate_field("Start date")
+ dialog.set_date_for(values: [new_start_date])
+
+ dialog.expect_input("Start date", value: new_start_date.strftime("%Y-%m-%d"))
+ # Expect the finish date to be cleared and activated
+ dialog.expect_input("Finish date", value: "", active: true)
+ dialog.expect_input("Duration", value: "", disabled: true)
+
+ # Set the new finish date too
+ dialog.activate_field("Finish date")
+ dialog.set_date_for(values: [new_finish_date])
+
+ dialog.expect_input("Start date", value: new_start_date.strftime("%Y-%m-%d"))
+ dialog.expect_input("Finish date", value: new_finish_date.strftime("%Y-%m-%d"))
+ dialog.expect_input("Duration", value: 8, disabled: true)
+
+ # Clearing the date fields by using the clear button
+ dialog.clear_dates
+
+ # Setting the finish date without a start date being present
+ dialog.activate_field("Finish date")
+ dialog.set_date_for(values: [new_finish_date])
+
+ # The empty start date is focused and the new finish date is filled in
+ dialog.expect_input("Start date", value: "", active: true)
+ dialog.expect_input("Finish date", value: new_finish_date.strftime("%Y-%m-%d"))
+ dialog.expect_input("Duration", value: "", disabled: true)
+
+ # Filling the activated start date should complete the range
+ dialog.set_date_for(values: [new_start_date])
+
+ dialog.expect_input("Start date", value: new_start_date.strftime("%Y-%m-%d"))
+ dialog.expect_input("Finish date", value: new_finish_date.strftime("%Y-%m-%d"))
+ dialog.expect_input("Duration", value: 8, disabled: true)
+
+ # Manually setting an inverse range should show an validation message
+ fill_in("Finish date", with: (new_start_date - 1.day).strftime("%Y-%m-%d"))
+ .send_keys(:tab)
+
+ dialog.expect_validation_message(
+ "Finish date",
+ text: "Finish date must be after the start date."
+ )
+
+ # Setting a correct range will clear the error message
+ fill_in("Finish date", with: new_finish_date.strftime("%Y-%m-%d"))
+ .send_keys(:tab)
+
+ dialog.expect_no_validation_message("Finish date")
+ end
+ end
end
context "when all LifeCycleSteps have a value" do
diff --git a/spec/support/components/projects/project_life_cycles/edit_dialog.rb b/spec/support/components/projects/project_life_cycles/edit_dialog.rb
index b94f7e1981d..d325120dea9 100644
--- a/spec/support/components/projects/project_life_cycles/edit_dialog.rb
+++ b/spec/support/components/projects/project_life_cycles/edit_dialog.rb
@@ -52,9 +52,15 @@ module Components
end
def clear_dates
- click_button("start_date_clear_button") if has_button?("start_date_clear_button")
- click_button("finish_date_clear_button") if has_button?("finish_date_clear_button")
- sleep 1 # Wait for the debounce from previewForm to complete
+ if has_button?("start_date_clear_button")
+ click_button("start_date_clear_button")
+ wait_for_form_preview_to_reload
+ end
+
+ if has_button?("finish_date_clear_button")
+ click_button("finish_date_clear_button")
+ wait_for_form_preview_to_reload
+ end
end
def set_date_for(values:)
@@ -64,10 +70,19 @@ module Components
values.each do |date|
datepicker.set_date(date.strftime("%Y-%m-%d"))
+ # TODO: Use wait_for_form_preview_to_reload instead when the backdrop loading
+ # via turbo streams is fixed.
sleep 1 # Wait for the debounce from previewForm to complete
end
end
+ def activate_field(field_name)
+ within_dialog do
+ find_field(field_name).click
+ end
+ expect_input(field_name, active: true)
+ end
+
def close
within_dialog do
page.find(".close-button").click
@@ -81,6 +96,11 @@ module Components
end
end
+ def wait_for_form_preview_to_reload
+ expect(page).to have_css("form[aria-busy]")
+ expect(page).to have_no_css("form[aria-busy]")
+ end
+
def submit
within_dialog do
page.find("[data-test-selector='save-project-life-cycles-button']").click
@@ -105,45 +125,37 @@ module Components
end
end
- def expect_input(label, value:, disabled: false)
+ def expect_input(label, value: nil, disabled: false, active: false)
+ field_options = { disabled: }
+ field_options[:with] = value if value
+ field_options[:class] = "op-datepicker-modal--date-field_current" if active
+
within_async_content do
- expect(page).to have_field(label, with: value, disabled:)
+ expect(page).to have_field(label, **field_options)
# Note: This capybara matcher has a bug and it raises an error, if the
- # label, name and disabled flags are passed at once.
+ # label, name and disabled flags are passed at once:
#
# TypeError: no implicit conversion of XPath::Expression into Integer (TypeError)
# expression_filter(:disabled) { |xpath, val| val ? xpath : xpath[~XPath.attr(:disabled)] }
# from ~/.rbenv/versions/3.4.2/lib/ruby/gems/3.4.0/gems/capybara-3.40.0/lib/capybara/selector.rb:448:in 'String#[]'
expect(page).to have_field(
- with: value,
name: "project_phase[#{label.parameterize.underscore}]",
- disabled:
+ **field_options
)
end
end
- def expect_validation_message(text: nil, present: true)
- selector = 'div[id^="validation"]'
- expect_selector_for(selector:, text:, present:)
- end
-
- def expect_no_validation_message
- expect_validation_message(present: false)
+ def expect_validation_message(field_name, text: nil, present: true)
+ parent = find_field(field_name).ancestor("primer-text-field")
+ if present
+ expect(parent).to have_css('div[id^="validation"]', text:)
+ else
+ expect(parent).to have_no_css('div[id^="validation"]')
+ end
end
- private
-
- def expect_selector_for(selector:, text: nil, present: true)
- within_async_content do
- input_id = "#project_phase_date_range"
- parent = find(input_id).ancestor("primer-datepicker-field")
-
- if present
- expect(parent).to have_selector(selector, text:)
- else
- expect(parent).to have_no_selector(selector)
- end
- end
+ def expect_no_validation_message(field_name)
+ expect_validation_message(field_name, present: false)
end
end
end