From: Stas Vilchik Date: Fri, 17 Apr 2015 09:00:50 +0000 (+0200) Subject: SONAR-5851 fix profile restoring X-Git-Tag: 5.2-RC1~2238 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=b07a2570e213f7919b69b4a2d43ed327f7f3d938;p=sonarqube.git SONAR-5851 fix profile restoring --- diff --git a/server/sonar-web/src/main/js/quality-profiles/restore-profile-view.js b/server/sonar-web/src/main/js/quality-profiles/restore-profile-view.js index 75b7a735cdd..24f7ae3409b 100644 --- a/server/sonar-web/src/main/js/quality-profiles/restore-profile-view.js +++ b/server/sonar-web/src/main/js/quality-profiles/restore-profile-view.js @@ -20,8 +20,9 @@ define([ 'common/modal-form', 'common/file-upload', + 'quality-profiles/profile', 'templates/quality-profiles' -], function (ModalFormView, uploader) { +], function (ModalFormView, uploader, Profile) { var $ = jQuery; @@ -31,21 +32,23 @@ define([ 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); + } } }); diff --git a/server/sonar-web/src/test/js/quality-profiles.js b/server/sonar-web/src/test/js/quality-profiles.js index 441c11f14e0..04e2632639c 100644 --- a/server/sonar-web/src/test/js/quality-profiles.js +++ b/server/sonar-web/src/test/js/quality-profiles.js @@ -566,6 +566,53 @@ casper.test.begin(testName('Create Profile'), 2, function (test) { }); +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 () {