You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ambari.apache.org by am...@apache.org on 2017/12/22 09:10:11 UTC

[26/51] [abbrv] ambari git commit: AMBARI-22682 Ambari 3.0 Admin View: Add visual-search box to all pages. (atkach)

http://git-wip-us.apache.org/repos/asf/ambari/blob/81c04545/ambari-admin/src/main/resources/ui/admin-web/test/unit/controllers/userManagement/UsersListCtrl_test.js
----------------------------------------------------------------------
diff --git a/ambari-admin/src/main/resources/ui/admin-web/test/unit/controllers/userManagement/UsersListCtrl_test.js b/ambari-admin/src/main/resources/ui/admin-web/test/unit/controllers/userManagement/UsersListCtrl_test.js
index fcafa59..db91b56 100644
--- a/ambari-admin/src/main/resources/ui/admin-web/test/unit/controllers/userManagement/UsersListCtrl_test.js
+++ b/ambari-admin/src/main/resources/ui/admin-web/test/unit/controllers/userManagement/UsersListCtrl_test.js
@@ -33,312 +33,6 @@ describe('#Cluster', function () {
       });
     }));
 
-    describe('#clearFilters()', function () {
-
-      it('should clear filters and reset pagination', function () {
-        scope.currentPage = 2;
-        scope.filters.name = 'a';
-        scope.filters.status = {
-          label: $t('common.local'),
-          value: false
-        };
-        scope.filters.type = {
-          label: $t('common.local'),
-          value: 'LOCAL'
-        };
-        scope.clearFilters();
-        expect(scope.filters.name).toEqual('');
-        expect(scope.filters.status).toEqual({
-          label: $t('common.all'),
-          value: '*'
-        });
-        expect(scope.filters.type).toEqual({
-          label: $t('common.all'),
-          value: '*'
-        });
-        expect(scope.currentPage).toEqual(1);
-      });
-
-    });
-
-    describe('#isNotEmptyFilter', function () {
-
-      var cases = [
-        {
-          currentNameFilter: '',
-          currentTypeFilter: null,
-          currentActiveFilter: null,
-          isNotEmptyFilter: false,
-          title: 'no filters'
-        },
-        {
-          currentNameFilter: '',
-          currentTypeFilter: {
-            value: '*'
-          },
-          currentActiveFilter: {
-            value: '*'
-          },
-          isNotEmptyFilter: false,
-          title: 'empty filters'
-        },
-        {
-          currentNameFilter: 'a',
-          currentTypeFilter: {
-            value: '*'
-          },
-          currentActiveFilter: {
-            value: '*'
-          },
-          isNotEmptyFilter: true,
-          title: 'name filter'
-        },
-        {
-          currentNameFilter: '0',
-          currentTypeFilter: {
-            value: '*'
-          },
-          currentActiveFilter: {
-            value: '*'
-          },
-          isNotEmptyFilter: true,
-          title: 'name filter with "0" as string'
-        },
-        {
-          currentNameFilter: '',
-          currentTypeFilter: {
-            value: 'LOCAL'
-          },
-          currentActiveFilter: {
-            value: '*'
-          },
-          isNotEmptyFilter: true,
-          title: 'type filter'
-        },
-        {
-          currentNameFilter: '',
-          currentTypeFilter: {
-            value: '*'
-          },
-          currentActiveFilter: {
-            value: false
-          },
-          isNotEmptyFilter: true,
-          title: 'activity filter'
-        },
-        {
-          currentNameFilter: 'a',
-          currentTypeFilter: {
-            value: 'LOCAL'
-          },
-          currentActiveFilter: {
-            value: '*'
-          },
-          isNotEmptyFilter: true,
-          title: 'name and type filters'
-        },
-        {
-          currentNameFilter: 'a',
-          currentTypeFilter: {
-            value: '*'
-          },
-          currentActiveFilter: {
-            value: false
-          },
-          isNotEmptyFilter: true,
-          title: 'name and activity filters'
-        },
-        {
-          currentNameFilter: 'a',
-          currentTypeFilter: {
-            value: '*'
-          },
-          currentActiveFilter: {
-            value: '*'
-          },
-          isNotEmptyFilter: true,
-          title: 'name and admin filters'
-        },
-        {
-          currentNameFilter: '0',
-          currentTypeFilter: {
-            value: 'LOCAL'
-          },
-          currentActiveFilter: {
-            value: '*'
-          },
-          isNotEmptyFilter: true,
-          title: 'name and type filters with "0" as string'
-        },
-        {
-          currentNameFilter: '0',
-          currentTypeFilter: {
-            value: '*'
-          },
-          currentActiveFilter: {
-            value: false
-          },
-          isNotEmptyFilter: true,
-          title: 'name and activity filters with "0" as string'
-        },
-        {
-          currentNameFilter: '0',
-          currentTypeFilter: {
-            value: '*'
-          },
-          currentActiveFilter: {
-            value: '*'
-          },
-          isNotEmptyFilter: true,
-          title: 'name and admin filters with "0" as string'
-        },
-        {
-          currentNameFilter: '',
-          currentTypeFilter: {
-            value: 'LOCAL'
-          },
-          currentActiveFilter: {
-            value: false
-          },
-          isNotEmptyFilter: true,
-          title: 'type and activity filters'
-        },
-        {
-          currentNameFilter: '',
-          currentTypeFilter: {
-            value: 'LOCAL'
-          },
-          currentActiveFilter: {
-            value: '*'
-          },
-          isNotEmptyFilter: true,
-          title: 'type and admin filters'
-        },
-        {
-          currentNameFilter: '',
-          currentTypeFilter: {
-            value: '*'
-          },
-          currentActiveFilter: {
-            value: false
-          },
-          isNotEmptyFilter: true,
-          title: 'activity and admin filters'
-        },
-        {
-          currentNameFilter: '',
-          currentTypeFilter: {
-            value: 'LOCAL'
-          },
-          currentActiveFilter: {
-            value: false
-          },
-          isNotEmptyFilter: true,
-          title: 'all filters except name one'
-        },
-        {
-          currentNameFilter: 'a',
-          currentTypeFilter: {
-            value: '*'
-          },
-          currentActiveFilter: {
-            value: false
-          },
-          isNotEmptyFilter: true,
-          title: 'all filters except type one'
-        },
-        {
-          currentNameFilter: 'a',
-          currentTypeFilter: {
-            value: 'LOCAL'
-          },
-          currentActiveFilter: {
-            value: '*'
-          },
-          isNotEmptyFilter: true,
-          title: 'all filters except activity one'
-        },
-        {
-          currentNameFilter: 'a',
-          currentTypeFilter: {
-            value: 'LOCAL'
-          },
-          currentActiveFilter: {
-            value: false
-          },
-          isNotEmptyFilter: true,
-          title: 'all filters except admin one'
-        },
-        {
-          currentNameFilter: '0',
-          currentTypeFilter: {
-            value: '*'
-          },
-          currentActiveFilter: {
-            value: false
-          },
-          isNotEmptyFilter: true,
-          title: 'all filters with "0" as string except type one'
-        },
-        {
-          currentNameFilter: '0',
-          currentTypeFilter: {
-            value: 'LOCAL'
-          },
-          currentActiveFilter: {
-            value: '*'
-          },
-          isNotEmptyFilter: true,
-          title: 'all filters with "0" as string except activity one'
-        },
-        {
-          currentNameFilter: '0',
-          currentTypeFilter: {
-            value: 'LOCAL'
-          },
-          currentActiveFilter: {
-            value: false
-          },
-          isNotEmptyFilter: true,
-          title: 'all filters with "0" as string except admin one'
-        },
-        {
-          currentNameFilter: 'a',
-          currentTypeFilter: {
-            value: false
-          },
-          currentActiveFilter: {
-            value: 'LOCAL'
-          },
-          isNotEmptyFilter: true,
-          title: 'all filters'
-        },
-        {
-          currentNameFilter: '0',
-          currentTypeFilter: {
-            value: false
-          },
-          currentActiveFilter: {
-            value: 'LOCAL'
-          },
-          isNotEmptyFilter: true,
-          title: 'all filters with "0" as string'
-        }
-      ];
-
-      cases.forEach(function (item) {
-        it(item.title, function () {
-          $httpBackend.expectGET(/\/api\/v1\/users/).respond(200);
-          scope.filters.name = item.currentNameFilter;
-          scope.filters.status = item.currentActiveFilter;
-          scope.filters.type = item.currentTypeFilter;
-          scope.$digest();
-          expect(scope.isNotEmptyFilter).toEqual(item.isNotEmptyFilter);
-        });
-      });
-
-    });
-
   });
 
 });

http://git-wip-us.apache.org/repos/asf/ambari/blob/81c04545/ambari-admin/src/main/resources/ui/admin-web/test/unit/directives/comboSearch_test.js
----------------------------------------------------------------------
diff --git a/ambari-admin/src/main/resources/ui/admin-web/test/unit/directives/comboSearch_test.js b/ambari-admin/src/main/resources/ui/admin-web/test/unit/directives/comboSearch_test.js
index 9bc7083..0f4e3b3 100644
--- a/ambari-admin/src/main/resources/ui/admin-web/test/unit/directives/comboSearch_test.js
+++ b/ambari-admin/src/main/resources/ui/admin-web/test/unit/directives/comboSearch_test.js
@@ -135,19 +135,6 @@ describe('#comboSearch', function () {
 
   describe('#hideAutocomplete', function() {
 
-    it('showAutoComplete should be false when filter passed', function () {
-      var isoScope = element.isolateScope();
-      var filter = {
-        showAutoComplete: true
-      };
-      jasmine.Clock.useMock();
-
-      isoScope.hideAutocomplete(filter);
-
-      jasmine.Clock.tick(101);
-      expect(filter.showAutoComplete).toBeFalsy();
-    });
-
     it('showAutoComplete should be false when isEditing = false', function () {
       var isoScope = element.isolateScope();
       jasmine.Clock.useMock();

http://git-wip-us.apache.org/repos/asf/ambari/blob/81c04545/ambari-admin/src/main/resources/ui/admin-web/test/unit/services/Filters_test.js
----------------------------------------------------------------------
diff --git a/ambari-admin/src/main/resources/ui/admin-web/test/unit/services/Filters_test.js b/ambari-admin/src/main/resources/ui/admin-web/test/unit/services/Filters_test.js
new file mode 100644
index 0000000..a8b2924
--- /dev/null
+++ b/ambari-admin/src/main/resources/ui/admin-web/test/unit/services/Filters_test.js
@@ -0,0 +1,161 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+describe('Filters Service', function () {
+  var Filters;
+
+  beforeEach(function () {
+    module('ambariAdminConsole', angular.noop);
+    inject(function (_Filters_) {
+      Filters = _Filters_;
+    });
+  });
+  describe('#initFilterOptions', function() {
+    var items = [
+      {
+        k1: {
+          values: ['val1', 'val3']
+        },
+        k2: 'val2'
+      }
+    ];
+    var filters = [
+      {
+        isMultiple: true,
+        key: 'k1',
+        options: [],
+        customValueConverter: function(item) {
+          return item.k1.values;
+        }
+      },
+      {
+        key: 'k2',
+        options: []
+      },
+      {
+        isStatic: true,
+        options: [
+          {
+            key: 'static1',
+            label: 'static1'
+          }
+        ]
+      }
+    ];
+    beforeEach(function() {
+      Filters.initFilterOptions(filters, items);
+    });
+
+    it('should set static options of filters', function() {
+      expect(filters[2].options).toEqual([{
+        key: 'static1',
+        label: 'static1'
+      }]);
+    });
+
+    it('should set options of filters', function() {
+      expect(filters[1].options).toEqual([{
+        key: 'val2',
+        label: 'val2'
+      }]);
+    });
+
+    it('should set multiple options of filters', function() {
+      expect(filters[0].options).toEqual([
+        {
+          key: 'val1',
+          label: 'val1'
+        },
+        {
+          key: 'val3',
+          label: 'val3'
+        }
+      ]);
+    });
+  });
+
+  describe('#filterItems', function() {
+
+    it('all items should be filtered when no filters applied', function() {
+      var items = [{}];
+
+      expect(Filters.filterItems(null, items, [])).toEqual(1);
+      expect(items[0].isFiltered).toBeTruthy();
+    });
+
+    it('items should be filtered when simple filter applied', function() {
+      var appliedFilters = [
+        {
+          key: 'p1',
+          values: ['val1']
+        }
+      ];
+      var items = [
+        { p1: 'val1' },
+        { p1: 'val2' }
+      ];
+      var filterDefinitions = [];
+
+      expect(Filters.filterItems(appliedFilters, items, filterDefinitions)).toEqual(1);
+      expect(items[0].isFiltered).toBeTruthy();
+      expect(items[1].isFiltered).toBeFalsy();
+    });
+
+    it('items should be filtered when filter applied on array values', function() {
+      var appliedFilters = [
+        {
+          key: 'p1',
+          values: ['a']
+        }
+      ];
+      var items = [
+        { p1: ['a', 'b'] },
+        { p1: ['c', 'b'] }
+      ];
+      var filterDefinitions = [];
+
+      expect(Filters.filterItems(appliedFilters, items, filterDefinitions)).toEqual(1);
+      expect(items[0].isFiltered).toBeTruthy();
+      expect(items[1].isFiltered).toBeFalsy();
+    });
+
+    it('items should be filtered when custom filter applied', function() {
+      var appliedFilters = [
+        {
+          key: 'p1',
+          values: ['a']
+        }
+      ];
+      var items = [
+        { p1: { customValue: 'a' } },
+        { p1: { customValue: 'b' } }
+      ];
+      var filterDefinitions = [{
+        key: 'p1',
+        customValueConverter: function(item) {
+          return item.p1.customValue;
+        }
+      }];
+
+      expect(Filters.filterItems(appliedFilters, items, filterDefinitions)).toEqual(1);
+      expect(items[0].isFiltered).toBeTruthy();
+      expect(items[1].isFiltered).toBeFalsy();
+    });
+  });
+
+});

http://git-wip-us.apache.org/repos/asf/ambari/blob/81c04545/ambari-admin/src/main/resources/ui/admin-web/test/unit/services/Pagination_test.js
----------------------------------------------------------------------
diff --git a/ambari-admin/src/main/resources/ui/admin-web/test/unit/services/Pagination_test.js b/ambari-admin/src/main/resources/ui/admin-web/test/unit/services/Pagination_test.js
new file mode 100644
index 0000000..ce6cb52
--- /dev/null
+++ b/ambari-admin/src/main/resources/ui/admin-web/test/unit/services/Pagination_test.js
@@ -0,0 +1,72 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+describe('Pagination Service', function () {
+  var Pagination, $pagination;
+
+  beforeEach(function () {
+    module('ambariAdminConsole', angular.noop);
+    inject(function (_Pagination_) {
+      Pagination = _Pagination_;
+      $pagination = Pagination.create({
+        itemsPerPage: 1
+      });
+    });
+  });
+
+  describe('#pageChanged', function() {
+
+    it('should show items on second page', function() {
+      var items = [
+        { isFiltered: true },
+        { isFiltered: true },
+        { isFiltered: true }
+      ];
+      var tableInfo = {
+        showed: 0
+      };
+      $pagination.currentPage = 2;
+      $pagination.pageChanged(items, tableInfo);
+      expect(items[0].isShowed).toBeFalsy();
+      expect(items[1].isShowed).toBeTruthy();
+      expect(items[2].isShowed).toBeFalsy();
+      expect(tableInfo.showed).toEqual(1);
+    });
+  });
+
+  describe('#resetPagination', function() {
+
+    it('should show items on first page', function() {
+      var items = [
+        { isFiltered: true },
+        { isFiltered: true },
+        { isFiltered: true }
+      ];
+      var tableInfo = {
+        showed: 0
+      };
+      $pagination.currentPage = 2;
+      $pagination.resetPagination(items, tableInfo);
+      expect(items[0].isShowed).toBeTruthy();
+      expect(items[1].isShowed).toBeFalsy();
+      expect(items[2].isShowed).toBeFalsy();
+      expect(tableInfo.showed).toEqual(1);
+    });
+  });
+
+});