67 lines
2.5 KiB
JavaScript
67 lines
2.5 KiB
JavaScript
describe('Test Location Field directive', function () {
|
|
var compile, scope, $httpBackend, events, $q, deferred;
|
|
|
|
beforeEach(module('myitsmApp', 'templates'));
|
|
beforeEach(function() {
|
|
inject(function(_$compile_, _$rootScope_, $injector, _events_, _$q_) {
|
|
$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();
|
|
events = _events_;
|
|
$q = _$q_;
|
|
deferred = $q.defer();
|
|
});
|
|
});
|
|
|
|
beforeEach(function() {
|
|
scope.field = {
|
|
name: 'changeLocation',
|
|
label: 'Location',
|
|
dataType: 'widget',
|
|
value: {
|
|
region: 'Americas',
|
|
siteGroup: 'United States',
|
|
name: 'Headquarters, Building 1.31'
|
|
},
|
|
id: 'AGHAA5V0HGOWWAOU6TE5A89PA7BC8N'
|
|
};
|
|
|
|
scope.ticket = {
|
|
companyName: {
|
|
name: 'Calbro Services'
|
|
}
|
|
};
|
|
});
|
|
|
|
function getCompiledElement() {
|
|
var element = angular.element('<location-custom-field data="field" context="ticket" is-editable="false"></location-custom-field>');
|
|
var compiledElement = compile(element)(scope);
|
|
scope.$digest();
|
|
return compiledElement;
|
|
}
|
|
|
|
it('should compile', function() {
|
|
var directiveElem = getCompiledElement();
|
|
var divElem = directiveElem[0];
|
|
expect(divElem).toBeDefined();
|
|
});
|
|
|
|
it('should successfully watch data.value and set the location in formatted form', function() {
|
|
var isolateScope = getCompiledElement().isolateScope();
|
|
spyOn(isolateScope, '$emit');
|
|
isolateScope.data.value = {
|
|
region: 'Melbourne',
|
|
siteGroup: 'United States',
|
|
name: 'Headquarters, Building 1.31'
|
|
};
|
|
isolateScope.$digest();
|
|
expect(isolateScope.$emit).toHaveBeenCalledWith(events.WIDGET_VALUE_CHANGE, { fieldName: scope.field.name, memberName: scope.field.value.fieldChanged});
|
|
expect(isolateScope.changeLocation).toBe('Melbourne > United States > Headquarters, Building 1.31')
|
|
});
|
|
}); |