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
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.tsindex 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.rbindex 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" docontext "when all LifeCycleSteps are blank" dobefore 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)endit "shows all the Project::Phases without a value" doproject_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 successfuldialog.expect_closed@@ -87,7 +91,11 @@ RSpec.describe "Edit project phases on project overview page", :js, with_flag: {# Set a value for life_cycle_initiatingdialog = 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)+ endretry_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_planningdialog = 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 successfuldialog.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.rbindex 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 Componentsclose if close_after_yieldend- 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 completeenddef set_date_for(values:)@@ -61,12 +62,9 @@ module Componentsdatepicker = 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 completeendend@@ -78,13 +76,13 @@ module Componentsalias_method :close_via_icon, :closedef close_via_button- within(dialog_css_selector) do+ within_dialog doclick_link_or_button "Cancel"endenddef submit- within(dialog_css_selector) do+ within_dialog dopage.find("[data-test-selector='save-project-life-cycles-button']").clickendend@@ -101,31 +99,29 @@ module Componentsexpect(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:)endend- 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:)