AMBARI-21632 Alerts list not sorted by status even though header displayed as 
sorted. (ababiichuk)


Project: http://git-wip-us.apache.org/repos/asf/ambari/repo
Commit: http://git-wip-us.apache.org/repos/asf/ambari/commit/c4a474a5
Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/c4a474a5
Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/c4a474a5

Branch: refs/heads/branch-feature-AMBARI-14714
Commit: c4a474a5c4912bec226b56c62c80b6d77ebb497b
Parents: ed08865
Author: ababiichuk <ababiic...@hortonworks.com>
Authored: Wed Aug 2 12:16:54 2017 +0300
Committer: ababiichuk <ababiic...@hortonworks.com>
Committed: Wed Aug 2 12:16:54 2017 +0300

----------------------------------------------------------------------
 .../app/views/main/alert_definitions_view.js    |  5 +-
 .../views/main/alert_definitions_view_test.js   | 69 ++++++++++++++++++++
 2 files changed, 72 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ambari/blob/c4a474a5/ambari-web/app/views/main/alert_definitions_view.js
----------------------------------------------------------------------
diff --git a/ambari-web/app/views/main/alert_definitions_view.js 
b/ambari-web/app/views/main/alert_definitions_view.js
index a578c84..530bca7 100644
--- a/ambari-web/app/views/main/alert_definitions_view.js
+++ b/ambari-web/app/views/main/alert_definitions_view.js
@@ -28,10 +28,11 @@ App.MainAlertDefinitionsView = App.TableView.extend({
 
   contentObs: function () {
     Em.run.once(this, this.contentObsOnce);
-  }.observes('controller.content.[]'),
+  }.observes('controller.content.[]', 
'App.router.clusterController.isAlertsLoaded'),
 
   contentObsOnce: function() {
-    var content = this.get('controller.content') ? 
this.get('controller.content').toArray().sort(App.AlertDefinition.getSortDefinitionsByStatus(true))
 : [];
+    var content = this.get('controller.content') && 
App.get('router.clusterController.isAlertsLoaded') ?
+      
this.get('controller.content').toArray().sort(App.AlertDefinition.getSortDefinitionsByStatus(true))
 : [];
     this.set('content', content);
   },
 

http://git-wip-us.apache.org/repos/asf/ambari/blob/c4a474a5/ambari-web/test/views/main/alert_definitions_view_test.js
----------------------------------------------------------------------
diff --git a/ambari-web/test/views/main/alert_definitions_view_test.js 
b/ambari-web/test/views/main/alert_definitions_view_test.js
index 8692ae4..edba415 100644
--- a/ambari-web/test/views/main/alert_definitions_view_test.js
+++ b/ambari-web/test/views/main/alert_definitions_view_test.js
@@ -436,4 +436,73 @@ describe('App.MainAlertDefinitionsView', function () {
       expect(view.tooltipsUpdater.calledOnce).to.be.true;
     });
   });
+
+  describe('#contentObsOnce', function () {
+    var toArray = function () {
+        return [{}];
+      },
+      cases = [
+        {
+          controllerContent: null,
+          isAlertsLoaded: false,
+          content: [],
+          title: 'no content in controller, alerts data not loaded'
+        },
+        {
+          controllerContent: null,
+          isAlertsLoaded: true,
+          content: [],
+          title: 'no content in controller, alerts data loaded'
+        },
+        {
+          controllerContent: {
+            toArray: toArray
+          },
+          isAlertsLoaded: false,
+          content: [],
+          title: 'content set in controller, alerts data not loaded'
+        },
+        {
+          controllerContent: {
+            toArray: toArray
+          },
+          isAlertsLoaded: true,
+          content: [{}],
+          title: 'content set in controller, alerts data loaded'
+        }
+      ];
+
+    cases.forEach(function (item) {
+      describe(item.title, function () {
+        beforeEach(function () {
+          var controller = {
+            content: item.controllerContent
+          };
+          sinon.stub(App.AlertDefinition, 'getSortDefinitionsByStatus', 
function () {
+            return Em.K;
+          });
+          sinon.stub(view, 'contentObs', Em.K);
+          sinon.stub(App, 'get', function (key) {
+            if (key === 'router.clusterController.isAlertsLoaded') {
+              return item.isAlertsLoaded;
+            }
+            return Em.get(App, key);
+          });
+          view.set('controller', controller);
+          view.contentObsOnce();
+        });
+
+        afterEach(function () {
+          view.contentObs.restore();
+          App.get.restore();
+          App.AlertDefinition.getSortDefinitionsByStatus.restore();
+        });
+
+        it('view.content', function () {
+          expect(view.get('content')).to.eql(item.content);
+        });
+      });
+    });
+  });
+
 });

Reply via email to