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

Update specs to handle multiple date input fields, restore preview form url instantly.

Dombi Attila5980f4a7478e
diff --git a/frontend/src/stimulus/controllers/form-preview.controller.ts b/frontend/src/stimulus/controllers/form-preview.controller.ts
index cd22b91e15b..0b3d44fc217 100644
--- a/frontend/src/stimulus/controllers/form-preview.controller.ts
+++ b/frontend/src/stimulus/controllers/form-preview.controller.ts
@@ -41,8 +41,10 @@ export default class FormPreviewController extends Controller<HTMLFormElement> {
}
const form = this.element;
+ const submitUrl = form.action;
form.action = this.urlValue;
-
- form.requestSubmit();
+ const submitter = document.querySelector(`button[form="${form.id}"][type="submit"]`) as HTMLElement;
+ form.requestSubmit(submitter);
+ form.action = submitUrl;
}
}
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 7ccc55c7dab..104cc941415 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
@@ -57,13 +57,17 @@ RSpec.describe "Edit project phases on project overview page", :js, with_flag: {
describe "with the dialog open" do
context "when all LifeCycleSteps are blank" do
before do
- Project::Phase.update_all(start_date: nil, finish_date: nil)
+ Project::Phase.update_all(start_date: nil, finish_date: nil, duration: nil)
+ project_life_cycles.each(&:reload)
end
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_input(life_cycle.name, value: "")
+ dialog.expect_title(life_cycle.name)
+ dialog.expect_input("Start date", value: "")
+ dialog.expect_input("Finish date", value: "")
+ dialog.expect_input("Duration", value: "", disabled: true)
dialog.submit # Saving the dialog is successful
dialog.expect_closed
@@ -87,7 +91,11 @@ RSpec.describe "Edit project phases on project overview page", :js, with_flag: {
# Set a value for life_cycle_initiating
dialog = overview_page.open_edit_dialog_for_life_cycle(life_cycle_initiating, wait_angular: true)
- dialog.expect_input_for(life_cycle_initiating)
+ life_cycle_initiating.tap do |step|
+ dialog.expect_input("Start date", value: step.start_date.strftime("%Y-%m-%d"))
+ dialog.expect_input("Finish date", value: step.finish_date.strftime("%Y-%m-%d"))
+ dialog.expect_input("Duration", value: step.duration, disabled: true)
+ end
retry_block do
# Retrying due to a race condition between filling the input vs submitting the form preview.
@@ -95,11 +103,12 @@ RSpec.describe "Edit project phases on project overview page", :js, with_flag: {
dialog.set_date_for(values: original_dates)
page.driver.clear_network_traffic
+
dialog.set_date_for(values: [start_date - 1.week, start_date])
- dialog.expect_caption(text: "Duration: 8 working days")
- # Ensure that only 1 ajax request is triggered after setting the date range.
- expect(page.driver.browser.network.traffic.size).to eq(1)
+ dialog.expect_input("Duration", value: 8, disabled: true)
+ # Ensure that 2 ajax request are triggered after setting the date range.
+ expect(page.driver.browser.network.traffic.size).to eq(2)
end
# Saving the dialog is successful
@@ -118,8 +127,13 @@ RSpec.describe "Edit project phases on project overview page", :js, with_flag: {
# Clear the value of life_cycle_planning
dialog = overview_page.open_edit_dialog_for_life_cycle(life_cycle_planning, wait_angular: true)
- dialog.expect_input_for(life_cycle_planning)
- dialog.clear_date
+ life_cycle_planning.tap do |step|
+ dialog.expect_input("Start date", value: step.start_date.strftime("%Y-%m-%d"), disabled: true)
+ dialog.expect_input("Finish date", value: step.finish_date.strftime("%Y-%m-%d"))
+ dialog.expect_input("Duration", value: step.duration, disabled: true)
+ end
+
+ dialog.clear_dates
# Saving the dialog is successful
dialog.submit
@@ -145,8 +159,16 @@ RSpec.describe "Edit project phases on project overview page", :js, with_flag: {
"#{I18n.l life_cycle_initiating.start_date} - " \
"#{I18n.l life_cycle_initiating.finish_date}")
- activity_page.expect_activity("Planning date deleted " \
+ activity_page.expect_activity("Planning changed from " \
"#{I18n.l life_cycle_planning_was.start_date} - " \
+ "#{I18n.l life_cycle_planning_was.finish_date} to " \
+ "#{I18n.l life_cycle_planning.start_date} - ")
+
+ activity_page.expect_activity("Planning Start Gate changed from " \
+ "#{I18n.l life_cycle_planning_was.start_date} to " \
+ "#{I18n.l life_cycle_planning.start_date}")
+
+ activity_page.expect_activity("Planning Finish Gate date deleted " \
"#{I18n.l life_cycle_planning_was.finish_date}")
activity_page.expect_activity("Executing changed from " \
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 0bd428cbfdb..b94f7e1981d 100644
--- a/spec/support/components/projects/project_life_cycles/edit_dialog.rb
+++ b/spec/support/components/projects/project_life_cycles/edit_dialog.rb
@@ -51,9 +51,10 @@ module Components
close if close_after_yield
end
- def clear_date
- find("input[id^='project_phase_date_range']").set ""
- find_by_id("edit-project-life-cycles-dialog-title").click
+ 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
end
def set_date_for(values:)
@@ -61,12 +62,9 @@ module Components
datepicker = Components::RangeDatepicker.new(dialog_selector)
- datepicker.open(
- "input[id^='project_phase_date_range']"
- )
-
values.each do |date|
datepicker.set_date(date.strftime("%Y-%m-%d"))
+ sleep 1 # Wait for the debounce from previewForm to complete
end
end
@@ -78,13 +76,13 @@ module Components
alias_method :close_via_icon, :close
def close_via_button
- within(dialog_css_selector) do
+ within_dialog do
click_link_or_button "Cancel"
end
end
def submit
- within(dialog_css_selector) do
+ within_dialog do
page.find("[data-test-selector='save-project-life-cycles-button']").click
end
end
@@ -101,31 +99,29 @@ module Components
expect(page).to have_css(async_content_container_css_selector)
end
- def expect_input(label, value:)
+ def expect_title(text)
+ within_dialog do
+ expect(page).to have_css("h1", text:)
+ end
+ end
+
+ def expect_input(label, value:, disabled: false)
within_async_content do
+ expect(page).to have_field(label, with: value, disabled:)
+ # Note: This capybara matcher has a bug and it raises an error, if the
+ # 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(
- label,
with: value,
- name: "project_phase[date_range]"
+ name: "project_phase[#{label.parameterize.underscore}]",
+ disabled:
)
end
end
- def expect_input_for(step)
- value = "#{step.start_date.strftime('%Y-%m-%d')} - #{step.finish_date.strftime('%Y-%m-%d')}"
-
- expect_input(step.name, value:)
- end
-
- def expect_caption(text: nil, present: true)
- selector = 'span[id^="caption"]'
- expect_selector_for(selector:, text:, present:)
- end
-
- def expect_no_caption
- expect_caption(present: false)
- end
-
def expect_validation_message(text: nil, present: true)
selector = 'div[id^="validation"]'
expect_selector_for(selector:, text:, present:)