285 lines
9.7 KiB
JavaScript
285 lines
9.7 KiB
JavaScript
describe('AssetEditDetailsController', function () {
|
|
|
|
beforeEach(module('myitsmApp'));
|
|
beforeEach(inject(function ($rootScope, $controller, events, configurationModel, assetModel, metadataModel, $q, systemAlertService, $filter, searchModel) {
|
|
this.scope = $rootScope.$new();
|
|
this.controller = $controller;
|
|
this.events = events;
|
|
this.configurationModel = configurationModel;
|
|
this.assetModel = assetModel;
|
|
this.metadataModel = metadataModel;
|
|
this.$q = $q;
|
|
this.systemAlertService = systemAlertService;
|
|
this.$filter = $filter;
|
|
this.searchModel = searchModel;
|
|
|
|
this.controllerInstance = this.controller('AssetEditDetailsController', {
|
|
$scope: this.scope
|
|
});
|
|
}));
|
|
|
|
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/v2/metadata?type=asset').respond(200);
|
|
$httpBackend.whenGET('/smartit/rest/asset/details/%5Bobject%20Object%5D/%5Bobject%20Object%5D').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();
|
|
var success = [
|
|
{
|
|
"metadatatype": "asset",
|
|
"statuses": [
|
|
{
|
|
"isValidForCreate": true,
|
|
"index": 0,
|
|
"name": "Ordered",
|
|
"label": "Ordered",
|
|
"$$hashKey": "object:3110"
|
|
}
|
|
],
|
|
"assetTypes": [
|
|
{
|
|
"subType": [
|
|
{
|
|
"putIntoInventory": true,
|
|
"index": 0,
|
|
"name": "BMC_COMPUTERSYSTEM",
|
|
"label": "Computer System",
|
|
"$$hashKey": "object:3104"
|
|
},
|
|
{
|
|
"putIntoInventory": true,
|
|
"index": 0,
|
|
"name": "BMC_MAINFRAME",
|
|
"label": "Mainframe",
|
|
"$$hashKey": "object:3105"
|
|
},
|
|
{
|
|
"putIntoInventory": true,
|
|
"index": 0,
|
|
"name": "BMC_PRINTER",
|
|
"label": "Printer",
|
|
"$$hashKey": "object:3106"
|
|
}
|
|
],
|
|
"index": 0,
|
|
"name": "Computer System",
|
|
"label": "Computer System",
|
|
"$$hashKey": "object:3024"
|
|
}
|
|
]
|
|
},
|
|
{
|
|
"name": "printer",
|
|
"desc": "this is for print pages",
|
|
"company": {
|
|
"name": "Calbro Services"
|
|
},
|
|
"product": {
|
|
"categorizations": [
|
|
{
|
|
"name": "product",
|
|
"tiers": {}
|
|
}
|
|
]
|
|
},
|
|
"reconciliationId": "OI-3422B6A0DE5047E982E32E234C7A47C5",
|
|
"classId": "BMC_COMPUTERSYSTEM",
|
|
"assetId": "",
|
|
"instanceId": "OI-2D1DE306A5B84270BFC506B6A7CF79D4",
|
|
"status": {
|
|
"value": "Deployed"
|
|
},
|
|
"type": "Computer System",
|
|
"subType": "BMC_COMPUTERSYSTEM",
|
|
"needsReconciliation": true,
|
|
"invoiceNumber": "",
|
|
"ticketType": "asset",
|
|
"extensionAttrs": {},
|
|
"poiInfo": {},
|
|
"following": false,
|
|
"assetType": "Computer System",
|
|
"isPoi": false,
|
|
"outageResourceAvailable": 1,
|
|
"typeLabel": "Computer System",
|
|
"subTypeLabel": "Computer System",
|
|
}
|
|
];
|
|
|
|
spyOn(this.metadataModel, "getMetadataByType").and.callFake(function () {
|
|
deferred.resolve(success);
|
|
return deferred.promise;
|
|
});
|
|
|
|
spyOn(this.assetModel, "getAssetDetailsByID").and.callFake(function () {
|
|
deferred.resolve(success);
|
|
return deferred.promise;
|
|
});
|
|
|
|
spyOn(this.searchModel, "getCompaniesByText").and.callFake(function () {
|
|
deferred.resolve(success);
|
|
return deferred.promise;
|
|
});
|
|
|
|
spyOn(this.assetModel, "getCostCentersByCompanyName").and.callFake(function () {
|
|
var companyData = { items : success };
|
|
deferred.resolve(companyData);
|
|
return deferred.promise;
|
|
});
|
|
|
|
spyOn(this.assetModel, "updateCacheAssetDetails").and.callFake(function () {
|
|
deferred.resolve(success);
|
|
return deferred.promise;
|
|
});
|
|
|
|
spyOn(this.systemAlertService, "error").and.callFake(function () {
|
|
deferred.resolve(success);
|
|
return deferred.promise;
|
|
});
|
|
|
|
}));
|
|
|
|
it('should defined', function () {
|
|
expect(this.controllerInstance).toBeDefined();
|
|
|
|
});
|
|
|
|
it('should broadcast TOGGLE_EDIT_MODED and assign asste data', inject(function ($rootScope) {
|
|
refreshAssetData = function () {
|
|
return
|
|
};
|
|
|
|
$rootScope.$broadcast(this.events.TOGGLE_EDIT_MODE, refreshAssetData);
|
|
this.scope.$apply();
|
|
expect(this.scope.metadata).toBeTruthy();
|
|
expect(this.scope.updatedModel).toBeTruthy();
|
|
}));
|
|
|
|
it('should run getCompaniesByType ()', function () {
|
|
this.type = 'test foo';
|
|
this.text = 'foo test';
|
|
this.myResult = this.scope.getCompaniesByType(this.type, this.text);
|
|
this.scope.$apply();
|
|
expect(this.myResult.$$state.status).toEqual(1);
|
|
});
|
|
|
|
it('should run setCompanyByType()', function () {
|
|
this.type = 'test foo';
|
|
this.item = {
|
|
name: 'foo test'
|
|
};
|
|
|
|
this.scope.setCompanyByType(this.item, this.item);
|
|
expect(this.scope.updatedModel).toBeTruthy();
|
|
});
|
|
|
|
it('should run openDatePicker()', function () {
|
|
this.calendar = {
|
|
open: function () {
|
|
return
|
|
}
|
|
};
|
|
|
|
this.scope.openDatePicker(this.calendar);
|
|
});
|
|
|
|
it('should run isFieldValid()', function () {
|
|
this.myResult = this.scope.isFieldValid();
|
|
expect(this.myResult).toBe(false);
|
|
});
|
|
|
|
it('should run updateAssetField()', function () {
|
|
this.type = 'depreciated';
|
|
this.item = {
|
|
label: 'test foo'
|
|
};
|
|
|
|
this.scope.updatedModel.financial = {
|
|
depreciated: ''
|
|
};
|
|
|
|
this.scope.updateAssetField(this.type, this.item);
|
|
expect(this.scope.updatedModel.financial.depreciated).toEqual('test foo');
|
|
});
|
|
|
|
it('should run getCostCentersByCompany ()', function () {
|
|
this.text = 'test foo';
|
|
this.scope.updatedModel.company = {
|
|
name: 'test foo'
|
|
};
|
|
|
|
this.myResult = this.scope.getCostCentersByCompany(this.text);
|
|
this.scope.$apply();
|
|
expect(this.myResult.$$state.status).toEqual(1);
|
|
});
|
|
|
|
it('should run updateCostCenter ()', function () {
|
|
this.item = {
|
|
value: 'test foo'
|
|
};
|
|
|
|
this.scope.updatedModel = {
|
|
financial: {
|
|
costCenter: ''
|
|
}
|
|
};
|
|
|
|
this.scope.updateCostCenter(this.item);
|
|
expect(this.scope.updatedModel.financial.costCenter).toBe('test foo');
|
|
});
|
|
|
|
it('should broadcast SAVE_CHANGES and assign asset data', inject(function ($rootScope) {
|
|
this.scope.updatedModel = {
|
|
financial: {
|
|
costCenter: '',
|
|
invoiceNumber: ''
|
|
}
|
|
};
|
|
this.scope.selectedImpact = null;
|
|
this.scope.selectedUrgency = null;
|
|
$rootScope.$broadcast(this.events.SAVE_CHANGES);
|
|
expect(this.scope.updatedModel.impact).toEqual("");
|
|
expect(this.scope.updatedModel.urgency).toEqual("");
|
|
}));
|
|
|
|
it('should broadcast SAVE_ALL_CHANGES_COMPLETE and assign asset data', inject(function ($rootScope) {
|
|
this.data = {
|
|
needsReconciliation: 'test foo'
|
|
};
|
|
|
|
var myEvent = new CustomEvent('mycustom event');
|
|
|
|
$rootScope.$broadcast(this.events.SAVE_ALL_CHANGES_COMPLETE, myEvent, this.data);
|
|
this.scope.$apply();
|
|
expect(this.scope.isAssetSaving).toBe(false);
|
|
}));
|
|
|
|
it('should broadcast SAVE_ALL_CHANGES_FAULT and assign asset data', inject(function ($rootScope) {
|
|
this.err = {
|
|
data: {
|
|
error: 'test foo'
|
|
}
|
|
};
|
|
|
|
var myEvent = new CustomEvent('mycustom event');
|
|
|
|
$rootScope.$broadcast(this.events.SAVE_ALL_CHANGES_FAULT, myEvent, this.err);
|
|
this.scope.$apply();
|
|
expect(this.scope.isAssetSaving).toBe(false);
|
|
}));
|
|
});
|