Skip to content

Commit

Permalink
Merge pull request #519 from wjt/filters
Browse files Browse the repository at this point in the history
Filter: fix adding filters from options dict
  • Loading branch information
tilgovi committed May 3, 2015
2 parents cf5e039 + 3852a95 commit cb8d6c4
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/ui/filter.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ var Filter = exports.Filter = function Filter(options) {
this.filters = [];
this.current = 0;

for (var i = 0, len = this.options.filters; i < len; i++) {
for (var i = 0, len = this.options.filters.length; i < len; i++) {
var filter = this.options.filters[i];
this.addFilter(filter);
}
Expand Down
38 changes: 38 additions & 0 deletions test/spec/ui/filter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,44 @@ describe('ui.filter.Filter', function () {
});
});

describe("passing filters to constructor", function () {
var testFilter = null;

beforeEach(function () {
testFilter = {
label: 'Tag',
property: 'tags'
};
plugin = new filter.Filter({
filterElement: element,
filters: [testFilter],
addAnnotationFilter: false
});
});

it("should add a filter object to Filter#plugins", function () {
assert.ok(plugin.filters[0]);
});

it("should append the html to Filter#toolbar", function () {
testFilter = plugin.filters[0];
assert.equal(testFilter.element[0], plugin.element.find('#annotator-filter-tags').parent()[0]);
});

it("should store the filter in the elements data store under 'filter'", function () {
testFilter = plugin.filters[0];
assert.equal(testFilter.element.data('filter'), plugin.filters[0]);
});

it("should not add a filter for a property that has already been loaded", function () {
plugin.addFilter({
label: 'Tag',
property: 'tags'
});
assert.lengthOf(plugin.filters, 1);
});
});

describe("updateFilter", function () {
var testFilter = null,
annotations = null;
Expand Down

0 comments on commit cb8d6c4

Please sign in to comment.