-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Tendrl-bug-id: #911 Signed-off-by: a2batic <[email protected]>
- Loading branch information
Showing
11 changed files
with
1,342 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
describe("Unit Component: Add User", function() { | ||
"use strict"; | ||
|
||
// Angular injectables | ||
var $scope, $q, $httpBackend, $injector, $rootScope, $state, $templateCache, $compile, $interval, $destroy, $componentController, $event, $uibModal; | ||
|
||
// Module defined (non-Angular) injectables | ||
var config, utils, userStore, capitalizeFilter, Notifications; | ||
|
||
// Local variables used for testing | ||
var createUserDeferred, vm, clock, throttled, intervalSpy, timer, args, element; | ||
|
||
// Initialize modules | ||
beforeEach(function() { | ||
module("TendrlModule"); | ||
module("TestDataModule"); | ||
module("templates"); | ||
}); | ||
|
||
beforeEach(function() { | ||
|
||
var templateHtml; | ||
|
||
inject(function(_$q_, _$componentController_, _$rootScope_, _$state_, _$templateCache_, _$compile_, _$interval_, _$uibModal_) { | ||
$q = _$q_; | ||
$componentController = _$componentController_; | ||
$rootScope = _$rootScope_; | ||
$state = _$state_; | ||
$templateCache = _$templateCache_; | ||
$compile = _$compile_; | ||
$interval = _$interval_; | ||
$uibModal = _$uibModal_; | ||
|
||
$scope = $rootScope.$new(); | ||
templateHtml = $templateCache.get("/modules/users/add-user/add-user.html"); | ||
|
||
element = $compile(templateHtml)($scope); | ||
}); | ||
|
||
inject(function(_utils_, _config_, _userStore_, _capitalizeFilter_, _Notifications_) { | ||
utils = _utils_; | ||
config = _config_; | ||
userStore = _userStore_; | ||
capitalizeFilter = _capitalizeFilter_; | ||
Notifications = _Notifications_; | ||
}); | ||
|
||
}); | ||
|
||
beforeEach(function() { | ||
$state.current.name = "add-user"; | ||
createUserDeferred = $q.defer(); | ||
|
||
sinon.stub($state, "go"); | ||
|
||
clock = sinon.useFakeTimers(); | ||
|
||
}); | ||
|
||
it("Should initialize all the properties", function() { | ||
vm = $componentController("addUser", { $scope: $scope }); | ||
|
||
expect(vm.typePassword).to.be.false; | ||
expect(vm.confirmPassword).to.be.false; | ||
expect(vm.errorMsg).to.be.equal(""); | ||
expect(vm.user).to.be.an("object").that.is.not.empty; | ||
expect(vm.user.notification).to.be.true; | ||
expect(vm.user.role).to.be.equal("admin"); | ||
}); | ||
|
||
describe("Add User List workflows", function() { | ||
beforeEach(function() { | ||
sinon.stub(userStore, "createUser").returns(createUserDeferred.promise); | ||
vm = $componentController("addUser", { $scope: $scope }); | ||
$rootScope.$digest(); | ||
}); | ||
|
||
it("Should test toggleTypePassword", function() { | ||
vm.typePassword = false; | ||
vm.toggleTypePassword(); | ||
expect(vm.typePassword).to.be.true; | ||
}); | ||
|
||
it("Should test toggleConfirmPassword", function() { | ||
vm.confirmPassword = false; | ||
vm.toggleConfirmPassword(); | ||
expect(vm.confirmPassword).to.be.true; | ||
}); | ||
|
||
}); | ||
|
||
afterEach(function() { | ||
// Tear down | ||
$state.go.restore(); | ||
clock.restore(); | ||
}); | ||
|
||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
describe("Unit Component: clusterHosts", function() { | ||
"use strict"; | ||
|
||
// Angular injectables | ||
var $scope, $q, $httpBackend, $injector, $rootScope, $state, $templateCache, $compile, $stateParams, $componentController; | ||
|
||
// Module defined (non-Angular) injectables | ||
var config, utils, clusterHosts, Notifications, clusterStore; | ||
|
||
// Local variables used for testing | ||
var getClusterListDeferred, vm, clock, throttled, intervalSpy, timer, args, dashboardStub, element; | ||
|
||
// Initialize modules | ||
beforeEach(function() { | ||
module("TendrlModule"); | ||
module("TestDataModule"); | ||
module("templates"); | ||
}); | ||
|
||
beforeEach(function() { | ||
|
||
var templateHtml; | ||
|
||
inject(function(_$q_, _$componentController_, _$rootScope_, _$state_, _$templateCache_, _$compile_, _$stateParams_) { | ||
$q = _$q_; | ||
$componentController = _$componentController_; | ||
$rootScope = _$rootScope_; | ||
$state = _$state_; | ||
$templateCache = _$templateCache_; | ||
$compile = _$compile_; | ||
$stateParams = _$stateParams_; | ||
|
||
$scope = $rootScope.$new(); | ||
templateHtml = $templateCache.get("/modules/cluster/cluster-hosts/cluster-hosts.html"); | ||
|
||
element = $compile(templateHtml)($scope); | ||
}); | ||
|
||
inject(function(_clusterStore_, _clusterHosts_) { | ||
clusterHosts = _clusterHosts_; | ||
clusterStore = _clusterStore_; | ||
}); | ||
|
||
}); | ||
|
||
beforeEach(function() { | ||
$stateParams.clusterId = clusterHosts.formattedOutput[0].clusterId; | ||
$state.current.name = "cluster-hosts"; | ||
getClusterListDeferred = $q.defer(); | ||
|
||
sinon.stub(clusterStore, "getClusterList").returns(getClusterListDeferred.promise); | ||
sinon.stub(clusterStore, "formatClusterData").returns(clusterHosts.formattedOutput); | ||
sinon.stub(clusterStore, "getClusterDetails").returns(clusterHosts.formattedOutput[0]); | ||
|
||
}); | ||
|
||
it("Should initialize all the properties", function() { | ||
vm = $componentController("clusterHosts", { $scope: $scope }); | ||
|
||
expect(vm.isDataLoading).to.be.true; | ||
expect(vm.clusterId).to.be.equal("e372c01c-5022-41ce-9412-e96038bca305"); | ||
expect($rootScope.selectedClusterOption).to.be.equal("e372c01c-5022-41ce-9412-e96038bca305"); | ||
}); | ||
|
||
it("Should call getClusterList if clusterData doens't exit", function() { | ||
vm = $componentController("clusterHosts", { $scope: $scope }); | ||
getClusterListDeferred.resolve(clusterHosts.clusters); | ||
$rootScope.$digest(); | ||
|
||
expect($rootScope.clusterData).to.deep.equal(clusterHosts.formattedOutput); | ||
expect(vm.isDataLoading).to.be.false; | ||
expect(vm.clusterObj).to.deep.equal(clusterHosts.formattedOutput[0]); | ||
expect(vm.clusterName).to.be.equal(clusterHosts.formattedOutput[0].clusterId); | ||
}); | ||
|
||
it("Should not call getClusterList if clusterData exists", function() { | ||
$rootScope.clusterData = clusterHosts.clusters; | ||
vm = $componentController("clusterHosts", { $scope: $scope }); | ||
|
||
expect(vm.isDataLoading).to.be.false; | ||
expect(vm.clusterObj).to.deep.equal(clusterHosts.formattedOutput[0]); | ||
expect(vm.clusterName).to.be.equal(clusterHosts.formattedOutput[0].clusterId); | ||
|
||
}); | ||
|
||
it("Should listen GotClusterData event broadcast", function() { | ||
|
||
vm = $componentController("clusterHosts", { $scope: $scope }); | ||
getClusterListDeferred.resolve(clusterHosts.clusters); | ||
$rootScope.$digest(); | ||
|
||
$rootScope.clusterData = clusterHosts.formattedOutput; | ||
$scope.$broadcast("GotClusterData"); | ||
expect($rootScope.selectedClusterOption).to.be.equal(clusterHosts.formattedOutput[0].clusterId); | ||
}); | ||
|
||
afterEach(function() { | ||
// Tear down | ||
clusterStore.getClusterList.restore(); | ||
clusterStore.formatClusterData.restore(); | ||
clusterStore.getClusterDetails.restore(); | ||
}); | ||
|
||
}); |
Oops, something went wrong.