mirror of
https://github.com/discourse/discourse.git
synced 2025-02-25 18:55:32 -06:00
UX: Prioritize categories autocomplete with new rules.
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
import createStore from 'helpers/create-store';
|
||||
import Category from 'discourse/models/category';
|
||||
|
||||
module("model:category");
|
||||
|
||||
@@ -50,6 +51,8 @@ test('findBySlug', function() {
|
||||
deepEqual(Discourse.Category.findBySlug('뉴스피드', '熱帶風暴畫眉'), newsFeed, 'we can find a category with CJK slug whose parent slug is also CJK');
|
||||
deepEqual(Discourse.Category.findBySlug('时间', 'darth'), time, 'we can find a category with CJK slug whose parent slug is english');
|
||||
deepEqual(Discourse.Category.findBySlug('bah', '熱帶風暴畫眉'), bah, 'we can find a category with english slug whose parent slug is CJK');
|
||||
|
||||
sandbox.restore();
|
||||
});
|
||||
|
||||
test('findSingleBySlug', function() {
|
||||
@@ -122,3 +125,47 @@ test('postCountStats', function() {
|
||||
result = category5.get('postCountStats');
|
||||
equal(result.length, 0, "should show nothing");
|
||||
});
|
||||
|
||||
test('search', () => {
|
||||
const result = (term, opts) => {
|
||||
return Category.search(term, opts).map((category) => category.get('id'));
|
||||
}
|
||||
|
||||
const store = createStore(),
|
||||
category1 = store.createRecord('category', { id: 1, name: 'middle term' }),
|
||||
category2 = store.createRecord('category', { id: 2, name: 'middle term' });
|
||||
|
||||
sandbox.stub(Category, "listByActivity").returns([category1, category2]);
|
||||
|
||||
deepEqual(result('term', { limit: 0 }), [], "returns an empty array when limit is 0");
|
||||
deepEqual(result(''), [category1.get('id'), category2.get('id')], "orders by activity if no term is matched");
|
||||
deepEqual(result('term'), [category1.get('id'), category2.get('id')], "orders by activity");
|
||||
|
||||
category2.set('name', 'term start');
|
||||
deepEqual(result('term'), [category2.get('id'), category1.get('id')], "orders matching begin with and then contains");
|
||||
|
||||
sandbox.restore();
|
||||
|
||||
const category3 = 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 });
|
||||
|
||||
sandbox.stub(Category, "listByActivity").returns([category4, category1, category3, category2]);
|
||||
|
||||
deepEqual(result(''),
|
||||
[category1.get('id'), category3.get('id'), category2.get('id'), category4.get('id')],
|
||||
"prioritize non read_restricted categories when term is blank");
|
||||
|
||||
deepEqual(result('', { limit: 3 }),
|
||||
[category1.get('id'), category3.get('id'), category4.get('id')],
|
||||
"prioritize non read_restricted categories when term is blank with limit");
|
||||
|
||||
deepEqual(result('term'),
|
||||
[category3.get('id'), category2.get('id'), category1.get('id'), category4.get('id')],
|
||||
"prioritize non read_restricted");
|
||||
|
||||
deepEqual(result('term', { limit: 3 }),
|
||||
[category3.get('id'), category2.get('id'), category4.get('id')],
|
||||
"prioritize non read_restricted with limit");
|
||||
|
||||
sandbox.restore();
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user