/** * Created by andey on 29-05-2017. */ describe('Test edit ticket 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=workorder").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(); }); /*inject(function ($injector) { var $filter = $injector.get('$filter'); localeFilter = $filter('i18n'); });*/ }); function getCompiledElement() { var element = angular.element('
'); var compiledElement = compile(element)(scope); scope.$digest(); return compiledElement; } it('should compile', function () { scope.ticket = new WorkOrderVO(); var directiveElem = getCompiledElement(); var divElem = directiveElem[0]; expect(divElem).toBeDefined(); expect(directiveElem.find('.edit-ticket-dates').length).not.toBeLessThan(1); }); it('should change dates and save', function () { scope.ticket = new WorkOrderVO(); scope.ticket.timing = true; var directiveElem = getCompiledElement().find('.edit-ticket-dates'); var isolatedScope = directiveElem.isolateScope(); spyOn(isolatedScope, '$emit'); isolatedScope.updateDateTime('actual'); isolatedScope.updateTargetDate(); rootScope.$broadcast('saveChanges'); expect(isolatedScope.$emit).toHaveBeenCalledWith('saveChangesRequest', jasmine.any(Object), true); }); it('should change dates and save for draft', function () { scope.ticket = new WorkOrderVO(); scope.ticket.timing = true; scope.isDraft = true; var directiveElem = getCompiledElement().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 WorkOrderVO(); var directiveElem = getCompiledElement().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 WorkOrderVO(); var directiveElem = getCompiledElement().find('.edit-ticket-dates'); spyOn(rootScope, '$broadcast').and.callThrough(); rootScope.$broadcast('toggleEditMode'); rootScope.$broadcast('saveAllChangesComplete'); var isolatedScope = directiveElem.isolateScope(); isolatedScope.save(); }); });