Commit 015aa1fc authored by Simon Knox's avatar Simon Knox

Merge branch 'fix-epic-date-change-without-user-input' into 'master'

Fix epic date changes without user input

See merge request gitlab-org/gitlab!75817
parents 7e0e61ea 813257fd
...@@ -124,6 +124,9 @@ export default { ...@@ -124,6 +124,9 @@ export default {
isLoading() { isLoading() {
return this.$apollo.queries.issuable.loading || this.loading; return this.$apollo.queries.issuable.loading || this.loading;
}, },
initialLoading() {
return this.$apollo.queries.issuable.loading;
},
hasDate() { hasDate() {
return this.dateValue !== null; return this.dateValue !== null;
}, },
...@@ -271,10 +274,10 @@ export default { ...@@ -271,10 +274,10 @@ export default {
<span class="collapse-truncated-title">{{ formattedDate }}</span> <span class="collapse-truncated-title">{{ formattedDate }}</span>
</div> </div>
<sidebar-inherit-date <sidebar-inherit-date
v-if="canInherit" v-if="canInherit && !initialLoading"
:issuable="issuable" :issuable="issuable"
:is-loading="isLoading"
:date-type="dateType" :date-type="dateType"
:is-loading="isLoading"
@reset-date="setDate(null)" @reset-date="setDate(null)"
@set-date="setFixedDate" @set-date="setFixedDate"
/> />
......
...@@ -17,8 +17,9 @@ export default { ...@@ -17,8 +17,9 @@ export default {
type: Object, type: Object,
}, },
isLoading: { isLoading: {
required: true, required: false,
type: Boolean, type: Boolean,
default: false,
}, },
dateType: { dateType: {
type: String, type: String,
...@@ -31,6 +32,7 @@ export default { ...@@ -31,6 +32,7 @@ export default {
return this.issuable?.[dateFields[this.dateType].isDateFixed] || false; return this.issuable?.[dateFields[this.dateType].isDateFixed] || false;
}, },
set(fixed) { set(fixed) {
if (fixed === this.issuable[dateFields[this.dateType].isDateFixed]) return;
this.$emit('set-date', fixed); this.$emit('set-date', fixed);
}, },
}, },
......
...@@ -145,13 +145,20 @@ describe('Sidebar date Widget', () => { ...@@ -145,13 +145,20 @@ describe('Sidebar date Widget', () => {
${false} | ${SidebarInheritDate} | ${'SidebarInheritDate'} | ${false} ${false} | ${SidebarInheritDate} | ${'SidebarInheritDate'} | ${false}
`( `(
'when canInherit is $canInherit, $componentName display is $expected', 'when canInherit is $canInherit, $componentName display is $expected',
({ canInherit, component, expected }) => { async ({ canInherit, component, expected }) => {
createComponent({ canInherit }); createComponent({ canInherit });
await waitForPromises();
expect(wrapper.find(component).exists()).toBe(expected); expect(wrapper.find(component).exists()).toBe(expected);
}, },
); );
it('does not render SidebarInheritDate when canInherit is true and date is loading', async () => {
createComponent({ canInherit: true });
expect(wrapper.find(SidebarInheritDate).exists()).toBe(false);
});
it('displays a flash message when query is rejected', async () => { it('displays a flash message when query is rejected', async () => {
createComponent({ createComponent({
dueDateQueryHandler: jest.fn().mockRejectedValue('Houston, we have a problem'), dueDateQueryHandler: jest.fn().mockRejectedValue('Houston, we have a problem'),
......
...@@ -10,7 +10,7 @@ describe('SidebarInheritDate', () => { ...@@ -10,7 +10,7 @@ describe('SidebarInheritDate', () => {
const findFixedRadio = () => wrapper.findAll(GlFormRadio).at(0); const findFixedRadio = () => wrapper.findAll(GlFormRadio).at(0);
const findInheritRadio = () => wrapper.findAll(GlFormRadio).at(1); const findInheritRadio = () => wrapper.findAll(GlFormRadio).at(1);
const createComponent = () => { const createComponent = ({ dueDateIsFixed = false } = {}) => {
wrapper = shallowMount(SidebarInheritDate, { wrapper = shallowMount(SidebarInheritDate, {
provide: { provide: {
canUpdate: true, canUpdate: true,
...@@ -18,11 +18,10 @@ describe('SidebarInheritDate', () => { ...@@ -18,11 +18,10 @@ describe('SidebarInheritDate', () => {
propsData: { propsData: {
issuable: { issuable: {
dueDate: '2021-04-15', dueDate: '2021-04-15',
dueDateIsFixed: true, dueDateIsFixed,
dueDateFixed: '2021-04-15', dueDateFixed: '2021-04-15',
dueDateFromMilestones: '2021-05-15', dueDateFromMilestones: '2021-05-15',
}, },
isLoading: false,
dateType: 'dueDate', dateType: 'dueDate',
}, },
}); });
...@@ -45,6 +44,13 @@ describe('SidebarInheritDate', () => { ...@@ -45,6 +44,13 @@ describe('SidebarInheritDate', () => {
expect(findInheritRadio().text()).toBe('Inherited:'); expect(findInheritRadio().text()).toBe('Inherited:');
}); });
it('does not emit set-date if fixed value does not change', () => {
createComponent({ dueDateIsFixed: true });
findFixedRadio().vm.$emit('input', true);
expect(wrapper.emitted('set-date')).toBeUndefined();
});
it('emits set-date event on click on radio button', () => { it('emits set-date event on click on radio button', () => {
findFixedRadio().vm.$emit('input', true); findFixedRadio().vm.$emit('input', true);
......
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