From bbc2ca40c2e1df0793c838d14ea3225a016fccbb Mon Sep 17 00:00:00 2001 From: Orlando Del Aguila Date: Fri, 29 Jun 2018 18:04:03 -0500 Subject: [PATCH] save current date before Pikaday init --- app/assets/javascripts/due_date_select.js | 4 +++- ...ing-milestone-date-change-when-editing.yml | 5 +++++ .../milestones/user_edits_milestone_spec.rb | 22 +++++++++++++++++++ 3 files changed, 30 insertions(+), 1 deletion(-) create mode 100644 changelogs/unreleased/41671-fixing-milestone-date-change-when-editing.yml create mode 100644 spec/features/milestones/user_edits_milestone_spec.rb diff --git a/app/assets/javascripts/due_date_select.js b/app/assets/javascripts/due_date_select.js index 4164149dd06..39bb838f683 100644 --- a/app/assets/javascripts/due_date_select.js +++ b/app/assets/javascripts/due_date_select.js @@ -170,6 +170,8 @@ export default class DueDateSelectors { initMilestoneDatePicker() { $('.datepicker').each(function initPikadayMilestone() { const $datePicker = $(this); + const datePickerVal = $datePicker.val(); + const calendar = new Pikaday({ field: $datePicker.get(0), theme: 'gitlab-theme animate-picker', @@ -182,7 +184,7 @@ export default class DueDateSelectors { }, }); - calendar.setDate(parsePikadayDate($datePicker.val())); + calendar.setDate(parsePikadayDate(datePickerVal)); $datePicker.data('pikaday', calendar); }); diff --git a/changelogs/unreleased/41671-fixing-milestone-date-change-when-editing.yml b/changelogs/unreleased/41671-fixing-milestone-date-change-when-editing.yml new file mode 100644 index 00000000000..c6a0dc4f129 --- /dev/null +++ b/changelogs/unreleased/41671-fixing-milestone-date-change-when-editing.yml @@ -0,0 +1,5 @@ +--- +title: "Fixing milestone date change when editing" +merge_request: 20279 +author: Orlando Del Aguila +type: fixed \ No newline at end of file diff --git a/spec/features/milestones/user_edits_milestone_spec.rb b/spec/features/milestones/user_edits_milestone_spec.rb new file mode 100644 index 00000000000..077295f1cc0 --- /dev/null +++ b/spec/features/milestones/user_edits_milestone_spec.rb @@ -0,0 +1,22 @@ +require "rails_helper" + +describe "User edits milestone", :js do + set(:user) { create(:user) } + set(:project) { create(:project) } + set(:milestone) { create(:milestone, project: project, start_date: Date.today, due_date: 5.days.from_now) } + + before do + project.add_developer(user) + sign_in(user) + + visit(edit_project_milestone_path(project, milestone)) + end + + it "shows the right start date and due date" do + start_date = milestone.start_date.strftime("%F") + due_date = milestone.due_date.strftime("%F") + + expect(page).to have_field(with: start_date) + expect(page).to have_field(with: due_date) + end +end