Skip to content

Commit 3852a95

Browse files
committed
Filter: fix & test adding filters in options dict
1 parent cf5e039 commit 3852a95

File tree

2 files changed

+39
-1
lines changed

2 files changed

+39
-1
lines changed

src/ui/filter.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ var Filter = exports.Filter = function Filter(options) {
2222
this.filters = [];
2323
this.current = 0;
2424

25-
for (var i = 0, len = this.options.filters; i < len; i++) {
25+
for (var i = 0, len = this.options.filters.length; i < len; i++) {
2626
var filter = this.options.filters[i];
2727
this.addFilter(filter);
2828
}

test/spec/ui/filter_spec.js

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,44 @@ describe('ui.filter.Filter', function () {
7070
});
7171
});
7272

73+
describe("passing filters to constructor", function () {
74+
var testFilter = null;
75+
76+
beforeEach(function () {
77+
testFilter = {
78+
label: 'Tag',
79+
property: 'tags'
80+
};
81+
plugin = new filter.Filter({
82+
filterElement: element,
83+
filters: [testFilter],
84+
addAnnotationFilter: false
85+
});
86+
});
87+
88+
it("should add a filter object to Filter#plugins", function () {
89+
assert.ok(plugin.filters[0]);
90+
});
91+
92+
it("should append the html to Filter#toolbar", function () {
93+
testFilter = plugin.filters[0];
94+
assert.equal(testFilter.element[0], plugin.element.find('#annotator-filter-tags').parent()[0]);
95+
});
96+
97+
it("should store the filter in the elements data store under 'filter'", function () {
98+
testFilter = plugin.filters[0];
99+
assert.equal(testFilter.element.data('filter'), plugin.filters[0]);
100+
});
101+
102+
it("should not add a filter for a property that has already been loaded", function () {
103+
plugin.addFilter({
104+
label: 'Tag',
105+
property: 'tags'
106+
});
107+
assert.lengthOf(plugin.filters, 1);
108+
});
109+
});
110+
73111
describe("updateFilter", function () {
74112
var testFilter = null,
75113
annotations = null;

0 commit comments

Comments
 (0)