170 lines
6.2 KiB
JavaScript
170 lines
6.2 KiB
JavaScript
/*** Created by npatil2 .*/
|
|
describe('service: locationModel', function () {
|
|
var $httpBackend, $rootScope, scope;
|
|
|
|
beforeEach(module('myitsmApp'));
|
|
beforeEach(inject(function ($injector, $rootScope, locationService, googleMapService, $q) {
|
|
scope = $rootScope.$new();
|
|
$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/restapi/person/supportgroupperson').respond(200);
|
|
$httpBackend.whenGET('/smartit/rest/v2/following/stream').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);
|
|
$rootScope = $injector.get('$rootScope');
|
|
this.locationModel = $injector.get('locationModel');
|
|
this.locationService = locationService;
|
|
this.googleMapService = googleMapService;
|
|
this.$q = $q;
|
|
}));
|
|
|
|
beforeEach(inject(function ($q) {
|
|
var deferred = $q.defer(), data = {
|
|
locations: {
|
|
location1: 'test location',
|
|
location2: 'test location1'
|
|
},
|
|
floormaps: {
|
|
pune: 'pune',
|
|
delhi: 'delhi'
|
|
}
|
|
};
|
|
|
|
spyOn(this.locationService, 'getLocationsBulk').and.callFake(function () {
|
|
deferred.resolve(data);
|
|
return deferred.promise;
|
|
});
|
|
|
|
spyOn(this.locationModel, 'getLocationsList').and.callFake(function () {
|
|
deferred.resolve(data);
|
|
return deferred.promise;
|
|
});
|
|
|
|
spyOn(this.locationService, 'getPOIdetails').and.callFake(function () {
|
|
deferred.resolve(data);
|
|
return deferred.promise;
|
|
});
|
|
|
|
spyOn(this.locationService, 'getLocationById').and.callFake(function () {
|
|
deferred.resolve(data);
|
|
return deferred.promise;
|
|
});
|
|
|
|
spyOn(this.locationService, 'getPOItypes').and.callFake(function () {
|
|
deferred.resolve(data);
|
|
return deferred.promise;
|
|
});
|
|
|
|
spyOn(this.locationService, 'getPOIbyLocation').and.callFake(function () {
|
|
deferred.resolve(data);
|
|
return deferred.promise;
|
|
});
|
|
|
|
spyOn(this.locationService, 'getMapTiles').and.callFake(function () {
|
|
deferred.resolve(['test', 'test1', 'test2']);
|
|
return deferred.promise;
|
|
});
|
|
|
|
spyOn(this.googleMapService, 'initFloorMap').and.callFake(function () {
|
|
deferred.resolve(data);
|
|
return deferred.promise;
|
|
});
|
|
|
|
spyOn(this.googleMapService, 'panAssetOnMap').and.callFake(function () {
|
|
deferred.resolve(data);
|
|
return deferred.promise;
|
|
});
|
|
}));
|
|
|
|
it('should return Locations List ', function () {
|
|
this.locationModel.locationsCache = {
|
|
location1: 'test location',
|
|
location2: 'test location1'
|
|
};
|
|
|
|
this.myResult = this.locationModel.getLocationsList();
|
|
scope.$apply();
|
|
expect(this.myResult.$$state.value.locations.location1).toEqual('test location');
|
|
expect(this.myResult.$$state.value.floormaps.pune).toEqual('pune');
|
|
});
|
|
|
|
|
|
it('should return Location By PoiId ', function () {
|
|
this.searchText = 'incident';
|
|
this.myResult = this.locationModel.getLocationByPoiId(this.searchText);
|
|
scope.$apply();
|
|
expect(this.myResult.$$state.value.locations.location1).toEqual('test location');
|
|
expect(this.myResult.$$state.value.floormaps.pune).toEqual('pune');
|
|
});
|
|
|
|
it('should filter Locations', function () {
|
|
this.poiId = 123;
|
|
this.myResult = this.locationModel.filterLocations(this.poiId);
|
|
scope.$apply();
|
|
expect(this.myResult.$$state.value).toBeDefined();
|
|
});
|
|
|
|
it('should return POI types ', function () {
|
|
this.myResult = this.locationModel.getPOItypes();
|
|
scope.$apply();
|
|
expect(this.locationModel.typesCache).toBeTruthy();
|
|
expect(this.locationModel.typeRequestPromise).toBeTruthy();
|
|
});
|
|
|
|
it('should return POI details ', function () {
|
|
this.id = 123;
|
|
this.myResult = this.locationModel.getPOIdetails(this.id);
|
|
scope.$apply();
|
|
expect(this.myResult.$$state.value.locations.location1).toEqual('test location');
|
|
expect(this.myResult.$$state.value.floormaps.pune).toEqual('pune');
|
|
});
|
|
|
|
it('should return POI by Location', function () {
|
|
this.id = 0;
|
|
this.myResult = this.locationModel.getPOIbyLocation(this.id);
|
|
scope.$apply();
|
|
expect(this.locationModel.poiByLocationCache[0]).toBeTruthy();
|
|
});
|
|
|
|
it('should return Map Tiles', function () {
|
|
this.poi = {
|
|
id: 0
|
|
};
|
|
|
|
this.locationModel.tilesCache = [];
|
|
this.myResult = this.locationModel.getMapTiles(this.poi);
|
|
scope.$apply();
|
|
expect(this.locationModel.tilesCache[0]).toBeTruthy();
|
|
this.locationModel.tilesCache = ['test', 'test1', 'test2'];
|
|
this.myResult = this.locationModel.getMapTiles(this.poi);
|
|
scope.$apply();
|
|
expect(this.myResult.$$state.value).toEqual('test');
|
|
});
|
|
|
|
it('should init LocationMap ', function () {
|
|
this.poi = {
|
|
id: 123
|
|
};
|
|
|
|
this.mapNode = 'test';
|
|
this.myResult = this.locationModel.initLocationMap(this.mapNode, this.poi);
|
|
scope.$apply();
|
|
expect(this.myResult.$$state.value.locations.location1).toEqual('test location');
|
|
expect(this.myResult.$$state.value.floormaps.pune).toEqual('pune');
|
|
});
|
|
|
|
it('should add Location Marker ', function () {
|
|
this.id = 123;
|
|
this.mapData = 'test data';
|
|
this.myResult = this.locationModel.addLocationMarker(this.mapData, this.id);
|
|
scope.$apply();
|
|
expect(this.myResult.$$state.value.locations.location1).toEqual('test location');
|
|
expect(this.myResult.$$state.value.floormaps.pune).toEqual('pune');
|
|
});
|
|
}); |