SmartIT_Extensions/BMC/smart-it-full/test/app/asset/asset-edit-header-controlle...

248 lines
8.2 KiB
JavaScript

/*** Created by npatil2 .*/
describe('AssetEditHeaderController', function () {
beforeEach(module('myitsmApp'));
beforeEach(inject(function ($rootScope, $controller, events, assetModel, searchModel, systemAlertService, $filter, $q, createTicketModel) {
this.scope = $rootScope.$new();
this.controller = $controller;
this.events = events;
this.assetModel = assetModel;
this.$q = $q;
this.systemAlertService = systemAlertService;
this.$filter = $filter;
this.searchModel = searchModel;
this.createTicketModel = createTicketModel;
this.controllerInstance = this.controller('AssetEditHeaderController', {
$scope: this.scope
});
}));
beforeEach(inject(function ($injector) {
var $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/asset/details/%5Bobject%20Object%5D/%5Bobject%20Object%5D').respond(200);
$httpBackend.whenGET('/smartit/rest/foundation/items?type=company').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);
}));
beforeEach(inject(function ($q, $rootScope) {
var deferred = $q.defer(),
success = {
company: {
name: 'test foo'
}
},
companyList = {
companies: success, exceedsChunkSize: false
},
data = {
name: 'computer',
desc: 'computer for work',
type: 'Computer System',
company: {
name: 'Calbro Services'
},
product: {
categorizations: [
{
name: 'product',
tiers: {
productCategoryTier1: 'Hardware'
}
}
]
},
reconciliationId: 'OI-A4F50EDF0C0F4399BB0399DC8A98C826',
classId: 'BMC_COMPUTERSYSTEM',
instanceId: 'OI-E3F1BE930E4D4C909625C1BF50878ADA',
site: {},
status: {
value: 'In Repair'
},
assetExtension: {
hostName: 'j',
systemType: 'Unknown',
primaryCapability: 'Not Dedicated'
},
accessMappings: [
{
permission: 'write',
id: 'timeline'
},
{
permission: 'write',
id: 'assetrelations'
},
{
permission: 'write',
id: 'details'
},
{
permission: 'write',
id: 'status'
},
{
permission: 'write',
id: 'priority'
},
{
permission: 'write',
id: 'relations'
},
{
permission: 'write',
id: 'financial'
},
{
permission: 'write',
id: 'inventory'
}
],
needsReconciliation: false,
floor: '',
systemRole: '',
partNumber: '',
invoiceNumber: '232',
subType: 'BMC_COMPUTERSYSTEM',
notes: '',
lastModifiedBy: {
firstName: 'Allen',
lastName: 'Allbrook',
fullName: 'Allen Allbrook',
loginId: 'Allen',
customFields: {}
},
submitter: {
firstName: 'Allen',
lastName: 'Allbrook',
fullName: 'Allen Allbrook',
loginId: 'Allen',
customFields: {}
},
assetId: 'u',
financial: {
costCenter: 'Unallocated',
depreciated: 'No',
unitPrice: {
value: 0,
currencycode: 'USD'
},
salesTax: {
value: 0,
currencycode: 'USD'
},
marketValue: {
value: 0,
currencycode: 'USD'
},
totalPurchaseCost: {
value: 0,
currencycode: 'USD'
},
bookValue: {
value: 0,
currencycode: 'USD'
}
},
lifecycleDates: {
modifiedDate: 1507021944000
},
assetType: 'Computer System',
verified: false,
customFields: {}
};
spyOn(this.assetModel, 'getAssetDetailsByID').and.callFake(function () {
deferred.resolve(success);
return deferred.promise;
});
spyOn(this.searchModel, 'getOperatingCompanies').and.callFake(function () {
deferred.resolve(companyList);
return deferred.promise;
});
spyOn(this.assetModel, 'update').and.callFake(function () {
deferred.resolve(data);
return deferred.promise;
});
spyOn(this.systemAlertService, 'warning').and.callFake(function () {
deferred.resolve(success);
return deferred.promise;
});
spyOn(this.assetModel, 'updateCacheAssetDetails').and.callFake(function () {
deferred.resolve(data);
return deferred.promise;
});
spyOn(this.createTicketModel, 'getList').and.callFake(function () {
deferred.resolve(success);
return deferred.promise;
});
spyOn(this.searchModel, 'getCompaniesByText').and.callFake(function () {
deferred.resolve(companyList);
return deferred.promise;
});
}));
it('should defined', function () {
expect(this.controllerInstance).toBeDefined();
});
it('should broadcast DISCARD_CHANGES and assign asste data', inject(function ($rootScope) {
$rootScope.$broadcast(this.events.SAVE_CHANGES);
this.scope.$apply();
}));
it('should run getList () ', function () {
this.type = 'test foo';
this.term = 'foo test';
this.myResult = this.scope.getList(this.type, this.term);
this.scope.$apply();
expect(this.myResult.$$state.status).toEqual(1);
});
it('should run getCompaniesByName () ', function () {
var item = {
company: {
name: 'test foo'
}
};
this.myResult = this.scope.getCompaniesByName(item);
this.scope.$apply();
expect(this.myResult.$$state.status).toEqual(1);
});
it('should run updateCompanyField () ', function () {
var item = {
name: 'test foo'
};
this.scope.updateCompanyField(item);
expect(this.scope.currentAssetCompany).toEqual('test foo');
});
it('should broadcast TOGGLE_EDIT_MODE and assign asset data', inject(function ($rootScope) {
$rootScope.$broadcast(this.events.TOGGLE_EDIT_MODE);
this.scope.$apply();
expect(this.scope.currentAssetCompany).toEqual('test foo');
//expect(this.scope.state.tooManyCompanies).toBe(false);
}));
it('should broadcast DISCARD_CHANGES and assign asset data', inject(function ($rootScope) {
$rootScope.$broadcast(this.events.DISCARD_CHANGES);
this.scope.$apply();
expect(this.scope.updatedModel).toBeTruthy();
}));
});