SmartIT_Extensions/BMC/smart-it-full/test/app/asset/add-people-controller.spec.js

303 lines
10 KiB
JavaScript

describe('AddPeopleController', function () {
'use strict';
var $httpBackend;
beforeEach(module('myitsmApp'));
beforeEach(inject(function ($injector, $rootScope, $controller, assetModel, configurationModel, userService, searchService, userModel, $q, searchModel, events, systemAlertService, i18nService, $filter, $timeout) {
this.scope = $rootScope.$new();
this.assetModel = assetModel;
this.configurationModel = configurationModel;
this.userService = userService;
this.searchService = searchService;
this.controller = $controller;
this.userModel = userModel;
this.searchModel = searchModel;
this.$q = $q;
this.events = events;
this.systemAlertService = systemAlertService;
this.i18nService = i18nService;
this.$filter = $filter;
this.$timeout;
this.controllerInstance = this.controller('AddPeopleController', {
$scope: this.scope,
$stateParams: {
id: 12233
}
});
}));
beforeEach(inject(function ($injector) {
$httpBackend = $injector.get('$httpBackend');
var getLocale = function () {
return readJSON('scripts/app/i18n/resources-locale_en.json');
};
$httpBackend.whenGET(/^scripts\/app\/i18n\/resources-locale_en.*$/).respond(getLocale());
$httpBackend.whenGET('/smartit/rest/v2/metadata?type=global').respond(200);
$httpBackend.whenGET('/smartit/restapi/person/supportgroupperson').respond(200);
$httpBackend.whenGET('/smartit/rest/serverstates').respond(200);
$httpBackend.whenGET('/smartit/rest/sessionstatus?getLicenseKey=true').respond(200);
$httpBackend.whenGET('views/dashboard/index.html').respond(200);
$httpBackend.whenGET('/smartit/rest/foundation/items?type=company').respond(200);
$httpBackend.whenGET('/smartit/rest/foundation/items?chunkInfo=%7B%22startIndex%22:0,%22chunkSize%22:80%7D&searchText=&type=company').respond(200);
$httpBackend.whenGET('/smartit/rest/person/search?name=&thumbnail=true').respond(200);
$httpBackend.whenGET('/smartit/rest/foundation/items?type=company').respond(200);
$httpBackend.whenGET('/smartit/rest/person/search/supportgroup').respond(200);
this.addPeopleData = {
relationshipType: 'uesdby',
type: 'person',
subType: 'company',
selectedPerson: {
"name": "Calbro Services",
"id": "AG00123F73CF5EDFYTSQRbxaAAFsUA",
"attributeMap": {},
"$$hashKey": "object:4335",
"displayId": 123
}
};
this.type = 'company';
}));
beforeEach(inject(function ($q, $rootScope) {
var deferred = $q.defer();
var success = {
"relationshipType": "usedby",
"type": "person",
"subType": "company",
"id": "AG00123F73CF5EDFYTSQRbxaAAFsUA",
"displayId": 'test foo'
};
var result = [
{
"name": "Calbro Services",
"id": "AG00123F73CF5EDFYTSQRbxaAAFsUA",
"attributeMap": {},
"$$hashKey": "object:11546"
},
{
"name": "Invention, Inc.",
"id": "AG00123F73CF5EDFYTSQdLxaAAGcUA",
"attributeMap": {},
"$$hashKey": "object:11547"
}
];
spyOn(this.assetModel, "addPeople").and.callFake(function () {
deferred.resolve(success);
return deferred.promise;
});
spyOn(this.searchModel, "getOperatingCompanies").and.callFake(function () {
deferred.resolve({companies: result, exceedsChunkSize: false});
return deferred.promise;
});
var resultUserService = [
{
"name": "Calbro Services",
"id": "AG00123F73CF5EDFYTSQRbxaAAFsUA",
"attributeMap": {},
"$$hashKey": "object:11538"
},
{
"name": "Invention, Inc.",
"id": "AG00123F73CF5EDFYTSQdLxaAAGcUA",
"attributeMap": {},
"$$hashKey": "object:11539"
}
];
spyOn(this.userService, "searchUserByName").and.callFake(function () {
deferred.resolve(resultUserService);
return deferred.promise;
});
var resultSearchModel = [
{
"name": "Calbro Services",
"id": "AG00123F73CF5EDFYTSQRbxaAAFsUA",
"attributeMap": {},
"$$hashKey": "object:11538"
},
{
"name": "Invention, Inc.",
"id": "AG00123F73CF5EDFYTSQdLxaAAGcUA",
"attributeMap": {},
"$$hashKey": "object:11539"
}
];
spyOn(this.searchModel, "getOrganizationsByCompany").and.callFake(function () {
deferred.resolve(resultSearchModel);
return deferred.promise;
});
var resultSearchService = [
{
"name": "Calbro Services",
"id": "AG00123F73CF5EDFYTSQRbxaAAFsUA",
"attributeMap": {},
"$$hashKey": "object:11538"
},
{
"name": "Invention, Inc.",
"id": "AG00123F73CF5EDFYTSQdLxaAAGcUA",
"attributeMap": {},
"$$hashKey": "object:11539"
}
];
spyOn(this.searchService, "getSupportGroupsList").and.callFake(function () {
deferred.resolve({supportGroups: resultSearchService, exceedsChunkSize: false});
return deferred.promise;
});
var data = true;
spyOn(this.systemAlertService, "modal").and.callFake(function () {
deferred.resolve(data);
return deferred.promise;
});
}));
it('should defined', function () {
expect(this.controllerInstance).toBeDefined();
});
it('should run selectPeopleType ()', function () {
this.scope.selectPeopleType(this.type);
this.scope.selectedType = 'person';
expect(this.scope.selectedType).toEqual('person');
expect(this.scope.searchPeople.results).toEqual([]);
});
it('should run onSearchTextChange()', function () {
this.scope.selectedType = 'supportgroup';
this.scope.state = {
dataIsLoading: false,
isPeopleRelationsLoading: false,
tooManyCompanies: false,
tooManySupportgroups: true,
dataSearching: true
};
this.scope.selectedType = 'supportgroup';
this.scope.state.tooManySupportgroups = true;
this.scope.onSearchTextChange();
expect(this.scope.searchPeople).toBeTruthy();
});
it('should run selectPerson()', function () {
this.person = {
"name": "Calbro Services",
"id": "AG00123F73CF5EDFYTSQRbxaAAFsUA",
"attributeMap": {},
"$$hashKey": "object:4335"
};
this.scope.selectPerson(this.person);
expect(this.scope.selectedPerson.name).toEqual(this.person.name);
});
it('should run addPeopleToAsset ()', function () {
expect(this.scope.state.isPeopleRelationsLoading).toEqual(false);
this.scope.selectedPerson = {
"name": "Calbro Services",
"id": "AG00123F73CF5EDFYTSQRbxaAAFsUA",
"attributeMap": {},
"$$hashKey": "object:4335",
"displayId": 123
};
this.scope.modalInstance = {
close: function () {
return
}
};
this.scope.addPeopleToAsset();
expect(this.scope.state.isPeopleRelationsLoading).toEqual(true);
this.scope.$apply();
expect(this.scope.state.isPeopleRelationsLoading).toEqual(false);
expect(this.assetModel.addPeople).toHaveBeenCalled();
});
it('should run selectRelationshipType ()', function () {
this.type = 'ownedby';
this.scope.selectRelationshipType(this.type);
expect(this.scope.selectedRelationshipType).toEqual(this.type);
});
it('shoul run dosearch ()', function () {
this.scope.selectedType = 'company';
this.scope.company = {
name: "test foo"
};
this.scope.doSearch();
//this.scope.selectedType = 'company';
this.scope.$apply();
expect(this.scope.companyList.length).toEqual(2);
expect(this.scope.state.tooManyCompanies).toBe(false);
expect(this.scope.state.isPeopleRelationsLoading).toBe(true);
});
it('should run for promise ', function () {
this.scope.selectedType = 'people';
this.resultSearchModel = [
{
"name": "Calbro Services",
"id": "AG00123F73CF5EDFYTSQRbxaAAFsUA",
"attributeMap": {},
"$$hashKey": "object:11538"
},
{
"name": "Invention, Inc.",
"id": "AG00123F73CF5EDFYTSQdLxaAAGcUA",
"attributeMap": {},
"$$hashKey": "object:11539"
}
];
this.scope.company = {
name: undefined
};
this.scope.doSearch();
this.scope.$apply();
expect(this.scope.searchPeople.results).toEqual(this.resultSearchModel);
});
it('should run loadMore ()', function () {
this.scope.loadMore();
this.scope.$apply();
expect(this.scope.state.isPeopleRelationsLoading).toBe(false);
expect(this.scope.showMore).toBe(false);
});
it('should run getCompaniesByName ()', function () {
this.cmpName = 'Calbro Services';
this.myResult = this.scope.getCompaniesByName(this.cmpName);
expect(this.myResult.$$state.status).toEqual(0);
});
it('should run changeCompany ()', function () {
this.cmpName = 'Calbro Services';
this.scope.changeCompany(this.cmpName);
expect(this.scope.company).toEqual(this.cmpName);
});
it('should run close ()', function () {
this.scope.modalInstance={
dismiss:function () {
return
}
}
this.scope.close();
this.scope.$apply();
});
});