Skip to content

Commit

Permalink
#39 Adicionando testes para a pesquisa de tags.
Browse files Browse the repository at this point in the history
  • Loading branch information
RatoX committed Jan 26, 2015
1 parent 984602a commit c80b380
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 1 deletion.
3 changes: 2 additions & 1 deletion app/scripts/services/util/tags-util.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,10 @@ angular.module('cmsApp')
var allTags = {};

var search = function(query){
query = (!!query) ? query.toLowerCase() : '';
var deferred = $q.defer();
var tags = _.map(allTags, function(e){
if(e.match(query)){
if(e.toLowerCase().match(query)){
return {tag: e};
}
return false;
Expand Down
31 changes: 31 additions & 0 deletions test/spec/services/util/tags-util.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,37 @@ describe('Service: TagsUtil', function () {
expect(!!TagsUtil).toBe(true);
});

describe('give a lot of tag-posts file', function (){
var tagsWithPosts, factory;

beforeEach(function () {
tagsWithPosts = {'Banana':['dois','tres', 'sete'],
'Cianureto':['tres','sete'],
'Manga':['dois','quatro'],
'Apollo':['onze','doze'],
'Maca':['quatro', 'seis', 'sete']};

factory = new TagsUtil(tagsWithPosts);
});

it('should search by name without casesensitive', inject(function($rootScope){
var query = 'MaNgA'; //Search by Manga
factory.search(query).then(function(result){
expect(result).toEqual([{tag:'Manga'}]);
});
$rootScope.$digest();
}));

it('should return all tags matched', inject(function($rootScope){
var query = 'M'; //Search by Manga
factory.search(query).then(function(result){
expect(result)
.toEqual(jasmine.objectContaining([{tag: 'Manga'}, {tag: 'Maca'}]));
});
$rootScope.$digest();
}));
});

describe('give a tag-posts file and a set of tags', function (){
var tagsWithPosts, factory;

Expand Down

0 comments on commit c80b380

Please sign in to comment.