SmartIT_Extensions/BMC/smart-it-full/test/app/ticket/copy-change-controller.spec.js

105 lines
3.3 KiB
JavaScript

describe('CopyChangeController', function () {
var $httpBackend, modalInstance, ticket;
beforeEach(module('myitsmApp'));
beforeEach(inject(function ($injector, $rootScope, $controller, $q, systemAlertService, ticketService, $state) {
$httpBackend = $injector.get('$httpBackend');
this.$rootScope = $rootScope;
this.scope = $rootScope.$new();
this.controller = $controller;
this.$q = $q;
this.systemAlertService = systemAlertService;
this.ticketService = ticketService;
this.state = $state;
modalInstance = {
close: jasmine.createSpy('modalInstance.close'),
dismiss: jasmine.createSpy('modalInstance.dismiss'),
result: {
then: jasmine.createSpy('modalInstance.result.then')
}
};
ticket = {
id: "IDGAA5V0HHE9CAP50PBNP43RBWLPR4"
};
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);
$httpBackend.whenGET('views/dashboard/index.html').respond(200);
this.controllerInstance = this.controller('CopyChangeController', {
$scope: this.scope,
$modalInstance: modalInstance,
ticket: ticket
});
}));
beforeEach(function () {
this.ticket = {
id: 'AG00123F73CF5EWtETSQsWU8Ag_UgB'
};
this.type = {
testType: 'test foo'
};
this.isCheckedAll = false;
this.copyOptions = {
copyRequestForCustomer: 'No',
copyCI: 'No',
copyImpactedAreas: 'No',
copyRelatedChange: 'No',
copyDocument: 'No',
copyTaskAutomatic: 'No',
copyTaskManual: 'No',
copyTaskCancelled: 'No',
copyTaskFailed: 'No'
};
});
afterEach(inject(function ($rootScope) {
$rootScope.$apply();
}));
it('should defined', function () {
expect(this.controllerInstance).toBeDefined();
});
it('should run init', function () {
this.scope.init()
expect(this.scope.ticket.id).toBe(ticket.id);
expect(this.scope.state.processing).toBeFalsy();
});
it('should call toggleSelectAll', function () {
this.scope.toggleSelectAll();
expect(this.scope.copyOptions.copyRequestForCustomer).toBe('Yes');
});
it('should call close', function () {
this.scope.close();
expect(modalInstance.dismiss).toHaveBeenCalled();
});
it('should call copyChnage', function() {
var deferred = this.$q.defer(),
ticket = {
id: "IDGAA5V0HHE9CAP50PBNP43RBWLPR4"
}
spyOn(this.ticketService, 'copyChange').and.callFake(function () {
deferred.resolve(ticket);
return deferred.promise;
});
spyOn(this.state, 'go');
this.scope.copyChange();
this.scope.$apply();
expect(this.ticketService.copyChange).toHaveBeenCalled();
expect(this.state.go).toHaveBeenCalled();
});
});