From f083994f5a4900fd988f37e0456aa57c0353701d Mon Sep 17 00:00:00 2001 From: Sam Date: Mon, 24 Oct 2016 12:43:38 +1100 Subject: [PATCH] FIX: exact group match always should be added --- app/assets/javascripts/discourse/lib/user-search.js.es6 | 2 +- test/javascripts/fixtures/user-search_fixtures.js.es6 | 3 +++ test/javascripts/helpers/create-pretender.js.es6 | 4 ++++ test/javascripts/lib/user-search-test.js.es6 | 9 +++++++++ 4 files changed, 17 insertions(+), 1 deletion(-) create mode 100644 test/javascripts/fixtures/user-search_fixtures.js.es6 create mode 100644 test/javascripts/lib/user-search-test.js.es6 diff --git a/app/assets/javascripts/discourse/lib/user-search.js.es6 b/app/assets/javascripts/discourse/lib/user-search.js.es6 index eb5bc209b35..def5e2e883a 100644 --- a/app/assets/javascripts/discourse/lib/user-search.js.es6 +++ b/app/assets/javascripts/discourse/lib/user-search.js.es6 @@ -59,7 +59,7 @@ function organizeResults(r, options) { if (r.groups) { r.groups.every(function(g) { - if (results.length > limit) return false; + if (results.length > limit && options.term !== g.name) return false; if (exclude.indexOf(g.name) === -1) { groups.push(g); results.push(g); diff --git a/test/javascripts/fixtures/user-search_fixtures.js.es6 b/test/javascripts/fixtures/user-search_fixtures.js.es6 new file mode 100644 index 00000000000..2923548d85d --- /dev/null +++ b/test/javascripts/fixtures/user-search_fixtures.js.es6 @@ -0,0 +1,3 @@ +export default { +"/search/user/search?term=team&include_mentionable_groups=true": {"users":[{"username":"TeaMoe","name":"TeaMoe","avatar_template":"https://avatars.discourse.org/v3/letter/t/41988e/{size}.png"},{"username":"TeamOneJ","name":"J Cobb","avatar_template":"https://avatars.discourse.org/v3/letter/t/3d9bf3/{size}.png"},{"username":"kudos","name":"Team Blogeto.com","avatar_template":"/user_avatar/meta.discourse.org/kudos/{size}/62185_1.png"},{"username":"RosieLinda","name":"Linda Teaman","avatar_template":"https://avatars.discourse.org/v3/letter/r/bc8723/{size}.png"},{"username":"legalatom","name":"Team LegalAtom","avatar_template":"https://avatars.discourse.org/v3/letter/l/a9a28c/{size}.png"},{"username":"dzsat_team","name":"Dz Sat Dz Sat","avatar_template":"https://avatars.discourse.org/v3/letter/d/eb9ed0/{size}.png"}],"groups":[{"name":"team","usernames":[]}]} +}; diff --git a/test/javascripts/helpers/create-pretender.js.es6 b/test/javascripts/helpers/create-pretender.js.es6 index 8a37d2bf5e6..6414216ee81 100644 --- a/test/javascripts/helpers/create-pretender.js.es6 +++ b/test/javascripts/helpers/create-pretender.js.es6 @@ -90,6 +90,10 @@ export default function() { return response({}); }); + this.get('/users/search/users', () => { + return response(fixturesByUrl['/search/user/search?term=team&include_mentionable_groups=true']); + }); + this.put('/users/eviltrout', () => response({ user: {} })); diff --git a/test/javascripts/lib/user-search-test.js.es6 b/test/javascripts/lib/user-search-test.js.es6 new file mode 100644 index 00000000000..c9931127970 --- /dev/null +++ b/test/javascripts/lib/user-search-test.js.es6 @@ -0,0 +1,9 @@ +import userSearch from 'discourse/lib/user-search'; + +module("lib:user-search"); + +test("it places groups unconditionally for exact match", function() { + return userSearch({term: 'team'}).then((results)=>{ + equal(results[results.length-1]["name"], "team"); + }); +});