From f21442841145676d9394fefa6d6d17f2f8e8f835 Mon Sep 17 00:00:00 2001 From: Joy Clark Date: Sun, 26 Apr 2015 17:50:53 +0200 Subject: [PATCH 1/2] Improved filter function as described in #5085 and added unit tests. --- test/spec/groupCtrlSpec.js | 17 +++++++++++------ website/public/js/controllers/groupsCtrl.js | 6 +++--- website/views/options/social/chat-box.jade | 4 ++-- 3 files changed, 16 insertions(+), 11 deletions(-) diff --git a/test/spec/groupCtrlSpec.js b/test/spec/groupCtrlSpec.js index 3ae5cb8562..249750d677 100644 --- a/test/spec/groupCtrlSpec.js +++ b/test/spec/groupCtrlSpec.js @@ -90,23 +90,28 @@ describe("Autocomplete controller", function() { }); describe("filterUser", function() { - it('filters with undefined query (not loaded yet) and defaults to true', function() { - expect(scope.filterUser({user: "boo"})).to.be.eq(true); + it('filters with undefined query (not loaded yet) and returns false (so it will not be rendered)', function() { + expect(scope.filterUser({user: "boo"})).to.be.eq(false); }) - it('filters with null query (no typing yet) and defaults to true', function() { + it('filters with null query (no typing yet) and returns false (so it will not be rendered)', function() { scope.query = null - expect(scope.filterUser({user: "boo"})).to.be.ok + expect(scope.filterUser({user: "boo"})).to.be.eq(false); + }) + + it('filters with empty prefix and returns true', function() { + scope.query = {text: ""} + expect(scope.filterUser({user: "prefix"})).to.be.eq(true); }) it('filters with prefix element and returns true', function() { scope.query = {text: "pre"} - expect(scope.filterUser({user: "prefix"})).to.be.ok + expect(scope.filterUser({user: "prefix"})).to.be.eq(true); }) it('filters with nonprefix element and returns false', function() { scope.query = {text: "noprefix"} - expect(scope.filterUser({user: "prefix"})).to.not.be.ok + expect(scope.filterUser({user: "prefix"})).to.be.eq(false); }) }); }); diff --git a/website/public/js/controllers/groupsCtrl.js b/website/public/js/controllers/groupsCtrl.js index a16665b602..7dfdf5a84f 100644 --- a/website/public/js/controllers/groupsCtrl.js +++ b/website/public/js/controllers/groupsCtrl.js @@ -220,11 +220,11 @@ habitrpg.controller("GroupsCtrl", ['$scope', '$rootScope', 'Shared', 'Groups', ' $scope.usernames = []; } - $scope.filterUser = function(userItem) { + $scope.filterUser = function(msg) { if ($scope.query === undefined || $scope.query === null) { - return true; + return false; } - return userItem.user.indexOf($scope.query.text) == 0; // query should be prefix of item.user + return msg.user.indexOf($scope.query.text) == 0; // query should be prefix of item.user } $scope.addNewUser = function(user) { diff --git a/website/views/options/social/chat-box.jade b/website/views/options/social/chat-box.jade index edc78f8eed..047f6e4eea 100644 --- a/website/views/options/social/chat-box.jade +++ b/website/views/options/social/chat-box.jade @@ -15,8 +15,8 @@ form.chat-form(ng-if='user.flags.communityGuidelinesAccepted' ng-submit='postCha 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='user in response | filter:filterUser | limitTo: 5', ng-click='autoComplete(user)') - span.username.label.label-default(ng-class=':: userLevelStyle(user)') {{::user.user}} + li(ng-repeat='msg in response | filter:filterUser | limitTo: 5', ng-click='autoComplete(msg)') + span.username.label.label-default(ng-class=':: userLevelStyle(msg)') {{::msg.user}} .chat-controls .chat-formatting include ../../shared/formatting-help From a94aad7a22df4ed51342878483fe1feebfe31ebb Mon Sep 17 00:00:00 2001 From: Blade Barringer Date: Sun, 26 Apr 2015 20:43:32 -0500 Subject: [PATCH 2/2] Fix comment --- website/public/js/controllers/groupsCtrl.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/website/public/js/controllers/groupsCtrl.js b/website/public/js/controllers/groupsCtrl.js index 7dfdf5a84f..0da3c5a053 100644 --- a/website/public/js/controllers/groupsCtrl.js +++ b/website/public/js/controllers/groupsCtrl.js @@ -224,7 +224,7 @@ habitrpg.controller("GroupsCtrl", ['$scope', '$rootScope', 'Shared', 'Groups', ' if ($scope.query === undefined || $scope.query === null) { return false; } - return msg.user.indexOf($scope.query.text) == 0; // query should be prefix of item.user + return msg.user.indexOf($scope.query.text) == 0; // query should be prefix of msg.user } $scope.addNewUser = function(user) {