64 lines
2.2 KiB
JavaScript
64 lines
2.2 KiB
JavaScript
describe('Test get directions directive', function () {
|
|
'use strict';
|
|
|
|
var compile, scope, element, $httpBackend, directiveElem, divElem;
|
|
|
|
beforeEach(module('myitsmApp', 'templates'));
|
|
beforeEach(function () {
|
|
inject(function ($compile, $rootScope, $injector, googleMapService) {
|
|
this.googleMapService = googleMapService;
|
|
$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/serverstates').respond(200);
|
|
$httpBackend.whenGET('/smartit/rest/sessionstatus?getLicenseKey=true').respond(200);
|
|
compile = $compile;
|
|
scope = $rootScope.$new();
|
|
});
|
|
});
|
|
|
|
beforeEach(inject(function ($q, $rootScope) {
|
|
|
|
var deferred = $q.defer();
|
|
var success = 'test success';
|
|
|
|
spyOn(this.googleMapService, "getDirectionUrl").and.callFake(function () {
|
|
deferred.resolve(success);
|
|
return deferred.promise;
|
|
});
|
|
}));
|
|
|
|
afterEach(inject(function ($rootScope) {
|
|
var $rootScope = $rootScope;
|
|
$rootScope.$apply();
|
|
}));
|
|
|
|
function getCompiledElement(address) {
|
|
element = angular.element('<get-directions destination = this.assetAddress ></get-directions>');
|
|
var compiledElement = compile(element)(scope);
|
|
|
|
scope.$digest();
|
|
return compiledElement;
|
|
}
|
|
|
|
it('should compile', function () {
|
|
this.address = 'asset.site.address.address';
|
|
directiveElem = getCompiledElement(this.address);
|
|
divElem = directiveElem[0];
|
|
expect(divElem).toBeDefined();
|
|
expect(directiveElem.find(element.length)).not.toBeLessThan(1);
|
|
});
|
|
|
|
it('should run getDirections()', function () {
|
|
directiveElem = getCompiledElement(this.address);
|
|
var isolatedScope = directiveElem.isolateScope();
|
|
|
|
isolatedScope.getDirections();
|
|
scope.$apply();
|
|
expect(this.googleMapService.getDirectionUrl).toHaveBeenCalled();
|
|
});
|
|
}); |