FIX: Don't include child categories when term is black.

This commit is contained in:
Guo Xiang Tan 2016-01-08 11:26:06 +08:00
parent e451d47e84
commit f519834824
2 changed files with 10 additions and 10 deletions

View File

@ -311,7 +311,7 @@ Category.reopenClass({
for (i = 0; i < length && !done(); i++) { for (i = 0; i < length && !done(); i++) {
const category = categories[i]; const category = categories[i];
if ((emptyTerm) || if ((emptyTerm && !category.get('parent_category_id')) ||
(!emptyTerm && category.get('name').toLowerCase().indexOf(term) === 0)) { (!emptyTerm && category.get('name').toLowerCase().indexOf(term) === 0)) {
data.push(category); data.push(category);
} }

View File

@ -149,25 +149,25 @@ test('search', () => {
sandbox.restore(); sandbox.restore();
const category3 = store.createRecord('category', { id: 3, name: 'term start', parent_category_id: category1.get('id') }), const child_category1 = store.createRecord('category', { id: 3, name: 'term start', parent_category_id: category1.get('id') }),
category4 = store.createRecord('category', { id: 4, name: 'some term', read_restricted: true }); read_restricted_category = store.createRecord('category', { id: 4, name: 'some term', read_restricted: true });
sandbox.stub(Category, "listByActivity").returns([category4, category1, category3, category2]); sandbox.stub(Category, "listByActivity").returns([read_restricted_category, category1, child_category1, category2]);
deepEqual(result(''), deepEqual(result(''),
[category1.get('id'), category3.get('id'), category2.get('id'), category4.get('id')], [category1.get('id'), category2.get('id'), read_restricted_category.get('id')],
"prioritize non read_restricted categories when term is blank"); "prioritize non read_restricted and does not include child categories when term is blank");
deepEqual(result('', { limit: 3 }), deepEqual(result('', { limit: 3 }),
[category1.get('id'), category3.get('id'), category4.get('id')], [category1.get('id'), category2.get('id'), read_restricted_category.get('id')],
"prioritize non read_restricted categories when term is blank with limit"); "prioritize non read_restricted and does not include child categories categories when term is blank with limit");
deepEqual(result('term'), deepEqual(result('term'),
[category3.get('id'), category2.get('id'), category1.get('id'), category4.get('id')], [child_category1.get('id'), category2.get('id'), category1.get('id'), read_restricted_category.get('id')],
"prioritize non read_restricted"); "prioritize non read_restricted");
deepEqual(result('term', { limit: 3 }), deepEqual(result('term', { limit: 3 }),
[category3.get('id'), category2.get('id'), category4.get('id')], [child_category1.get('id'), category2.get('id'), read_restricted_category.get('id')],
"prioritize non read_restricted with limit"); "prioritize non read_restricted with limit");
sandbox.restore(); sandbox.restore();