Fix timeago rendering for environment timeago
This commit is contained in:
parent
18a646c388
commit
c520504610
|
@ -218,7 +218,7 @@
|
|||
}
|
||||
|
||||
if (environment.deployed_at && environment.deployed_at_formatted) {
|
||||
environment.deployed_at = gl.utils.getTimeago(environment.deployed_at) + '.';
|
||||
environment.deployed_at = gl.utils.getTimeago().format(environment.deployed_at, 'gl_en') + '.';
|
||||
} else {
|
||||
$('.js-environment-timeago', $template).remove();
|
||||
environment.name += '.';
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
/* eslint-disable space-before-function-paren, quotes, comma-dangle, dot-notation, indent, quote-props, no-var, padded-blocks, max-len */
|
||||
/*= require merge_request_widget */
|
||||
/*= require lib/utils/timeago.js */
|
||||
/*= require lib/utils/timeago */
|
||||
/*= require lib/utils/datetime_utility */
|
||||
|
||||
(function() {
|
||||
describe('MergeRequestWidget', function() {
|
||||
|
@ -54,6 +55,57 @@
|
|||
});
|
||||
});
|
||||
|
||||
describe('renderEnvironments', function() {
|
||||
describe('should render correct timeago', function() {
|
||||
beforeEach(function() {
|
||||
this.environments = [{
|
||||
id: 'test-environment-id',
|
||||
url: 'testurl',
|
||||
deployed_at: new Date().toISOString(),
|
||||
deployed_at_formatted: true
|
||||
}];
|
||||
});
|
||||
|
||||
function getTimeagoText(template) {
|
||||
var el = document.createElement('html');
|
||||
el.innerHTML = template;
|
||||
return el.querySelector('.js-environment-timeago').innerText.trim();
|
||||
}
|
||||
|
||||
it('should render less than a minute ago text', function() {
|
||||
spyOn(this.class.$widgetBody, 'before').and.callFake(function(template) {
|
||||
expect(getTimeagoText(template)).toBe('less than a minute ago.');
|
||||
});
|
||||
|
||||
this.class.renderEnvironments(this.environments);
|
||||
});
|
||||
|
||||
it('should render about an hour ago text', function() {
|
||||
var oneHourAgo = new Date();
|
||||
oneHourAgo.setHours(oneHourAgo.getHours() - 1);
|
||||
|
||||
this.environments[0].deployed_at = oneHourAgo.toISOString();
|
||||
spyOn(this.class.$widgetBody, 'before').and.callFake(function(template) {
|
||||
expect(getTimeagoText(template)).toBe('about an hour ago.');
|
||||
});
|
||||
|
||||
this.class.renderEnvironments(this.environments);
|
||||
});
|
||||
|
||||
it('should render about 2 hours ago text', function() {
|
||||
var twoHoursAgo = new Date();
|
||||
twoHoursAgo.setHours(twoHoursAgo.getHours() - 2);
|
||||
|
||||
this.environments[0].deployed_at = twoHoursAgo.toISOString();
|
||||
spyOn(this.class.$widgetBody, 'before').and.callFake(function(template) {
|
||||
expect(getTimeagoText(template)).toBe('about 2 hours ago.');
|
||||
});
|
||||
|
||||
this.class.renderEnvironments(this.environments);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
return describe('getCIStatus', function() {
|
||||
beforeEach(function() {
|
||||
this.ciStatusData = {
|
||||
|
|
Loading…
Reference in New Issue