From 4450a5d7c399ed840340ed43033130ccdbc51e78 Mon Sep 17 00:00:00 2001 From: Joy Clark Date: Sun, 3 May 2015 18:14:28 +0200 Subject: [PATCH 1/2] Fixes #5094 Now show list based on whether or not a search query is defined. The autocomplete function from the directive is encapsulated so that it can be called and then the query can be set to null. --- test/spec/groupCtrlSpec.js | 14 ++++++++++++++ website/public/js/controllers/groupsCtrl.js | 5 +++++ website/views/options/social/chat-box.jade | 6 +++--- 3 files changed, 22 insertions(+), 3 deletions(-) diff --git a/test/spec/groupCtrlSpec.js b/test/spec/groupCtrlSpec.js index bd633b914c..a64385545a 100644 --- a/test/spec/groupCtrlSpec.js +++ b/test/spec/groupCtrlSpec.js @@ -149,6 +149,20 @@ describe("Autocomplete controller", function() { }); }); + describe("performCompletion", function() { + it('auto complete triggers', function() { + scope.autoComplete = function(v) {}; // this function normally will be filled in by the auto-complete directive + var autoCompleteTriggered = sinon.spy(scope, 'autoComplete'); + scope.query = {text: "b"}; + + scope.performCompletion({user: "boo"}); + + expect(scope.query).to.be.eq(null); + expect(autoCompleteTriggered.callCount).to.be.eq(1); + }); + + }); + describe("addNewUser", function() { it('a new message from a new user will modify the usernames', function() { expect(scope.response).to.be.empty; diff --git a/website/public/js/controllers/groupsCtrl.js b/website/public/js/controllers/groupsCtrl.js index 26a4196a97..205b5f35b7 100644 --- a/website/public/js/controllers/groupsCtrl.js +++ b/website/public/js/controllers/groupsCtrl.js @@ -232,6 +232,11 @@ habitrpg.controller("GroupsCtrl", ['$scope', '$rootScope', 'Shared', 'Groups', ' return user.indexOf(text) == 0; } + $scope.performCompletion = function(msg) { + $scope.autoComplete(msg); + $scope.query = null; + } + $scope.addNewUser = function(user) { if($.inArray(user.user,$scope.usernames) == -1) { user.username = user.user; diff --git a/website/views/options/social/chat-box.jade b/website/views/options/social/chat-box.jade index 047f6e4eea..2266fd5e31 100644 --- a/website/views/options/social/chat-box.jade +++ b/website/views/options/social/chat-box.jade @@ -13,9 +13,9 @@ div.chat-form.guidelines-not-accepted(ng-if='!user.flags.communityGuidelinesAcce form.chat-form(ng-if='user.flags.communityGuidelinesAccepted' ng-submit='postChat(group,message.content)') div(ng-controller='AutocompleteCtrl') textarea.form-control(rows=4, ui-keydown='{"meta-enter":"postChat(group,message.content)"}', ui-keypress='{13:"postChat(group,message.content)"}', ng-model='message.content', updateinterval='250', flag='@', at-user, auto-complete placeholder="{{group._id == 'habitrpg' ? env.t('tavernCommunityGuidelinesPlaceholder') : ''}}") - span.user-list(ng-show='!isAtListHidden') - ul.list-at-user - li(ng-repeat='msg in response | filter:filterUser | limitTo: 5', ng-click='autoComplete(msg)') + span.user-list + ul.list-at-user(ng-show="query") + li(ng-repeat='msg in response | filter:filterUser | limitTo: 5', ng-click='performCompletion(msg)') span.username.label.label-default(ng-class=':: userLevelStyle(msg)') {{::msg.user}} .chat-controls .chat-formatting From efa193b262d2df8faade4d2389d8e8046a2065b5 Mon Sep 17 00:00:00 2001 From: Blade Barringer Date: Fri, 8 May 2015 08:44:50 -0500 Subject: [PATCH 2/2] Refactor test --- test/spec/groupCtrlSpec.js | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/test/spec/groupCtrlSpec.js b/test/spec/groupCtrlSpec.js index a64385545a..dd402909ed 100644 --- a/test/spec/groupCtrlSpec.js +++ b/test/spec/groupCtrlSpec.js @@ -150,17 +150,17 @@ describe("Autocomplete controller", function() { }); describe("performCompletion", function() { - it('auto complete triggers', function() { - scope.autoComplete = function(v) {}; // this function normally will be filled in by the auto-complete directive - var autoCompleteTriggered = sinon.spy(scope, 'autoComplete'); - scope.query = {text: "b"}; + it('triggers autoComplete', function() { + scope.autoComplete = sinon.spy(); - scope.performCompletion({user: "boo"}); + var msg = {user: "boo"}; // scope.autoComplete only cares about user + scope.query = {text: "b"}; + scope.performCompletion(msg); expect(scope.query).to.be.eq(null); - expect(autoCompleteTriggered.callCount).to.be.eq(1); + expect(scope.autoComplete.callCount).to.be.eq(1); + expect(scope.autoComplete).to.have.been.calledWith(msg); }); - }); describe("addNewUser", function() {