Commit 4743499a authored by Illya Klymov's avatar Illya Klymov

Merge branch...

Merge branch '227809-replace-timeago-mixin-with-timeago_tooltip-component-in-dashboard-compliance' into 'master'

Update compliance dashboard to use time_ago_tooltip

Closes #227809

See merge request gitlab-org/gitlab!38909
parents 8b384988 703f27bb
<script> <script>
import { GlTooltipDirective } from '@gitlab/ui'; import { GlSprintf } from '@gitlab/ui';
import { sprintf, __ } from '~/locale'; import { __ } from '~/locale';
import timeagoMixin from '~/vue_shared/mixins/timeago'; import TimeAgoTooltip from '~/vue_shared/components/time_ago_tooltip.vue';
import Approvers from './approvers.vue'; import Approvers from './approvers.vue';
import BranchDetails from './branch_details.vue'; import BranchDetails from './branch_details.vue';
...@@ -12,18 +12,16 @@ import Pagination from '../shared/pagination.vue'; ...@@ -12,18 +12,16 @@ import Pagination from '../shared/pagination.vue';
import Status from './status.vue'; import Status from './status.vue';
export default { export default {
directives: {
GlTooltip: GlTooltipDirective,
},
components: { components: {
Approvers, Approvers,
BranchDetails, BranchDetails,
GlSprintf,
GridColumnHeading, GridColumnHeading,
MergeRequest, MergeRequest,
Pagination, Pagination,
Status, Status,
TimeAgoTooltip,
}, },
mixins: [timeagoMixin],
props: { props: {
mergeRequests: { mergeRequests: {
type: Array, type: Array,
...@@ -39,21 +37,14 @@ export default { ...@@ -39,21 +37,14 @@ export default {
key(id, value) { key(id, value) {
return `${id}-${value}`; return `${id}-${value}`;
}, },
timeAgoString(mergedAt) {
return sprintf(__('merged %{timeAgo}'), {
timeAgo: this.timeFormatted(mergedAt),
});
},
timeTooltip(mergedAt) {
return this.tooltipTitle(mergedAt);
},
hasBranchDetails(mergeRequest) { hasBranchDetails(mergeRequest) {
return mergeRequest.target_branch && mergeRequest.source_branch; return mergeRequest.target_branch && mergeRequest.source_branch;
}, },
}, },
strings: { strings: {
mergeRequestLabel: __('Merge Request'),
approvalStatusLabel: __('Approval Status'), approvalStatusLabel: __('Approval Status'),
mergedAtText: __('merged %{timeAgo}'),
mergeRequestLabel: __('Merge Request'),
pipelineStatusLabel: __('Pipeline'), pipelineStatusLabel: __('Pipeline'),
updatesLabel: __('Updates'), updatesLabel: __('Updates'),
}, },
...@@ -106,11 +97,17 @@ export default { ...@@ -106,11 +97,17 @@ export default {
uri: mergeRequest.target_branch_uri, uri: mergeRequest.target_branch_uri,
}" }"
/> />
<span class="gl-text-gray-500"> <time-ago-tooltip
<time v-gl-tooltip.bottom="timeTooltip(mergeRequest.merged_at)">{{ :time="mergeRequest.merged_at"
timeAgoString(mergeRequest.merged_at) tooltip-placement="bottom"
}}</time> class="gl-text-gray-500"
</span> >
<template #default="{ timeAgo }">
<gl-sprintf :message="$options.strings.mergedAtText">
<template #timeAgo>{{ timeAgo }}</template>
</gl-sprintf>
</template>
</time-ago-tooltip>
</div> </div>
</template> </template>
</div> </div>
......
...@@ -47,13 +47,12 @@ exports[`MergeRequestsGrid component when intialized matches the snapshot 1`] = ...@@ -47,13 +47,12 @@ exports[`MergeRequestsGrid component when intialized matches the snapshot 1`] =
<!----> <!---->
<span <time-ago-tooltip-stub
class="gl-text-gray-500" class="gl-text-gray-500"
> cssclass=""
<time> time="2020-01-01T00:00:00.000Z"
merged 2 days ago tooltipplacement="bottom"
</time> />
</span>
</div> </div>
<div <div
data-testid="merge-request" data-testid="merge-request"
...@@ -78,13 +77,12 @@ exports[`MergeRequestsGrid component when intialized matches the snapshot 1`] = ...@@ -78,13 +77,12 @@ exports[`MergeRequestsGrid component when intialized matches the snapshot 1`] =
<!----> <!---->
<span <time-ago-tooltip-stub
class="gl-text-gray-500" class="gl-text-gray-500"
> cssclass=""
<time> time="2020-01-01T00:00:00.000Z"
merged 2 days ago tooltipplacement="bottom"
</time> />
</span>
</div> </div>
</div> </div>
......
import { shallowMount } from '@vue/test-utils'; import { shallowMount } from '@vue/test-utils';
import TimeAgoTooltip from '~/vue_shared/components/time_ago_tooltip.vue';
import Approvers from 'ee/compliance_dashboard/components/merge_requests/approvers.vue'; import Approvers from 'ee/compliance_dashboard/components/merge_requests/approvers.vue';
import BranchDetails from 'ee/compliance_dashboard/components/merge_requests/branch_details.vue'; import BranchDetails from 'ee/compliance_dashboard/components/merge_requests/branch_details.vue';
import MergeRequestsGrid from 'ee/compliance_dashboard/components/merge_requests/grid.vue'; import MergeRequestsGrid from 'ee/compliance_dashboard/components/merge_requests/grid.vue';
import Status from 'ee/compliance_dashboard/components/merge_requests/status.vue'; import Status from 'ee/compliance_dashboard/components/merge_requests/status.vue';
import { createMergeRequests } from '../../mock_data'; import { createMergeRequests, mergedAt } from '../../mock_data';
describe('MergeRequestsGrid component', () => { describe('MergeRequestsGrid component', () => {
let wrapper; let wrapper;
const findMergeRequests = () => wrapper.findAll('[data-testid="merge-request"]'); const findMergeRequests = () => wrapper.findAll('[data-testid="merge-request"]');
const findTime = () => wrapper.find('time'); const findTime = () => wrapper.find(TimeAgoTooltip);
const findStatuses = () => wrapper.findAll(Status); const findStatuses = () => wrapper.findAll(Status);
const findApprovers = () => wrapper.find(Approvers); const findApprovers = () => wrapper.find(Approvers);
const findBranchDetails = () => wrapper.find(BranchDetails); const findBranchDetails = () => wrapper.find(BranchDetails);
...@@ -91,7 +93,7 @@ describe('MergeRequestsGrid component', () => { ...@@ -91,7 +93,7 @@ describe('MergeRequestsGrid component', () => {
}); });
it('renders the "merged at" time', () => { it('renders the "merged at" time', () => {
expect(findTime().text()).toBe('merged 2 days ago'); expect(findTime().props('time')).toEqual(mergedAt());
}); });
}); });
}); });
const twoDaysAgo = () => {
const date = new Date();
date.setDate(date.getDate() - 2);
return date.toISOString();
};
const createUser = id => ({ const createUser = id => ({
id, id,
avatar_url: `https://${id}`, avatar_url: `https://${id}`,
...@@ -13,6 +7,15 @@ const createUser = id => ({ ...@@ -13,6 +7,15 @@ const createUser = id => ({
web_url: `http://localhost:3000/user-${id}`, web_url: `http://localhost:3000/user-${id}`,
}); });
export const mergedAt = () => {
const date = new Date();
date.setFullYear(2020, 0, 1);
date.setHours(0, 0, 0, 0);
return date.toISOString();
};
export const createPipelineStatus = status => ({ export const createPipelineStatus = status => ({
details_path: '/h5bp/html5-boilerplate/pipelines/58', details_path: '/h5bp/html5-boilerplate/pipelines/58',
favicon: '', favicon: '',
...@@ -30,7 +33,7 @@ export const createMergeRequest = ({ id = 1, props } = {}) => { ...@@ -30,7 +33,7 @@ export const createMergeRequest = ({ id = 1, props } = {}) => {
id, id,
approved_by_users: [], approved_by_users: [],
issuable_reference: '!1', issuable_reference: '!1',
merged_at: twoDaysAgo(), merged_at: mergedAt(),
milestone: null, milestone: null,
path: `/h5bp/html5-boilerplate/-/merge_requests/${id}`, path: `/h5bp/html5-boilerplate/-/merge_requests/${id}`,
title: `Merge request ${id}`, title: `Merge request ${id}`,
...@@ -44,13 +47,13 @@ export const createMergeRequest = ({ id = 1, props } = {}) => { ...@@ -44,13 +47,13 @@ export const createMergeRequest = ({ id = 1, props } = {}) => {
export const createApprovers = count => { export const createApprovers = count => {
return Array(count) return Array(count)
.fill() .fill(null)
.map((_, id) => createUser(id)); .map((_, id) => createUser(id));
}; };
export const createMergeRequests = ({ count = 1, props = {} } = {}) => { export const createMergeRequests = ({ count = 1, props = {} } = {}) => {
return Array(count) return Array(count)
.fill() .fill(null)
.map((_, id) => .map((_, id) =>
createMergeRequest({ createMergeRequest({
id, id,
......
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