]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-5851 fix profile restoring
authorStas Vilchik <vilchiks@gmail.com>
Fri, 17 Apr 2015 09:00:50 +0000 (11:00 +0200)
committerStas Vilchik <vilchiks@gmail.com>
Fri, 17 Apr 2015 09:32:33 +0000 (11:32 +0200)
server/sonar-web/src/main/js/quality-profiles/restore-profile-view.js
server/sonar-web/src/test/js/quality-profiles.js

index 75b7a735cddb2dd91430d1c3b537312fb7ed7e5f..24f7ae3409ba2b71499e74bc088ce34b474206d9 100644 (file)
@@ -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);
+      }
     }
   });
 
index 441c11f14e04f8bad1fa548552fc35e4d0dced81..04e2632639c566cb30b7b8d7061845145a04d50e 100644 (file)
@@ -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 () {