2016-10-26 04:02:58 -04:00
|
|
|
/* eslint-disable */
|
2016-07-24 16:45:11 -04:00
|
|
|
/*= require merge_request_widget */
|
2016-10-04 10:03:13 -04:00
|
|
|
/*= require lib/utils/jquery.timeago.js */
|
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",
|
|
|
|
builds_path: "http://sampledomain.local/sampleBuildsPath"
|
|
|
|
};
|
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
|
|
|
|
|
|
|
spyOn(jQuery, 'getJSON').and.callFake((req, cb) => {
|
|
|
|
cb(this.ciEnvironmentsStatusData);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should call renderEnvironments when the environments property is set', function() {
|
|
|
|
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() {
|
2016-10-11 13:48:43 -04:00
|
|
|
this.ciEnvironmentsStatusData = null;
|
2016-10-07 18:10:06 -04:00
|
|
|
const spy = spyOn(this.class, 'renderEnvironments').and.stub();
|
|
|
|
this.class.getCIEnvironmentsStatus();
|
|
|
|
expect(spy).not.toHaveBeenCalled();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2016-07-24 16:45:11 -04:00
|
|
|
return describe('getCIStatus', function() {
|
|
|
|
beforeEach(function() {
|
2016-10-07 18:10:06 -04:00
|
|
|
this.ciStatusData = {
|
|
|
|
"title": "Sample MR title",
|
|
|
|
"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();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
}).call(this);
|