define([
'common/modal-form',
'common/file-upload',
+ 'quality-profiles/profile',
'templates/quality-profiles'
-], function (ModalFormView, uploader) {
+], function (ModalFormView, uploader, Profile) {
var $ = jQuery;
onFormSubmit: function (e) {
var that = this;
ModalFormView.prototype.onFormSubmit.apply(this, arguments);
- this.disableForm();
uploader({ form: $(e.currentTarget) }).done(function (r) {
if (_.isArray(r.errors) || _.isArray(r.warnings)) {
that.showErrors(r.errors, r.warnings);
- that.enableForm();
} else {
- that.collection.fetch().done(function () {
- var profile = that.collection.findWhere({ key: r.profile.key });
- if (profile != null) {
- profile.trigger('select', profile);
- }
- });
+ that.addProfile(r.profile);
that.close();
}
});
+ },
+
+ addProfile: function (profileData) {
+ var profile = new Profile(profileData);
+ this.collection.add([profile], { merge: true });
+ var addedProfile = this.collection.get(profile.id);
+ if (addedProfile != null) {
+ addedProfile.trigger('select', addedProfile);
+ }
}
});
});
+casper.test.begin(testName('Restore Profile'), 2, function (test) {
+ casper
+ .start(lib.buildUrl('profiles'), function () {
+ lib.setDefaultViewport();
+
+ lib.mockRequestFromFile('/api/users/current', 'user-admin.json');
+ this.searchMock = lib.mockRequestFromFile('/api/qualityprofiles/search', 'search.json');
+ lib.mockRequestFromFile('/api/rules/search', 'rules.json');
+ lib.mockRequestFromFile('/api/qualityprofiles/inheritance', 'inheritance.json');
+ })
+
+ .then(function () {
+ casper.evaluate(function () {
+ require(['/js/quality-profiles/app.js']);
+ jQuery.ajaxSetup({ dataType: 'json' });
+ });
+ })
+
+ .then(function () {
+ casper.waitForSelector('.js-list .list-group-item');
+ })
+
+ .then(function () {
+ test.assertElementCount('.js-list .list-group-item', 5);
+ casper.click('#quality-profiles-restore');
+ casper.waitForSelector('.modal');
+ })
+
+ .then(function () {
+ casper.click('#restore-profile-submit');
+ lib.waitForElementCount('.js-list .list-group-item', 6);
+ })
+
+ .then(function () {
+ test.assert(true);
+ })
+
+ .then(function () {
+ lib.sendCoverage();
+ })
+
+ .run(function () {
+ test.done();
+ });
+});
+
+
casper.test.begin(testName('Importers'), 6, function (test) {
casper
.start(lib.buildUrl('profiles'), function () {