/*** Created by npatil2.*/ describe('service: configurationModel', function () { var $httpBackend, scope, metadata; beforeEach(module('myitsmApp')); beforeEach(inject(function ($rootScope, $injector, AUTH_EVENTS, metadataModel, appConfiguration) { scope = $rootScope.$new(); this.AUTH_EVENTS = AUTH_EVENTS; this.appConfiguration = appConfiguration; this.metadataModel = metadataModel; $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); $httpBackend.whenGET('views/dashboard/index.html').respond(200); this.configurationModel = $injector.get('configurationModel'); })); beforeEach(inject(function ($q) { var deferred = $q.defer(); metadata = { configurationParameters: { assignmentCompanyChunkSize: 2, assignmentSupportOrganizationChunkSize: 2, assignmentSupportGroupChunkSize: 2, assignmentSupportPersonChunkSize: 1, disableCollisionManagement: true, disableImpactAnalysis: true, showNameInSmartRecorderCreateTicket: true, dateTimeStyleProperty: true, socialWorklogAccessSetting: true } }; spyOn(this.metadataModel, 'getMetadataByType').and.callFake(function () { deferred.resolve(metadata); return deferred.promise; }); })); it('should defined configurationModel () ', function () { expect(this.configurationModel).toBeDefined(); }); it('should get data ', function () { this.myResult = this.configurationModel.get('enabledServerApplications'); expect(this.myResult).toBeDefined(); }); it('should set enabledServerApplications ', function () { this.configurationModel.set('enabledServerApplications', 'testdata'); expect(this.appConfiguration['enabledServerApplications']).toEqual('testdata'); }); it('should return Week Starting Day ', function () { this.myResult = this.configurationModel.getWeekStartingDay(); expect(this.myResult).toBe(1); }); it('should Server Application Enabled ', function () { this.myResult = this.configurationModel.isServerApplicationEnabled('test app'); expect(this.myResult).toBe(false); }); it('should File Extension Allowed', function () { this.myResult = this.configurationModel.isFileExtensionAllowed('test fileext'); expect(this.myResult).toBe(false); }); it('should trigger $emit for LOGIN_SUCCESS ', function () { scope.$emit(this.AUTH_EVENTS.LOGIN_SUCCESS); scope.$apply(); expect(this.configurationModel).toBeDefined(); expect(this.configurationModel.dateTimeStyleProperty).toBe(true); expect(this.configurationModel.showNameInSmartRecorderCreateTicket).toBe(true); expect(this.configurationModel.disableImpactAnalysis).toBe(true); expect(this.configurationModel.disableCollisionManagement).toBe(true); expect(this.configurationModel.socialWorklogAccessSetting).toBe(true); }); it('should trigger $emit for SESSION_ACTIVE ', function () { scope.$emit(this.AUTH_EVENTS.SESSION_ACTIVE); scope.$apply(); expect(this.configurationModel.dateTimeStyleProperty).toBe(true); expect(this.configurationModel.showNameInSmartRecorderCreateTicket).toBe(true); expect(this.configurationModel.disableImpactAnalysis).toBe(true); expect(this.configurationModel.disableCollisionManagement).toBe(true); expect(this.configurationModel.socialWorklogAccessSetting).toBe(true); }); it('should loadGlobalMetadata on LOGIN_SUCCESS or SESSION_ACTIVE event and will not assign any value if configuration parameter does not have that property', function () { metadata.configurationParameters = {}; scope.$emit(this.AUTH_EVENTS.SESSION_ACTIVE); scope.$apply(); expect(this.configurationModel.dateTimeStyleProperty).toBeUndefined(); expect(this.configurationModel.showNameInSmartRecorderCreateTicket).toBeUndefined(); expect(this.configurationModel.disableImpactAnalysis).toBeUndefined(); expect(this.configurationModel.disableCollisionManagement).toBeUndefined(); expect(this.configurationModel.socialWorklogAccessSetting).toBeFalsy(); }); });