Repository: ambari Updated Branches: refs/heads/trunk f582b59a9 -> cb95f1c60
AMBARI-8773. Create unit test for repo version subversion input. (Richard Zang via yusaku) Project: http://git-wip-us.apache.org/repos/asf/ambari/repo Commit: http://git-wip-us.apache.org/repos/asf/ambari/commit/cb95f1c6 Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/cb95f1c6 Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/cb95f1c6 Branch: refs/heads/trunk Commit: cb95f1c6004b1ea5a0fa430bfc8069b676914f13 Parents: f582b59 Author: Yusaku Sako <[email protected]> Authored: Mon Dec 22 16:19:20 2014 -0800 Committer: Yusaku Sako <[email protected]> Committed: Mon Dec 22 16:19:20 2014 -0800 ---------------------------------------------------------------------- .../stackVersions/StackVersionsCreateCtrl.js | 5 +- .../app/views/stackVersions/create.html | 2 +- .../StackVersionsCreateCtrl_test.js | 56 ++++++++++++++++++++ 3 files changed, 60 insertions(+), 3 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/ambari/blob/cb95f1c6/ambari-admin/src/main/resources/ui/admin-web/app/scripts/controllers/stackVersions/StackVersionsCreateCtrl.js ---------------------------------------------------------------------- diff --git a/ambari-admin/src/main/resources/ui/admin-web/app/scripts/controllers/stackVersions/StackVersionsCreateCtrl.js b/ambari-admin/src/main/resources/ui/admin-web/app/scripts/controllers/stackVersions/StackVersionsCreateCtrl.js index 99a6a1a..4a27003 100644 --- a/ambari-admin/src/main/resources/ui/admin-web/app/scripts/controllers/stackVersions/StackVersionsCreateCtrl.js +++ b/ambari-admin/src/main/resources/ui/admin-web/app/scripts/controllers/stackVersions/StackVersionsCreateCtrl.js @@ -20,12 +20,13 @@ angular.module('ambariAdminConsole') .controller('StackVersionsCreateCtrl', ['$scope', 'Stack', '$routeParams', '$location', 'Alert', function($scope, Stack, $routeParams, $location, Alert) { $scope.clusterName = $routeParams.clusterName; + $scope.subversionPattern = /^\d(\.\d)?(\-\d*)?$/; $scope.upgradeStack = { selected: null, options: [] }; $scope.fetchStackVersionFilterList = function () { - Stack.allStackVersions() + return Stack.allStackVersions() .then(function (allStackVersions) { var versions = []; angular.forEach(allStackVersions, function (version) { @@ -84,7 +85,7 @@ angular.module('ambariAdminConsole') }; $scope.create = function () { - Stack.addRepo($scope.upgradeStack.selected, $scope.repoSubversion, $scope.repositories) + return Stack.addRepo($scope.upgradeStack.selected, $scope.repoSubversion, $scope.repositories) .success(function () { var versionName = $scope.upgradeStack.selected.stack_version + '.' + $scope.repoSubversion; var stackName = $scope.upgradeStack.selected.stack_name; http://git-wip-us.apache.org/repos/asf/ambari/blob/cb95f1c6/ambari-admin/src/main/resources/ui/admin-web/app/views/stackVersions/create.html ---------------------------------------------------------------------- diff --git a/ambari-admin/src/main/resources/ui/admin-web/app/views/stackVersions/create.html b/ambari-admin/src/main/resources/ui/admin-web/app/views/stackVersions/create.html index b4487db..c2fc3c3 100644 --- a/ambari-admin/src/main/resources/ui/admin-web/app/views/stackVersions/create.html +++ b/ambari-admin/src/main/resources/ui/admin-web/app/views/stackVersions/create.html @@ -37,7 +37,7 @@ <span class="bold-dot">.</span> </div> <div class="form-group col-sm-6" ng-class="{'has-error' : repoRegForm.version.$error.pattern}"> - <input class="form-control" name="version" type="text" ng-model="repoSubversion" ng-pattern="/^\d(\.\d)?(\-\d*)?$/" + <input class="form-control" name="version" type="text" ng-model="repoSubversion" ng-pattern="subversionPattern" placeholder="Version Name" required/> <span class="text-primary" ng-show="!repoRegForm.version.$error.pattern"> {{upgradeStack.selected.displayName + '.' + repoSubversion}}</span> <span class="text-danger" ng-show="repoRegForm.version.$error.pattern">Invalid subversion. eg: 1.0-123</span> http://git-wip-us.apache.org/repos/asf/ambari/blob/cb95f1c6/ambari-admin/src/main/resources/ui/admin-web/test/unit/controllers/stackVersions/StackVersionsCreateCtrl_test.js ---------------------------------------------------------------------- diff --git a/ambari-admin/src/main/resources/ui/admin-web/test/unit/controllers/stackVersions/StackVersionsCreateCtrl_test.js b/ambari-admin/src/main/resources/ui/admin-web/test/unit/controllers/stackVersions/StackVersionsCreateCtrl_test.js new file mode 100644 index 0000000..abae72a --- /dev/null +++ b/ambari-admin/src/main/resources/ui/admin-web/test/unit/controllers/stackVersions/StackVersionsCreateCtrl_test.js @@ -0,0 +1,56 @@ +/** + * 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('#Cluster', function () { + describe('StackVersionsCreateCtrl', function() { + var scope, ctrl; + + beforeEach(module('ambariAdminConsole', function($provide) {})); + beforeEach(inject(function($rootScope, $controller) { + scope = $rootScope.$new(); + ctrl = $controller('StackVersionsCreateCtrl', {$scope: scope}); + })); + + describe('Test repository subversion input validation', function () { + it('1 digit', function() { + var input = "1"; + var invalidInput = "11"; + var regex = scope.subversionPattern; + expect(regex.test(input)).toBe(true); + expect(regex.test(invalidInput)).toBe(false); + }); + + it('1 digit dot 1 digit', function() { + var input = "1.2"; + var invalidInput = "1.22"; + var regex = scope.subversionPattern; + expect(regex.test(input)).toBe(true); + expect(regex.test(invalidInput)).toBe(false); + }); + + it('1 digit dot 1 digit dash 3 digits', function() { + var input = "1.2-345"; + var invalidInput = "1.1-abc"; + var regex = scope.subversionPattern; + expect(regex.test(input)).toBe(true); + expect(regex.test(invalidInput)).toBe(false); + }); + + }); + }); +});
