SmartIT_Extensions/BMC/smart-it-full/test/app/common/edit-activity-dates.spec.js

83 lines
3.4 KiB
JavaScript

describe('Test edit activity dates directive', function () {
var scope, compile, rootScope, $httpBackend;
beforeEach(module('myitsmApp', 'templates'));
beforeEach(module('ticketModule'));
beforeEach(function () {
inject(function ($compile, $rootScope, $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=incident").respond(new MetadataVO());
$httpBackend.whenGET("/smartit/rest/v2/metadata?type=global").respond(200);
$httpBackend.whenGET("/smartit/restapi/person/supportgroupperson").respond(200);
compile = $compile;
rootScope = $rootScope;
scope = $rootScope.$new();
});
});
function getCompiledElement(ticket, isDraft, updatedByParent) {
var element = angular.element('<form name="forms.editActivityDateSection"><edit-activity-dates ticket="ticket" is-draft=isDraft'
+ ' date-form="forms.editActivityDateSection" is-draft="isDraft"'
+ ' update-is-handled-by-parent="updatedByParent"></edit-activity-dates></form>');
var compiledElement = compile(element)(scope);
scope.$digest();
return compiledElement;
}
it('should compile', function () {
var ticket = new IncidentVO();
var directiveElem = getCompiledElement(ticket);
var divElem = directiveElem[0];
expect(divElem).toBeDefined();
expect(directiveElem.find('.edit-ticket-dates').length).not.toBeLessThan(1);
});
it('should save changes and close', function () {
var ticket = new IncidentVO();
var directiveElem = getCompiledElement(ticket).find('.edit-ticket-dates');
var isolatedScope = directiveElem.isolateScope();
spyOn(isolatedScope, '$emit');
rootScope.$broadcast('saveChanges');
expect(isolatedScope.$emit).toHaveBeenCalledWith('saveChangesComplete');
});
it('should change date', function () {
scope.ticket = new IncidentVO();
scope.ticket.timing = true;
var directiveElem = getCompiledElement(scope.ticket, true).find('.edit-ticket-dates');
var isolatedScope = directiveElem.isolateScope();
spyOn(isolatedScope, '$emit');
isolatedScope.updateDateTime('actual');
isolatedScope.save();
expect(isolatedScope.$emit).toHaveBeenCalledWith('saveChangesRequest', jasmine.any(Object), true);
});
it('should close on cancel press', function () {
scope.ticket = new IncidentVO();
var directiveElem = getCompiledElement(scope.ticket, true, true).find('.edit-ticket-dates');
var isolatedScope = directiveElem.isolateScope();
spyOn(isolatedScope, '$emit');
rootScope.$broadcast('discardChanges');
expect(isolatedScope.$emit).toHaveBeenCalledWith('saveChangesComplete');
});
it('should honour broadcasts', function () {
scope.ticket = new IncidentVO();
getCompiledElement(scope.ticket, true, true).find('.edit-ticket-dates');
spyOn(rootScope, '$broadcast').and.callThrough();
rootScope.$broadcast('toggleEditMode');
rootScope.$broadcast('saveAllChangesComplete');
});
});