2017-01-11 22:49:57 -05:00
|
|
|
/* eslint-disable space-before-function-paren, quotes, comma-dangle, dot-notation, quote-props, no-var, max-len */
|
2016-11-23 00:47:52 -05:00
|
|
|
|
2017-01-09 18:23:54 -05:00
|
|
|
require('~/merge_request_widget');
|
2017-02-02 12:45:58 -05:00
|
|
|
require('~/smart_interval');
|
2017-01-09 18:23:54 -05:00
|
|
|
require('~/lib/utils/datetime_utility');
|
2016-07-24 16:45:11 -04:00
|
|
|
|
|
|
|
(function() {
|
|
|
|
describe('MergeRequestWidget', function() {
|
|
|
|
beforeEach(function() {
|
|
|
|
window.notifyPermissions = function() {};
|
|
|
|
window.notify = function() {};
|
|
|
|
this.opts = {
|
|
|
|
ci_status_url: "http://sampledomain.local/ci/getstatus",
|
2016-10-07 18:10:06 -04:00
|
|
|
ci_environments_status_url: "http://sampledomain.local/ci/getenvironmentsstatus",
|
2016-07-24 16:45:11 -04:00
|
|
|
ci_status: "",
|
|
|
|
ci_message: {
|
|
|
|
normal: "Build {{status}} for \"{{title}}\"",
|
|
|
|
preparing: "{{status}} build for \"{{title}}\""
|
|
|
|
},
|
|
|
|
ci_title: {
|
|
|
|
preparing: "{{status}} build",
|
|
|
|
normal: "Build {{status}}"
|
|
|
|
},
|
|
|
|
gitlab_icon: "gitlab_logo.png",
|
2016-12-28 11:53:05 -05:00
|
|
|
ci_pipeline: 80,
|
|
|
|
ci_sha: "12a34bc5",
|
|
|
|
builds_path: "http://sampledomain.local/sampleBuildsPath",
|
|
|
|
commits_path: "http://sampledomain.local/commits",
|
|
|
|
pipeline_path: "http://sampledomain.local/pipelines"
|
2016-07-24 16:45:11 -04:00
|
|
|
};
|
2016-10-04 10:03:13 -04:00
|
|
|
this["class"] = new window.gl.MergeRequestWidget(this.opts);
|
2016-07-24 16:45:11 -04:00
|
|
|
});
|
2016-10-07 18:10:06 -04:00
|
|
|
|
|
|
|
describe('getCIEnvironmentsStatus', function() {
|
|
|
|
beforeEach(function() {
|
2016-10-11 13:48:43 -04:00
|
|
|
this.ciEnvironmentsStatusData = [{
|
2016-10-07 18:10:06 -04:00
|
|
|
created_at: '2016-09-12T13:38:30.636Z',
|
|
|
|
environment_id: 1,
|
|
|
|
environment_name: 'env1',
|
|
|
|
external_url: 'https://test-url.com',
|
|
|
|
external_url_formatted: 'test-url.com'
|
2016-10-11 13:48:43 -04:00
|
|
|
}];
|
2016-10-07 18:10:06 -04:00
|
|
|
|
2016-11-18 23:47:10 -05:00
|
|
|
spyOn(jQuery, 'getJSON').and.callFake(function(req, cb) {
|
2016-10-07 18:10:06 -04:00
|
|
|
cb(this.ciEnvironmentsStatusData);
|
2016-11-18 23:47:10 -05:00
|
|
|
}.bind(this));
|
2016-10-07 18:10:06 -04:00
|
|
|
});
|
|
|
|
|
|
|
|
it('should call renderEnvironments when the environments property is set', function() {
|
2017-01-11 22:49:57 -05:00
|
|
|
const spy = spyOn(this.class, 'renderEnvironments').and.stub();
|
|
|
|
this.class.getCIEnvironmentsStatus();
|
|
|
|
expect(spy).toHaveBeenCalledWith(this.ciEnvironmentsStatusData);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should not call renderEnvironments when the environments property is not set', function() {
|
|
|
|
this.ciEnvironmentsStatusData = null;
|
|
|
|
const spy = spyOn(this.class, 'renderEnvironments').and.stub();
|
|
|
|
this.class.getCIEnvironmentsStatus();
|
|
|
|
expect(spy).not.toHaveBeenCalled();
|
|
|
|
});
|
2016-10-07 18:10:06 -04:00
|
|
|
});
|
|
|
|
|
2016-11-17 15:41:35 -05:00
|
|
|
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);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2016-11-25 09:09:50 -05:00
|
|
|
describe('mergeInProgress', function() {
|
2017-01-11 22:49:57 -05:00
|
|
|
it('should display error with h4 tag', function() {
|
|
|
|
spyOn(this.class.$widgetBody, 'html').and.callFake(function(html) {
|
|
|
|
expect(html).toBe('<h4>Sorry, something went wrong.</h4>');
|
|
|
|
});
|
|
|
|
spyOn($, 'ajax').and.callFake(function(e) {
|
|
|
|
e.success({ merge_error: 'Sorry, something went wrong.' });
|
2016-11-25 09:09:50 -05:00
|
|
|
});
|
2017-01-11 22:49:57 -05:00
|
|
|
this.class.mergeInProgress(null);
|
2016-11-25 09:09:50 -05:00
|
|
|
});
|
2017-01-11 22:49:57 -05:00
|
|
|
});
|
2016-11-25 09:09:50 -05:00
|
|
|
|
2016-12-28 11:53:05 -05:00
|
|
|
describe('getCIStatus', function() {
|
2016-07-24 16:45:11 -04:00
|
|
|
beforeEach(function() {
|
2016-10-07 18:10:06 -04:00
|
|
|
this.ciStatusData = {
|
|
|
|
"title": "Sample MR title",
|
2016-12-28 11:53:05 -05:00
|
|
|
"pipeline": 80,
|
2016-10-07 18:10:06 -04:00
|
|
|
"sha": "12a34bc5",
|
|
|
|
"status": "success",
|
|
|
|
"coverage": 98
|
|
|
|
};
|
|
|
|
|
2016-10-04 10:03:13 -04:00
|
|
|
spyOn(jQuery, 'getJSON').and.callFake((function(_this) {
|
2016-07-24 16:45:11 -04:00
|
|
|
return function(req, cb) {
|
|
|
|
return cb(_this.ciStatusData);
|
|
|
|
};
|
|
|
|
})(this));
|
|
|
|
});
|
|
|
|
it('should call showCIStatus even if a notification should not be displayed', function() {
|
|
|
|
var spy;
|
|
|
|
spy = spyOn(this["class"], 'showCIStatus').and.stub();
|
|
|
|
this["class"].getCIStatus(false);
|
|
|
|
return expect(spy).toHaveBeenCalledWith(this.ciStatusData.status);
|
|
|
|
});
|
|
|
|
it('should call showCIStatus when a notification should be displayed', function() {
|
|
|
|
var spy;
|
|
|
|
spy = spyOn(this["class"], 'showCIStatus').and.stub();
|
|
|
|
this["class"].getCIStatus(true);
|
|
|
|
return expect(spy).toHaveBeenCalledWith(this.ciStatusData.status);
|
|
|
|
});
|
|
|
|
it('should call showCICoverage when the coverage rate is set', function() {
|
|
|
|
var spy;
|
|
|
|
spy = spyOn(this["class"], 'showCICoverage').and.stub();
|
|
|
|
this["class"].getCIStatus(false);
|
|
|
|
return expect(spy).toHaveBeenCalledWith(this.ciStatusData.coverage);
|
|
|
|
});
|
|
|
|
it('should not call showCICoverage when the coverage rate is not set', function() {
|
|
|
|
var spy;
|
|
|
|
this.ciStatusData.coverage = null;
|
|
|
|
spy = spyOn(this["class"], 'showCICoverage').and.stub();
|
|
|
|
this["class"].getCIStatus(false);
|
|
|
|
return expect(spy).not.toHaveBeenCalled();
|
|
|
|
});
|
2016-10-04 10:03:13 -04:00
|
|
|
it('should not display a notification on the first check after the widget has been created', function() {
|
2016-07-24 16:45:11 -04:00
|
|
|
var spy;
|
|
|
|
spy = spyOn(window, 'notify');
|
2016-10-04 10:03:13 -04:00
|
|
|
this["class"] = new window.gl.MergeRequestWidget(this.opts);
|
2016-07-24 16:45:11 -04:00
|
|
|
this["class"].getCIStatus(true);
|
|
|
|
return expect(spy).not.toHaveBeenCalled();
|
|
|
|
});
|
2016-12-28 11:53:05 -05:00
|
|
|
it('should update the pipeline URL when the pipeline changes', function() {
|
|
|
|
var spy;
|
|
|
|
spy = spyOn(this["class"], 'updatePipelineUrls').and.stub();
|
|
|
|
this["class"].getCIStatus(false);
|
|
|
|
this.ciStatusData.pipeline += 1;
|
|
|
|
this["class"].getCIStatus(false);
|
|
|
|
return expect(spy).toHaveBeenCalled();
|
|
|
|
});
|
|
|
|
it('should update the commit URL when the sha changes', function() {
|
|
|
|
var spy;
|
|
|
|
spy = spyOn(this["class"], 'updateCommitUrls').and.stub();
|
|
|
|
this["class"].getCIStatus(false);
|
|
|
|
this.ciStatusData.sha = "9b50b99a";
|
|
|
|
this["class"].getCIStatus(false);
|
|
|
|
return expect(spy).toHaveBeenCalled();
|
|
|
|
});
|
2016-07-24 16:45:11 -04:00
|
|
|
});
|
|
|
|
});
|
|
|
|
}).call(this);
|