123 lines
4.4 KiB
JavaScript
123 lines
4.4 KiB
JavaScript
/*** Created by npatil2.*/
|
|
describe('SearchBarController', function () {
|
|
'use strict';
|
|
|
|
var $httpBackend;
|
|
|
|
beforeEach(module('myitsmApp'));
|
|
beforeEach(inject(function ($injector, $rootScope, $controller, searchModel, $state, $timeout, $location, metadataModel, configurationModel, searchService) {
|
|
this.scope = $rootScope.$new();
|
|
this.searchModel = searchModel;
|
|
this.$state = $state;
|
|
this.$timeout = $timeout;
|
|
this.$location = $location;
|
|
this.controller = $controller;
|
|
this.metadataModel = metadataModel;
|
|
this.configurationModel = configurationModel;
|
|
this.searchService = searchService;
|
|
}));
|
|
|
|
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);
|
|
$httpBackend.whenGET('/smartit/rest/map_api_properties').respond(200);
|
|
|
|
}));
|
|
|
|
beforeEach(inject(function ($q) {
|
|
var data = 'success', metadata = {
|
|
configurationParameters: {
|
|
skipWildcardInGlobalSearch: true,
|
|
disableTypeaheadInGlobalSearch: 'true'
|
|
}
|
|
};
|
|
this.scope.disableTypeaheadInGlobalSearch = false;
|
|
spyOn(this.searchModel, 'getSuggestedSearchResults').and.callFake(function () {
|
|
var deferred = $q.defer();
|
|
deferred.resolve(data);
|
|
return deferred.promise;
|
|
});
|
|
|
|
spyOn(this.metadataModel, 'getMetadataByType').and.callFake(function () {
|
|
var deferred = $q.defer();
|
|
deferred.resolve(metadata);
|
|
return deferred.promise;
|
|
});
|
|
|
|
this.controllerInstance = this.controller('SearchBarController', {
|
|
$scope: this.scope
|
|
});
|
|
}));
|
|
|
|
it('should be defined', function () {
|
|
expect(this.controllerInstance).toBeDefined();
|
|
});
|
|
|
|
it('should change disableTypeaheadInGlobalSearch', function () {
|
|
this.scope.$apply();
|
|
expect(this.scope.disableTypeaheadInGlobalSearch).toEqual(true);
|
|
});
|
|
|
|
xit('should change Search Criteria', function () {
|
|
this.item = 'test item';
|
|
this.scope.searchText = 'incident';
|
|
this.scope.changeSearchCriteria(this.item);
|
|
expect(this.scope.targetArea).toEqual('test item');
|
|
});
|
|
|
|
it('should activate SearchBar', function () {
|
|
this.scope.activateSearchBar();
|
|
expect(this.scope.isSearchBarActive).toEqual(true);
|
|
});
|
|
|
|
it('should deactivate SearchBar', function () {
|
|
this.scope.deactivateSearchBar();
|
|
expect(this.scope.isSearchBarActive).toEqual(false);
|
|
});
|
|
|
|
it('should move To SearchState', function () {
|
|
this.text = 'incident';
|
|
this.scope.moveToSearchState(this.text);
|
|
expect(this.scope.searchText).toEqual('incident');
|
|
expect(this.scope.isSearchBarActive).toEqual(false);
|
|
});
|
|
|
|
it('should select Suggested Result', function () {
|
|
this.result = 'incident';
|
|
this.scope.selectSuggestedResult(this.result);
|
|
expect(this.scope.searchText).toEqual('incident');
|
|
expect(this.scope.isSearchBarActive).toEqual(false);
|
|
});
|
|
|
|
it('should Suggested Search Results', function () {
|
|
this.text = {
|
|
startsWith: function () {
|
|
return
|
|
}
|
|
};
|
|
|
|
this.myResult = this.scope.getSuggestedSearchResults(this.text);
|
|
this.scope.$apply();
|
|
expect(this.myResult.$$state.value).toEqual('success');
|
|
expect(this.scope.isSearchBarActive).toEqual(true);
|
|
});
|
|
|
|
it('should wildCard Validation', function () {
|
|
this.scope.searchText = '%%incident';
|
|
this.scope.skipWildcardInGlobalSearch = 'true';
|
|
this.scope.wildCardValidation();
|
|
expect(this.scope.searchText).toEqual('incident');
|
|
expect(this.scope.wildCardEntered).toEqual(false);
|
|
});
|
|
});
|