199 lines
6.5 KiB
JavaScript
199 lines
6.5 KiB
JavaScript
/*** Created by npatil2 .*/
|
|
describe('SearchController', function () {
|
|
'use strict';
|
|
|
|
var $httpBackend;
|
|
|
|
beforeEach(module('myitsmApp'));
|
|
beforeEach(inject(function ($injector, $rootScope, $controller, searchModel, $state, $timeout, $window, $filter, i18nService, events, configurationModel, searchService) {
|
|
this.scope = $rootScope.$new();
|
|
this.searchModel = searchModel;
|
|
this.$state = $state;
|
|
this.$timeout = $timeout;
|
|
this.$window = $window;
|
|
this.controller = $controller;
|
|
this.$filter = $filter;
|
|
this.configurationModel = configurationModel;
|
|
this.searchService = searchService;
|
|
this.i18nService = i18nService;
|
|
this.events = events;
|
|
|
|
this.controllerInstance = this.controller('SearchController', {
|
|
$scope: this.scope
|
|
});
|
|
}));
|
|
|
|
beforeEach(inject(function ($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=global').respond(200);
|
|
$httpBackend.whenGET('/smartit/restapi/person/supportgroupperson').respond(200);
|
|
$httpBackend.whenGET('/smartit/rest/serverstates').respond(200);
|
|
$httpBackend.whenGET('/smartit/rest/sessionstatus?getLicenseKey=true').respond(200);
|
|
$httpBackend.whenGET('views/dashboard/index.html').respond(200);
|
|
}));
|
|
|
|
beforeEach(inject(function ($q, $rootScope) {
|
|
var deferred = $q.defer(), success = {
|
|
items: {
|
|
searchCategory: 'test1',
|
|
displayLimit: 'test3',
|
|
test4: 'test5'
|
|
}
|
|
};
|
|
|
|
spyOn(this.searchModel, 'loadMoreGlobalSearchResults').and.callFake(function () {
|
|
deferred.resolve(success);
|
|
return deferred.promise;
|
|
});
|
|
|
|
spyOn(this.searchService, 'setSelectedTargetArea').and.callFake(function () {
|
|
deferred.resolve(success);
|
|
return deferred.promise;
|
|
});
|
|
|
|
spyOn(this.searchModel, 'categoriesConfig').and.callFake(function () {
|
|
deferred.resolve(success);
|
|
return deferred.promise;
|
|
});
|
|
|
|
spyOn(this.searchModel, 'getGlobalSearchResults').and.callFake(function () {
|
|
deferred.resolve(success);
|
|
return deferred.promise;
|
|
});
|
|
}));
|
|
|
|
it('should be defined', function () {
|
|
expect(this.controllerInstance).toBeDefined();
|
|
});
|
|
|
|
it('should clear All Filters', function () {
|
|
this.scope.clearAllFilters();
|
|
expect(this.scope.isAllResultsDisplaying).toBe(true);
|
|
expect(this.scope.selectedCategory).toBeDefined();
|
|
expect(this.scope.searchModel.selectedFilters).toBeDefined();
|
|
expect(this.scope.searchModel.filterCriteria).toBeDefined();
|
|
});
|
|
|
|
it('should change Search Criteria ()', function () {
|
|
this.targetAreaObj = {
|
|
types: 'test'
|
|
};
|
|
|
|
this.scope.searchModel.globalSearchResults = {
|
|
items: [
|
|
{
|
|
id: '12td',
|
|
name: 'tp',
|
|
totalCount: 2,
|
|
displayLimit: 5,
|
|
active: true,
|
|
searchCategory: 'test'
|
|
},
|
|
{
|
|
id: '12td',
|
|
name: 'tp',
|
|
totalCount: 2,
|
|
displayLimit: 5,
|
|
active: true,
|
|
searchCategory: 'test'
|
|
},
|
|
{
|
|
id: '12td',
|
|
name: 'tp',
|
|
totalCount: 2,
|
|
displayLimit: 5,
|
|
active: true,
|
|
searchCategory: 'test'
|
|
}
|
|
|
|
]
|
|
};
|
|
|
|
this.scope.selectedCategory = {
|
|
name: 'test',
|
|
totalCount: 0
|
|
};
|
|
|
|
this.scope.defaultDisplayLimit = 5;
|
|
this.scope.searchText = 'test';
|
|
this.scope.changeSearchCriteria(this.targetAreaObj);
|
|
expect(this.scope.isSearchDataLoading).toBe(true);
|
|
this.scope.$apply();
|
|
expect(this.scope.searchResults).toBeDefined();
|
|
expect(this.scope.isSearchDataLoading).toBe(false);
|
|
});
|
|
|
|
it('should close Category', function () {
|
|
this.scope.selectedCategory = 'incident';
|
|
this.searchModel.filterCriteria = {
|
|
types: 'incident',
|
|
searchCompanies: 'test search',
|
|
createDateRange: 'test data range',
|
|
modifiedDateRange: 'modified data range',
|
|
statuses: 'empty'
|
|
};
|
|
|
|
this.searchModel.selectedFilters = {
|
|
test: 'test by name',
|
|
testId: 'test by id'
|
|
};
|
|
|
|
this.scope.closeCategory();
|
|
expect(this.scope.isAllResultsDisplaying).toBe(true);
|
|
expect(this.scope.selectedCategory).toBeDefined();
|
|
});
|
|
|
|
it('should loadMore Category Items', function () {
|
|
this.scope.isSearchDataLoading = false;
|
|
this.scope.isAllResultsDisplaying = false;
|
|
this.scope.searchResults.items = {
|
|
searchCategory: [
|
|
{
|
|
id: 'tp234',
|
|
name: 'tp testt'
|
|
}, {
|
|
id: 'tp234',
|
|
name: 'tp testt'
|
|
}
|
|
],
|
|
totalCount: 123,
|
|
chunkIndex: 1
|
|
|
|
};
|
|
|
|
this.searchModel.chunkSize = 2;
|
|
this.scope.selectedCategory = {};
|
|
this.myResult = this.scope.loadMoreCategoryItems();
|
|
expect(this.scope.isSearchDataLoading).toBe(false);
|
|
});
|
|
|
|
it('should trigger List Limit and selectItem', function () {
|
|
this.section = {
|
|
displayLimit: 15
|
|
};
|
|
|
|
this.scope.defaultDisplayLimit = 15;
|
|
this.arr = ['test', 'test1', 'test2'];
|
|
this.scope.triggerListLimit(this.arr, this.section);
|
|
this.scope.defaultDisplayLimit = 15;
|
|
this.scope.triggerListLimit(this.arr, this.section);
|
|
});
|
|
|
|
it('should trigger event SET_PREVIEW_ITEM', inject(function ($rootScope) {
|
|
var $rootScope = $rootScope, previewItem = {
|
|
id: 123,
|
|
type: 'test'
|
|
};
|
|
|
|
$rootScope.$broadcast(this.events.SET_PREVIEW_ITEM, previewItem);
|
|
expect(this.scope.selectedItem.id).toEqual(123);
|
|
expect(this.scope.selectedItem.type).toEqual('test');
|
|
}));
|
|
});
|