/*** Created by npatil2 .*/ describe('factory: searchModel', function () { var $httpBackend; beforeEach(module('myitsmApp')); beforeEach(inject(function ($injector, configurationModel, permissionModel, $rootScope, searchService, $q, roles, userModel, metadataModel, assetService) { $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('/smartit/rest/v2/metadata?type=global').respond(200); $httpBackend.whenGET('views/dashboard/index.html').respond(200); $httpBackend.whenGET('/smartit/restapi/person/supportgroupperson').respond(200); this.$rootScope = $injector.get('$rootScope'); this.searchModel = $injector.get('searchModel'); this.configurationModel = configurationModel; this.permissionModel = permissionModel; this.searchService = searchService; this.$q = $q; this.roles = roles; this.userModel = userModel; this.metadataModel = metadataModel; this.assetService = assetService; })); beforeEach(inject(function ($q, $rootScope) { var deferred = $q.defer(), data = { items: [ { searchId: 'DummySearchID00001', results: [ { additionalInformation: { assignee: { fullName: 'Test User1', loginId: 'testuser1', customFields: {} }, status: { value: 'Assigned' }, priority: 'Low', categorizations: [ { name: 'operational', tiers: { operationCategoryTier1: 'Facilities', operationCategoryTier2: 'Conference Room', operationCategoryTier3: 'Projector' } }, { name: 'product', tiers: { productCategoryTier1: 'Hardware', productCategoryTier2: 'Peripheral', productCategoryTier3: 'Projector' } } ], createDate: 1507296006000, modifiedDate: 1507296006000 }, category: 'tickets', displayId: 'WO211', id: 'IDGAA5V0HGVEGAOX4KZSOW810D3JG3', relevancy: 66, type: 'workorder', templateName: '', visited: false, subType: '' } ], totalCount: 35, chunkIndex: true, nextChunkIndex: 0, searchCategory: 'tickets', active: true, sortOrder: 1 } ], totalCount: 35 }; spyOn(this.metadataModel, 'getMetadataByType').and.callFake(function () { deferred.resolve(data); return deferred.promise; }); spyOn(this.userModel, 'getFullCurrentUserData').and.callFake(function () { deferred.resolve(data); return deferred.promise; }); spyOn(this.searchService, 'getGlobalSearchResults').and.callFake(function () { deferred.resolve('sucess'); return deferred.promise; }); spyOn(this.searchService, 'getAssigneeSupportGroupsList').and.callFake(function () { deferred.resolve(data); return deferred.promise; }); spyOn(this.searchService, 'getSupportGroupsList').and.callFake(function () { deferred.resolve({supportGroups: data}); return deferred.promise; }); spyOn(this.searchService, 'getListOfServiceByText').and.callFake(function () { deferred.resolve(data); return deferred.promise; }); spyOn(this.searchService, 'getApproverSupportCompanies').and.callFake(function () { deferred.resolve(data); return deferred.promise; }); spyOn(this.searchService, 'getApproverSupportOrganizations').and.callFake(function () { deferred.resolve(data); return deferred.promise; }); spyOn(this.searchService, 'getFilteredOutagesList').and.callFake(function () { deferred.resolve(data); return deferred.promise; }); spyOn(this.searchService, 'getSitesByCompany').and.callFake(function () { deferred.resolve(data); return deferred.promise; }); spyOn(this.searchService, 'searchCIsRelatedToChangeRequestByCriteria').and.callFake(function () { deferred.resolve(data); return deferred.promise; }); spyOn(this.assetService, 'getListOfAssetsByType').and.callFake(function () { deferred.resolve(data); return deferred.promise; }); spyOn(this.searchService, 'getFoundationItems').and.callFake(function () { var foundationData = {foundationItems:data}; deferred.resolve(foundationData); return deferred.promise; }); spyOn(this.searchService, 'getOrganizationsByCompany').and.callFake(function () { deferred.resolve(data); return deferred.promise; }); spyOn(this.searchService, 'getAssigneeSupportOrgByCompany').and.callFake(function () { deferred.resolve(data); return deferred.promise; }); spyOn(this.searchService, 'getSupportOrganizationsByCompany').and.callFake(function () { deferred.resolve(data); return deferred.promise; }); spyOn(this.searchService, 'getSupportOrganizationsByTextAndCompany').and.callFake(function () { deferred.resolve(data); return deferred.promise; }); spyOn(this.searchService, 'getSmartSearchResults').and.callFake(function () { deferred.resolve(data); return deferred.promise; }); spyOn(this.searchService, 'getSuggestedSearchResults').and.callFake(function () { deferred.resolve(data); return deferred.promise; }); spyOn(this.searchService, 'getSitesByText').and.callFake(function () { deferred.resolve(data); return deferred.promise; }); spyOn(this.searchService, 'getOrganizationsByText').and.callFake(function () { deferred.resolve(data); return deferred.promise; }); spyOn(this.searchService, 'getOrganizationsByTextAndCompany').and.callFake(function () { deferred.resolve(data); return deferred.promise; }); spyOn(this.searchService, 'getSupportOrganizationsByText').and.callFake(function () { deferred.resolve(data); return deferred.promise; }); spyOn(this.searchService, 'getSupportCompaniesByText').and.callFake(function () { deferred.resolve(data); return deferred.promise; }); spyOn(this.searchService, 'getAssigneeSupportCompaniesByText').and.callFake(function () { deferred.resolve(data); return deferred.promise; }); spyOn(this.searchService, 'getOutages').and.callFake(function () { deferred.resolve(data); return deferred.promise; }); spyOn(this.searchService, 'getCompaniesByText').and.callFake(function () { deferred.resolve({companies: data, exceedsChunkSize: true}); return deferred.promise; }); spyOn(this.searchService, 'getAssigneeByText').and.callFake(function () { deferred.resolve(data); return deferred.promise; }); })); it('should be defined', function () { expect(this.searchModel).toBeDefined(); }); it('should load More Global Search Results', function () { this.searchText = 'incident'; this.filters = { types: [ 'tickets' ] }; this.suggestSearch = true; this.chunkIndex = true; this.myResult = this.searchModel.getGlobalSearchResults(this.searchText, this.filters, this.chunkIndex, this.suggestSearch); this.$rootScope.$apply(); expect(this.searchModel.globalSearchResults).toEqual('sucess'); }); it('should return Foundation Regions By Text', function () { this.searchText = 'incident'; this.myResult = this.searchModel.getFoundationRegionsByText(this.searchText); this.$rootScope.$apply(); expect(this.myResult.$$state.value.items).toBeDefined(); }); it('should return Foundation Site Groups By Text', function () { this.searchText = 'incident'; this.myResult = this.searchModel.getFoundationSiteGroupsByText(this.searchText); this.$rootScope.$apply(); expect(this.myResult.$$state.value.items).toBeDefined(); }); it('should return Foundation Sites By Text', function () { this.searchText = 'incident'; this.myResult = this.searchModel.getFoundationSitesByText(this.searchText); this.$rootScope.$apply(); expect(this.myResult.$$state.value.items).toBeDefined(); }); it('should return Sites By Text', function () { this.searchText = 'incident'; this.myResult = this.searchModel.getSitesByText(this.searchText); this.$rootScope.$apply(); expect(this.myResult.$$state.value.items).toBeDefined(); }); it('should return Sites By Text And Company', function () { this.searchText = 'incident'; this.companyName = 'collabroService'; this.myResult = this.searchModel.getSitesByTextAndCompany(this.searchText); this.$rootScope.$apply(); expect(this.myResult.$$state.value.items).toBeDefined(); }); it('should return Organizations By Text', function () { this.searchText = 'incident'; this.chunkSize = 0; this.myResult = this.searchModel.getOrganizationsByText(this.searchText, this.chunkSize); this.$rootScope.$apply(); expect(this.myResult.$$state.value.items).toBeDefined(); }); it('should return Organizations By Text And Company', function () { this.searchText = 'incident'; this.chunkSize = 0; this.companyName = 'collabroService'; this.myResult = this.searchModel.getOrganizationsByTextAndCompany(this.searchText, this.companyName, this.chunkSize); this.$rootScope.$apply(); expect(this.myResult.$$state.value.items).toBeDefined(); }); it('should return Support Organizations By Text', function () { this.searchText = 'incident'; this.chunkSize = 0; this.companyName = 'collabroService'; this.myResult = this.searchModel.getSupportOrganizationsByText(this.searchText, this.companyName, this.chunkSize); this.$rootScope.$apply(); expect(this.myResult.$$state.value.items).toBeDefined(); }); it('should return Support Companies By Text', function () { this.searchText = 'incident'; this.chunkSize = 0; this.options = true; this.myResult = this.searchModel.getSupportCompaniesByText(this.searchText, this.options, this.chunkSize); this.$rootScope.$apply(); expect(this.myResult.$$state.value.items).toBeDefined(); }); it('should return Assignee Support Companies By Text ', function () { this.searchText = 'incident'; this.chunkSize = 0; this.options = true; this.myResult = this.searchModel.getAssigneeSupportCompaniesByText(this.searchText, this.options, this.chunkSize); this.$rootScope.$apply(); expect(this.myResult.$$state.value.items).toBeDefined(); }); it('should return Outages ', function () { this.searchParams = true; this.myResult = this.searchModel.getOutages(this.searchParams); this.$rootScope.$apply(); expect(this.myResult.$$state.value.items).toBeDefined(); }); it('should return Support Companies ', function () { this.options = true; this.chunkSize = 1; this.myResult = this.searchModel.getSupportCompanies(this.options, this.chunkSize); this.$rootScope.$apply(); expect(this.myResult.$$state.value.items).toBeDefined(); }); it('should return Assignee Support Companies ', function () { this.options = true; this.chunkSize = 1; this.myResult = this.searchModel.getAssigneeSupportCompanies(this.options, this.chunkSize); this.$rootScope.$apply(); expect(this.myResult.$$state.value.items).toBeDefined(); }); it('should return Assignee Support Groups For Company And Org By Name', function () { this.companyName = 'collabroService'; this.orgName = true; this.chunkSize = 1; this.name = 'incident'; this.customerCompany = true; this.locationCompany = true; this.ownerCompany = true; this.primaryCompany = true; this.authorCompany = true; this.myResult = this.searchModel.getAssigneeSupportGroupsForCompanyAndOrgByName(this.companyName, this.orgName, this.name, this.customerCompany, this.locationCompany, this.ownerCompany, this.primaryCompany, this.authorCompany); this.$rootScope.$apply(); expect(this.myResult.$$state.value.items).toBeDefined(); }); it('should return Assignee Support Groups For Company And Org', function () { this.companyName = 'collabroService'; this.orgName = true; this.chunkSize = 1; this.name = 'incident'; this.customerCompany = true; this.locationCompany = true; this.ownerCompany = true; this.primaryCompany = true; this.authorCompany = true; this.myResult = this.searchModel.getAssigneeSupportGroupsForCompanyAndOrg(this.companyName, this.orgName, this.name, this.customerCompany, this.locationCompany, this.ownerCompany, this.primaryCompany, this.authorCompany); this.$rootScope.$apply(); this.role = false; this.companyName = null; this.orgName = false; this.customerCompany = false; this.locationCompany = false; this.ownerCompany = false; this.authorCompany = false; this.myResult = this.searchModel.getAssigneeSupportGroupsForCompanyAndOrg(this.companyName, this.orgName, this.role, this.name, this.customerCompany, this.locationCompany, this.ownerCompany, this.primaryCompany, this.authorCompany); this.$rootScope.$apply(); expect(this.myResult.$$state.value.items).toBeDefined(); }); it('should return Support Groups For Company And Org', function () { this.companyName = 'collabroService'; this.orgName = true; this.chunkSize = 1; this.name = 'incident'; this.customerCompany = true; this.locationCompany = true; this.ownerCompany = true; this.primaryCompany = true; this.authorCompany = true; this.myResult = this.searchModel.getSupportGroupsForCompanyAndOrg(this.companyName, this.orgName, this.name, this.customerCompany, this.locationCompany, this.ownerCompany, this.primaryCompany, this.authorCompany); this.$rootScope.$apply(); this.role = false; this.companyName = null; this.myResult = this.searchModel.getSupportGroupsForCompanyAndOrg(this.companyName, this.orgName, this.role, this.name, this.customerCompany, this.locationCompany, this.ownerCompany, this.primaryCompany, this.authorCompany); this.$rootScope.$apply(); expect(this.myResult.$$state.value.supportGroups.items).toBeDefined(); }); it('should return Support Groups For Company And Org By Name', function () { this.companyName = 'collabroService'; this.orgName = true; this.name = 'incident'; this.chunkSize = 1; this.myResult = this.searchModel.getSupportGroupsForCompanyAndOrgByName(this.companyName, this.orgName, this.name, this.chunkSize); expect(this.myResult.$$state.value.supportGroups.items).toBeDefined(); }); it('should return Affected Business Service', function () { this.searchText = 'incident'; this.myResult = this.searchModel.getAffectedBusinessService(this.searchText); this.$rootScope.$apply(); expect(this.myResult.$$state.value.items).toBeDefined(); }); it('should return Support Groups', function () { this.searchModel.allGroups = true; this.myResult = this.searchModel.getSupportGroups(); this.$rootScope.$apply(); expect(this.myResult.$$state.value.supportGroups).toBeDefined(); }); it('should return Support Groups For Role', function () { this.role = true; this.myResult = this.searchModel.getSupportGroupsForRole(this.role); this.$rootScope.$apply(); expect(this.myResult.$$state.value.supportGroups.items).toBeDefined(); }); it('should return Support Groups For KA Share', function () { this.chunkSize = 1; this.myResult = this.searchModel.getSupportGroupsForKAShare(this.chunkSize); this.$rootScope.$apply(); expect(this.myResult.$$state.value.supportGroups.items).toBeDefined(); }); it('should return Support Groups By Text', function () { this.searchText = 'incident'; this.myResult = this.searchModel.getSupportGroupsByText(this.searchText); this.$rootScope.$apply(); expect(this.myResult.$$state.value.supportGroups.items).toBeDefined(); }); it('should return Change Manager Groups By Text', function () { this.searchText = 'incident'; this.myResult = this.searchModel.getChangeManagerGroupsByText(this.searchText); this.$rootScope.$apply(); expect(this.myResult.$$state.value.items).toBeDefined(); }); it('should return Change Coordinator Groups By Text ', function () { this.searchText = 'incident'; this.myResult = this.searchModel.getChangeCoordinatorGroupsByText(this.searchText); this.$rootScope.$apply(); expect(this.myResult.$$state.value.items).toBeDefined(); }); it('should return Problem Coordinator Groups By Text ', function () { this.searchText = 'incident'; this.myResult = this.searchModel.getProblemCoordinatorGroupsByText(this.searchText); this.$rootScope.$apply(); expect(this.myResult.$$state.value.items).toBeDefined(); }); it('should return Release Coordinator Groups By Text ', function () { this.searchText = 'incident'; this.myResult = this.searchModel.getReleaseCoordinatorGroupsByText(this.searchText); this.$rootScope.$apply(); expect(this.myResult.$$state.value.items).toBeDefined(); }); it('should return Approver Support Companies ', function () { this.searchText = 'incident'; this.chunkSize = 1; this.myResult = this.searchModel.getApproverSupportCompanies(this.searchText, this.chunkSize); this.$rootScope.$apply(); expect(this.myResult.$$state.value.items).toBeDefined(); }); it('should return Approver Support Organizations ', function () { this.searchText = false; this.chunkSize = 1; this.companyName = 'collabroService'; this.myResult = this.searchModel.getApproverSupportOrganizations(this.searchText, this.companyName, this.chunkSize); this.$rootScope.$apply(); expect(this.myResult.$$state.value.items).toBeDefined(); this.companyName = null; this.myResult = this.searchModel.getApproverSupportOrganizations(this.searchText, this.companyName, this.chunkSize); this.$rootScope.$apply(); expect(this.myResult.$$state.value).toEqual([]); }); it('should return Approver Support Groups ', function () { this.searchText = 'incident'; this.chunkSize = 1; this.companyName = 'Calbro Service'; this.orgName = true; this.myResult = this.searchModel.getApproverSupportGroups(this.searchText, this.companyName, this.orgName, this.chunkSize); this.$rootScope.$apply(); expect(this.myResult.$$state.value.supportGroups.items).toBeDefined(); this.companyName = null; this.myResult = this.searchModel.getApproverSupportGroups(this.searchText, this.companyName, this.orgName, this.chunkSize); this.$rootScope.$apply(); expect(this.myResult.$$state.value).toEqual({supportGroups: [], exceedsChunkSize: false}); }); it('should return Filtered Outages List ', function () { this.filters = true; this.ticket = 'incident'; this.myResult = this.searchModel.getFilteredOutagesList(this.filters, this.ticket); this.$rootScope.$apply(); expect(this.myResult.$$state.value.items).toBeDefined(); this.filters = false; this.myResult = this.searchModel.getFilteredOutagesList(this.filters, this.ticket); this.$rootScope.$apply(); expect(this.myResult.$$state.value.error).toBeDefined(); }); it('should return Filtered Suggested Outages List ', function () { this.ticket = 'incident'; this.myResult = this.searchModel.getFilteredSuggestedOutagesList(this.ticket); this.$rootScope.$apply(); expect(this.myResult.$$state.value.items).toBeDefined(); }); it('should search CIs Related To Change Request By Criteria ', function () { this.ticket = 'incident'; this.params = false; this.chunkInfo = 1; this.myResult = this.searchModel.searchCIsRelatedToChangeRequestByCriteria(this.ticket, this.params, this.chunkInfo); this.$rootScope.$apply(); expect(this.myResult.$$state.value.error).toBeDefined(); this.ticket = 'incident'; this.params = true; this.myResult = this.searchModel.searchCIsRelatedToChangeRequestByCriteria(this.ticket, this.params, this.chunkInfo); this.$rootScope.$apply(); expect(this.myResult.$$state.value.items).toBeDefined(); }); it('should search Business Service By Keyword ', function () { this.searchText = 'incident'; this.myResult = this.searchModel.searchBusinessServiceByKeyword(this.searchText); this.$rootScope.$apply(); expect(this.myResult.$$state.value).toEqual([]); }); it('should return Foundation Suppliers By Text ', function () { this.searchText = 'incident'; this.myResult = this.searchModel.getFoundationSuppliersByText(this.searchText); this.$rootScope.$apply(); expect(this.myResult.$$state.value.items).toBeDefined(); }); it('should return Foundation Manufacturers By Text ', function () { this.searchText = 'incident'; this.myResult = this.searchModel.getFoundationManufacturersByText(this.searchText); this.$rootScope.$apply(); expect(this.myResult.$$state.value.items).toBeDefined(); }); it('should return Operating Companies ', function () { this.options = { customerCompany: true, ownerCompany: true }; this.searchModel.operatingCompanies = false; this.myResult = this.searchModel.getOperatingCompanies(this.options); this.$rootScope.$apply(); expect(this.myResult.$$state.value.items).toBeDefined(); }); it('should return Organizations By Company ', function () { this.companyName = 'collabroService'; this.chunkSize = 1; this.myResult = this.searchModel.getOrganizationsByCompany(this.companyName, this.chunkSize); this.$rootScope.$apply(); expect(this.myResult.$$state.value.items).toBeDefined(); }); it('should return Assignee By Text', function () { this.searchText = 'incident'; this.myResult = this.searchModel.getAssigneeByText(this.searchText); this.$rootScope.$apply(); expect(this.myResult.$$state.value.items).toBeDefined(); }); it('should return tAssignee Support Org By Company ', function () { this.companyName = 'collabroService'; this.orgName = true; this.chunkSize = 1; this.role = true; this.name = 'incident'; this.customerCompany = true; this.locationCompany = true; this.ownerCompany = true; this.primaryCompany = true; this.authorCompany = true; this.myResult = this.searchModel.getAssigneeSupportOrgByCompany(this.companyName, this.chunkSize, this.role, this.customerCompany, this.locationCompany, this.ownerCompany, this.primaryCompany, this.authorCompany); this.$rootScope.$apply(); expect(this.myResult.$$state.value.items).toBeDefined(); }); it('should return Support Organizations By Company ', function () { this.companyName = 'collabroService'; this.orgName = true; this.chunkSize = 1; this.role = true; this.name = 'incident'; this.customerCompany = true; this.locationCompany = true; this.ownerCompany = true; this.primaryCompany = true; this.authorCompany = true; this.myResult = this.searchModel.getSupportOrganizationsByCompany(this.companyName, this.chunkSize, this.role, this.customerCompany, this.locationCompany, this.ownerCompany, this.primaryCompany); this.$rootScope.$apply(); expect(this.myResult.$$state.value.items).toBeDefined(); }); it('should return Support Organizations By Text And Company ', function () { this.companyName = 'collabroService'; this.orgName = true; this.chunkSize = 1; this.customerCompany = true; this.locationCompany = true; this.ownerCompany = true; this.primaryCompany = true; this.searchText = 'incident'; this.myResult = this.searchModel.getSupportOrganizationsByTextAndCompany(this.searchText, this.companyName, this.chunkSize, this.customerCompany, this.locationCompany, this.ownerCompany, this.primaryCompany); this.$rootScope.$apply(); expect(this.myResult.$$state.value.items).toBeDefined(); }); it('should run Smart Search ', function () { this.searchText = 'incident'; this.myResult = this.searchModel.runSmartSearch(this.searchText); this.$rootScope.$apply(); expect(this.searchModel.smartSearchResults).toBeTruthy(); }); it('should return Suggested Search Results ', function () { this.searchText = 'incident'; this.myResult = this.searchModel.getSuggestedSearchResults(this.searchText); this.$rootScope.$apply(); expect(this.myResult.$$state.value.items).toBeDefined(); }); });