Commit d2f0b0a7 authored by Eulyeon Ko's avatar Eulyeon Ko

Fix dates being incorrectly set on epic creation

Date pickers emit Javascript Date instances and
these get converted to datetime strings with timezone info.

Ex. a user in UTC+9 timezone picks some date (say July 1).
The underlying Date object gets converted to a string
that uses UTC+0 as the default timezone and the date may
change becuase of this conversion:

'2021-07-01 UTC+9 Korean Standard Time'
=> '2021-06-30T??:??:??Z'

Changelog: fixed
EE: true
parent 86d5d922
...@@ -8,6 +8,7 @@ import { ...@@ -8,6 +8,7 @@ import {
GlFormInput, GlFormInput,
} from '@gitlab/ui'; } from '@gitlab/ui';
import createFlash from '~/flash'; import createFlash from '~/flash';
import { formatDate } from '~/lib/utils/datetime_utility';
import { visitUrl } from '~/lib/utils/url_utility'; import { visitUrl } from '~/lib/utils/url_utility';
import { s__ } from '~/locale'; import { s__ } from '~/locale';
import MarkdownField from '~/vue_shared/components/markdown/field.vue'; import MarkdownField from '~/vue_shared/components/markdown/field.vue';
...@@ -70,9 +71,11 @@ export default { ...@@ -70,9 +71,11 @@ export default {
title: this.title, title: this.title,
description: this.description, description: this.description,
confidential: this.confidential, confidential: this.confidential,
startDateFixed: this.startDateFixed, startDateFixed: this.startDateFixed
? formatDate(this.startDateFixed, 'yyyy-mm-dd')
: null,
startDateIsFixed: Boolean(this.startDateFixed), startDateIsFixed: Boolean(this.startDateFixed),
dueDateFixed: this.dueDateFixed, dueDateFixed: this.dueDateFixed ? formatDate(this.dueDateFixed, 'yyyy-mm-dd') : null,
dueDateIsFixed: Boolean(this.dueDateFixed), dueDateIsFixed: Boolean(this.dueDateFixed),
}, },
}, },
......
...@@ -92,48 +92,56 @@ describe('ee/epic/components/epic_form.vue', () => { ...@@ -92,48 +92,56 @@ describe('ee/epic/components/epic_form.vue', () => {
}); });
describe('save', () => { describe('save', () => {
it('submits successfully if form data is provided', async () => { const addLabelIds = [1];
createWrapper(); const title = 'Status page MVP';
const description = '### Goal\n\n- [ ] Item';
const confidential = true;
const addLabelIds = [1]; it.each`
const title = 'Status page MVP'; startDateFixed | dueDateFixed | startDateIsFixed | dueDateIsFixed
const description = '### Goal\n\n- [ ] Item'; ${null} | ${null} | ${false} | ${false}
const confidential = true; ${'2021-07-01'} | ${null} | ${true} | ${false}
const startDateFixed = new Date(); ${null} | ${'2021-07-02'} | ${false} | ${true}
const startDateIsFixed = true; ${'2021-07-01'} | ${'2021-07-02'} | ${true} | ${true}
const dueDateFixed = null; `(
const dueDateIsFixed = false; 'requests mutation with correct data with all start and due date configurations',
async ({ startDateFixed, dueDateFixed, startDateIsFixed, dueDateIsFixed }) => {
findTitle().vm.$emit('input', title); createWrapper();
findDescription().setValue(description);
findConfidentialityCheck().vm.$emit('input', confidential); findTitle().vm.$emit('input', title);
findLabels().vm.$emit('updateSelectedLabels', [{ id: 1, set: 1 }]); findDescription().setValue(description);
findStartDate().vm.$emit('input', startDateFixed); findConfidentialityCheck().vm.$emit('input', confidential);
findDueDate().vm.$emit('input', dueDateFixed); findLabels().vm.$emit('updateSelectedLabels', [{ id: 1, set: 1 }]);
findForm().vm.$emit('submit', { preventDefault: () => {} }); // Make sure the submitted values for start and due dates are date strings without timezone info.
// (Datepicker emits a Date object but the submitted value must be a date string).
expect(wrapper.vm.$apollo.mutate).toHaveBeenCalledWith({ findStartDate().vm.$emit('input', startDateFixed ? new Date(startDateFixed) : null);
mutation: createEpic, findDueDate().vm.$emit('input', dueDateFixed ? new Date(dueDateFixed) : null);
variables: {
input: { findForm().vm.$emit('submit', { preventDefault: () => {} });
groupPath: TEST_GROUP_PATH,
addLabelIds, expect(wrapper.vm.$apollo.mutate).toHaveBeenCalledWith({
title, mutation: createEpic,
description, variables: {
confidential, input: {
startDateFixed, groupPath: TEST_GROUP_PATH,
startDateIsFixed, addLabelIds,
dueDateFixed, title,
dueDateIsFixed, description,
confidential,
startDateFixed,
startDateIsFixed,
dueDateFixed,
dueDateIsFixed,
},
}, },
}, });
});
await wrapper.vm.$nextTick(); await wrapper.vm.$nextTick();
expect(visitUrl).toHaveBeenCalled(); expect(visitUrl).toHaveBeenCalled();
}); },
);
it.each` it.each`
status | result | loading status | result | loading
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment