Commit 7cd2b75c authored by Filipa Lacerda's avatar Filipa Lacerda

Merge branch 'mr-widget-merged-date-tooltip' into 'master'

Fixes merge request widget date tooltip inconsistencies

Closes #38545

See merge request gitlab-org/gitlab-ce!14578
parents 7dbdc983 775c9f68
......@@ -16,9 +16,9 @@ export default {
<div class="media-body">
<mr-widget-author-and-time
actionText="Closed by"
:author="mr.closedBy"
:dateTitle="mr.updatedAt"
:dateReadable="mr.closedAt"
:author="mr.closedEvent.author"
:dateTitle="mr.closedEvent.updatedAt"
:dateReadable="mr.closedEvent.formattedUpdatedAt"
/>
<section class="mr-info-list">
<p>
......
......@@ -69,9 +69,9 @@ export default {
<div class="space-children">
<mr-widget-author-and-time
actionText="Merged by"
:author="mr.mergedBy"
:dateTitle="mr.updatedAt"
:dateReadable="mr.mergedAt" />
:author="mr.mergedEvent.author"
:date-title="mr.mergedEvent.updatedAt"
:date-readable="mr.mergedEvent.formattedUpdatedAt" />
<a
v-if="mr.canRevertInCurrentMR"
v-tooltip
......
......@@ -37,10 +37,8 @@ export default class MergeRequestStore {
}
this.updatedAt = data.updated_at;
this.mergedAt = MergeRequestStore.getEventDate(data.merge_event);
this.closedAt = MergeRequestStore.getEventDate(data.closed_event);
this.mergedBy = MergeRequestStore.getAuthorObject(data.merge_event);
this.closedBy = MergeRequestStore.getAuthorObject(data.closed_event);
this.mergedEvent = MergeRequestStore.getEventObject(data.merge_event);
this.closedEvent = MergeRequestStore.getEventObject(data.closed_event);
this.setToMWPSBy = MergeRequestStore.getAuthorObject({ author: data.merge_user || {} });
this.mergeUserId = data.merge_user_id;
this.currentUserId = gon.current_user_id;
......@@ -120,6 +118,14 @@ export default class MergeRequestStore {
}
}
static getEventObject(event) {
return {
author: MergeRequestStore.getAuthorObject(event),
updatedAt: gl.utils.formatDate(MergeRequestStore.getEventUpdatedAtDate(event)),
formattedUpdatedAt: MergeRequestStore.getEventDate(event),
};
}
static getAuthorObject(event) {
if (!event) {
return {};
......@@ -133,6 +139,14 @@ export default class MergeRequestStore {
};
}
static getEventUpdatedAtDate(event) {
if (!event) {
return '';
}
return event.updated_at;
}
static getEventDate(event) {
const timeagoInstance = new Timeago();
......@@ -140,7 +154,7 @@ export default class MergeRequestStore {
return '';
}
return timeagoInstance.format(event.updated_at);
return timeagoInstance.format(MergeRequestStore.getEventUpdatedAtDate(event));
}
}
---
title: Fixed merge request widget merged & closed date tooltip text
merge_request:
author:
type: fixed
......@@ -4,11 +4,15 @@ import closedComponent from '~/vue_merge_request_widget/components/states/mr_wid
const mr = {
targetBranch: 'good-branch',
targetBranchPath: '/good-branch',
closedBy: {
closedEvent: {
author: {
name: 'Fatih Acet',
username: 'fatihacet',
},
updatedAt: '2017-03-23T20:08:08.845Z',
updatedAt: 'closedEventUpdatedAt',
formattedUpdatedAt: '',
},
updatedAt: 'mrUpdatedAt',
closedAt: '1 day ago',
};
......@@ -18,7 +22,7 @@ const createComponent = () => {
return new Component({
el: document.createElement('div'),
propsData: { mr },
}).$el;
});
};
describe('MRWidgetClosed', () => {
......@@ -38,14 +42,30 @@ describe('MRWidgetClosed', () => {
});
describe('template', () => {
it('should have correct elements', () => {
const el = createComponent();
let vm;
let el;
beforeEach(() => {
vm = createComponent();
el = vm.$el;
});
afterEach(() => {
vm.$destroy();
});
it('should have correct elements', () => {
expect(el.querySelector('h4').textContent).toContain('Closed by');
expect(el.querySelector('h4').textContent).toContain(mr.closedBy.name);
expect(el.querySelector('h4').textContent).toContain(mr.closedEvent.author.name);
expect(el.textContent).toContain('The changes were not merged into');
expect(el.querySelector('.label-branch').getAttribute('href')).toEqual(mr.targetBranchPath);
expect(el.querySelector('.label-branch').textContent).toContain(mr.targetBranch);
});
it('should use closedEvent updatedAt as tooltip title', () => {
expect(
el.querySelector('time').getAttribute('title'),
).toBe('closedEventUpdatedAt');
});
});
});
......@@ -14,9 +14,12 @@ const createComponent = () => {
canRevertInCurrentMR: true,
canRemoveSourceBranch: true,
sourceBranchRemoved: true,
mergedBy: {},
mergedAt: '',
updatedAt: '',
mergedEvent: {
author: {},
updatedAt: 'mergedUpdatedAt',
formattedUpdatedAt: '',
},
updatedAt: 'mrUpdatedAt',
targetBranch,
};
......@@ -170,5 +173,11 @@ describe('MRWidgetMerged', () => {
done();
});
});
it('should use mergedEvent updatedAt as tooltip title', () => {
expect(
el.querySelector('time').getAttribute('title'),
).toBe('mergedUpdatedAt');
});
});
});
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