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

110 lines
3.6 KiB
JavaScript

/*** Created by vdhakre .*/
describe('AssetController', function () {
var $httpBackend;
beforeEach(module('myitsmApp'));
beforeEach(inject(function ($rootScope, $controller, events, $state, assetModel, userModel, metadataModel, screenConfigurationModel) {
this.$rootScope = $rootScope;
this.scope = $rootScope.$new();
this.controller = $controller;
this.events = events;
this.$state = $state;
this.assetModel = assetModel;
this.userModel = userModel;
this.metadataModel = metadataModel;
this.screenConfigurationModel = screenConfigurationModel;
this.controllerInstance = this.controller('AssetController', {
$scope: this.scope
});
this.personItem = {
"desc": "",
"displayId": "PPL000000000014",
"parentId": "OI-89C88452FC7211E8A674A4ADEC2F5748",
"relationshipType": "ownedby",
"tag": "",
"type": "person",
"templateName": "",
"realObject": {
"reqType": "people",
"fullName": "Bob Baxter",
"accessPermitted": "No",
"organizationName": "Information Technology",
"isPrimaryContact": "Yes",
"loginId": "Bob",
"companyContactName": "Calbro Services",
"id": "AG00123F73CF5ERkUTSQ-DgZAAg6QA"
},
"visited": false,
"subType": "",
"id": "Bob",
"isPoi": false
};
}));
beforeEach(inject(function ($injector, $q) {
$httpBackend = $injector.get('$httpBackend');
var getLocale = function () {
return readJSON('scripts/app/i18n/resources-locale_en.json');
},
deferred = $q.defer(),
getAssetData = function () {
return readJSON('mocks/asset.json');
},
getAllMetadata = function () {
return readJSON('mocks/metadata-allTypes.json');
};
$httpBackend.whenGET(/^scripts\/app\/i18n\/resources-locale_en.*$/).respond(getLocale());
$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.whenPOST('/smartit/rest/asset/relationshiptypes').respond(200);
spyOn(this.assetModel, 'getAssetDetailsByID').and.callFake(function () {
deferred.resolve(getAssetData());
return deferred.promise;
});
spyOn(this.assetModel, 'getPeopleRelations').and.callFake(function () {
deferred.resolve({});
return deferred.promise;
});
spyOn(this.userModel,'getBCMIntegrationConfig').and.callFake(function () {
deferred.resolve({});
return deferred.promise;
});
spyOn(this.metadataModel,'getMetadataByType').and.callFake(function () {
deferred.resolve(getAllMetadata());
return deferred.promise;
});
spyOn(this.assetModel, 'getPrimaryContact').and.callFake(function () {
deferred.resolve({});
return deferred.promise;
});
spyOn(this.assetModel, 'getAssetOwnerDetails').and.callFake(function () {
deferred.resolve(this.personItem);
return deferred.promise;
});
spyOn(this.screenConfigurationModel, 'loadScreenConfigurationAndCustomFieldLabels').and.callFake(function () {
deferred.resolve({});
return deferred.promise;
});
}));
it('should be defined', function () {
this.scope.init(1,2);
this.$rootScope.$apply();
expect(this.controllerInstance).toBeDefined();
expect(this.assetModel.assetId).toEqual(1);
});
it('should load the asset owner', function () {
this.assetModel.assetPrimaryContact = this.personItem;
this.scope.init(1,2);
this.$rootScope.$apply();
expect(this.assetModel.assetId).toEqual(1);
expect(this.scope.asset.owner.id).toEqual('Bob');
});
});