Przeglądaj źródła

AMBARI-14404. Ambari Admin: incorrect cluster filter behaviour on Versions page

Alex Antonenko 9 lat temu
rodzic
commit
2c7ecd12ec

+ 6 - 7
ambari-admin/src/main/resources/ui/admin-web/app/scripts/controllers/stackVersions/StackVersionsListCtrl.js

@@ -89,10 +89,8 @@ angular.module('ambariAdminConsole')
     });
   };
 
-  $scope.fillClusters = function (clusters) {
-    $scope.dropDownClusters = [].concat(clusters);
-    $scope.selectedCluster = $scope.dropDownClusters[0];
-    angular.forEach(clusters, function (cluster) {
+    $scope.fillClusters = function (clusters) {
+      $scope.dropDownClusters = [].concat(clusters);
       var options = [{label: "All", value: ''}];
       angular.forEach(clusters, function (cluster) {
         options.push({
@@ -101,9 +99,10 @@ angular.module('ambariAdminConsole')
         });
       });
       $scope.filter.cluster.options = options;
-      $scope.filter.cluster.current = options[0];
-    });
-  };
+      if (!$scope.filter.cluster.current) {
+        $scope.filter.cluster.current = options[0];
+      }
+    };
 
   $scope.fetchClusters = function () {
     return Cluster.getAllClusters().then(function (clusters) {

+ 1 - 1
ambari-admin/src/main/resources/ui/admin-web/app/views/stackVersions/list.html

@@ -41,7 +41,7 @@
         <select class="form-control"
                 ng-change="resetPagination()"
                 ng-model="filter.cluster.current"
-                ng-options="item.label for item in filter.cluster.options"
+                ng-options="item.label for item in filter.cluster.options track by item.value"
           ></select>
       </th>
       <th></th>

+ 50 - 3
ambari-admin/src/main/resources/ui/admin-web/test/unit/controllers/stackVersions/StackversionsListCtrl_test.js

@@ -29,10 +29,57 @@ describe('#Cluster', function () {
       ctrl = $controller('StackVersionsListCtrl', {$scope: scope});
     }));
 
-    it('saves list of stacks', function() {
-      scope.fetchRepos().then(function() {
-        expect(Array.isArray(scope.repos)).toBe(true);
+    describe('fetchRepos()', function () {
+
+      it('saves list of stacks', function() {
+        scope.fetchRepos().then(function() {
+          expect(Array.isArray(scope.repos)).toBe(true);
+        });
       });
+
     });
+
+    describe('fillClusters()', function () {
+
+      var clusters = [
+          {
+            Clusters: {
+              cluster_name: 'c0'
+            }
+          }
+        ],
+        cases = [
+          {
+            prev: null,
+            current: {
+              label: 'All',
+              value: ''
+            },
+            title: 'no cluster selected before'
+          },
+          {
+            prev: {
+              label: 'c0',
+              value: 'c0'
+            },
+            current: {
+              label: 'c0',
+              value: 'c0'
+            },
+            title: 'cluster was selected before'
+          }
+        ];
+
+      angular.forEach(cases, function (item) {
+        it(item.title, function() {
+          scope.filter.cluster.current = item.prev;
+          scope.fillClusters(clusters);
+          expect(scope.dropDownClusters).toEqual(clusters);
+          expect(scope.filter.cluster.current).toEqual(item.current);
+        });
+      });
+
+    });
+
   });
 });