Repository: ambari
Updated Branches:
  refs/heads/branch-2.5 7c6f754e9 -> 963d7c612


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/963d7c61
Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/963d7c61
Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/963d7c61

Branch: refs/heads/branch-2.5
Commit: 963d7c61262a37f3166e59d1d97ee2e19915302b
Parents: 7c6f754
Author: ababiichuk <ababiic...@hortonworks.com>
Authored: Wed Aug 2 12:19:21 2017 +0300
Committer: ababiichuk <ababiic...@hortonworks.com>
Committed: Wed Aug 2 12:19:21 2017 +0300

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


http://git-wip-us.apache.org/repos/asf/ambari/blob/963d7c61/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 6e8c21e..9fb517f 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/963d7c61/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 704cde4..a571a6e 100644
--- a/ambari-web/test/views/main/alert_definitions_view_test.js
+++ b/ambari-web/test/views/main/alert_definitions_view_test.js
@@ -86,4 +86,72 @@ describe('App.MainAlertDefinitionsView', function () {
     });
   });
 
+  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