diff --git a/README.md b/README.md index c41ef44..498431b 100644 --- a/README.md +++ b/README.md @@ -1,9 +1,9 @@ # bem-tools-find [![NPM version](http://img.shields.io/npm/v/bem-tools-find.svg?style=flat)](http://www.npmjs.org/package/bem-tools-find) -[![Build Status](https://travis-ci.org/bem-incubator/bem-tools-find.svg)](https://travis-ci.org/bem-incubator/bem-tools-find) -[![Coverage Status](https://coveralls.io/repos/bem-incubator/bem-tools-find/badge.svg?branch=master&service=github)](https://coveralls.io/github/bem-incubator/bem-tools-find?branch=master) -[![David](https://img.shields.io/david/bem-incubator/bem-tools-find.svg)](https://david-dm.org/bem-incubator/bem-tools-find) +[![Build Status](https://travis-ci.org/bem-contrib/bem-tools-find.svg)](https://travis-ci.org/bem-contrib/bem-tools-find) +[![Coverage Status](https://coveralls.io/repos/bem-contrib/bem-tools-find/badge.svg?branch=master&service=github)](https://coveralls.io/github/bem-contrib/bem-tools-find?branch=master) +[![David](https://img.shields.io/david/bem-contrib/bem-tools-find.svg)](https://david-dm.org/bem-contrib/bem-tools-find) ![Logo](./logo.ico) diff --git a/lib/filter.js b/lib/filter.js index 4d3eecb..b1ee22e 100644 --- a/lib/filter.js +++ b/lib/filter.js @@ -40,7 +40,7 @@ Filter.prototype = { * @private */ _byBlock: function(item) { - return this._shouldPass(item, 'blocks', 'block'); + return this._shouldPass(item.entity, 'blocks', 'block'); }, /** diff --git a/lib/util.js b/lib/util.js index b4ea017..ffa1df9 100644 --- a/lib/util.js +++ b/lib/util.js @@ -49,7 +49,7 @@ exports.conditionsFromBEMItems = function(items) { * @returns {Object} */ exports.initializeConfig = function(config) { - config = config.extended; + config = config.extended || {}; /** * Returns list of levels diff --git a/package.json b/package.json index 961fc6d..77ccd39 100644 --- a/package.json +++ b/package.json @@ -40,7 +40,7 @@ "JSONStream": "^1.0.7", "bem-config": "git://github.com/bem-incubator/bem-config.git", "bem-naming": "^0.5.1", - "bem-walk": "0.0.4", + "bem-walk": "1.0.0-1", "chalk": "^1.1.1", "coa": "^1.0.1", "flow-tostring": "^1.0.1", diff --git a/test/lib/filter.js b/test/lib/filter.js index 140e599..6ec0c45 100644 --- a/test/lib/filter.js +++ b/test/lib/filter.js @@ -4,18 +4,56 @@ var Filter = require('../../lib/filter'); describe('Filter', function() { describe('apply', function() { - testBySingleCriteria_('blocks', 'block'); testBySingleCriteria_('elements', 'elem'); testBySingleCriteria_('modifiers', 'modName'); testBySingleCriteria_('techs', 'tech'); + it('should pass block item if no info about blocks provided in config', function() { + var filter = new Filter({}), + item = { + entity: { + block: 'foo' + } + }; + assert.equal(filter.apply(item), true); + }); + + it('should pass block item if block matches blocks to search', function() { + var opts = { + blocks: 'foo' + }; + var filter = new Filter(opts), + item = { + entity: { + block: 'foo' + } + }; + assert.equal(filter.apply(item), true); + }); + + it('should not pass block item if block not match blocks to search', function() { + var opts = { + blocks: ['foo'] + }; + var filter = new Filter(opts), + item = { + entity: { + block: 'bar' + } + }; + + assert.equal(filter.apply(item), false); + }); + it('should not pass if matches block, but not matches elem', function() { var filter = new Filter({ blocks: ['foo'], elements: ['bar'] }), item = { - block: 'foo', + entity: { + block: 'foo' + }, elem: 'baz' }; @@ -28,7 +66,9 @@ describe('Filter', function() { elements: ['bar'] }), item = { - block: 'foo', + entity: { + block: 'foo' + }, elem: 'bar' }; @@ -41,7 +81,9 @@ describe('Filter', function() { modifiers: ['bar'] }), item = { - block: 'foo', + entity: { + block: 'foo' + }, modName: 'baz' }; @@ -54,7 +96,9 @@ describe('Filter', function() { modifiers: ['bar'] }), item = { - block: 'foo', + entity: { + block: 'foo' + }, modName: 'bar' }; @@ -67,7 +111,9 @@ describe('Filter', function() { techs: ['bar'] }), item = { - block: 'foo', + entity: { + block: 'foo' + }, tech: 'baz' }; @@ -80,7 +126,9 @@ describe('Filter', function() { techs: ['bar'] }), item = { - block: 'foo', + entity: { + block: 'foo' + }, tech: 'bar' }; @@ -94,7 +142,9 @@ describe('Filter', function() { modifiers: ['fizz'] }), item = { - block: 'foo', + entity: { + block: 'foo' + }, elem: 'bar', modName: 'buzz' }; @@ -109,7 +159,9 @@ describe('Filter', function() { modifiers: ['fizz'] }), item = { - block: 'foo', + entity: { + block: 'foo' + }, elem: 'bar', modName: 'fizz' }; @@ -125,7 +177,9 @@ describe('Filter', function() { techs: ['buzz'] }), item = { - block: 'foo', + entity: { + block: 'foo' + }, elem: 'bar', modName: 'fizz', tech: 'BAZ' @@ -142,7 +196,9 @@ describe('Filter', function() { techs: ['buzz'] }), item = { - block: 'foo', + entity: { + block: 'foo' + }, elem: 'bar', modName: 'fizz', tech: 'buzz' @@ -158,7 +214,9 @@ describe('Filter', function() { techs: ['buzz'] }), item = { - block: 'foo', + entity: { + block: 'foo' + }, elem: 'bar', tech: 'BAZ' }; @@ -173,7 +231,9 @@ describe('Filter', function() { techs: ['buzz'] }), item = { - block: 'foo', + entity: { + block: 'foo' + }, elem: 'bar', tech: 'buzz' }; @@ -188,7 +248,9 @@ describe('Filter', function() { techs: ['buzz'] }), item = { - block: 'foo', + entity: { + block: 'foo' + }, modName: 'fizz', tech: 'BAZ' }; @@ -203,7 +265,9 @@ describe('Filter', function() { techs: ['buzz'] }), item = { - block: 'foo', + entity: { + block: 'foo' + }, modName: 'fizz', tech: 'buzz' };