From 3458815f28291711a4ad268dab6856b9b0161bc1 Mon Sep 17 00:00:00 2001 From: Joy Clark Date: Sat, 25 Apr 2015 23:08:28 +0200 Subject: [PATCH] #5085 added some unit tests. --- test/spec/groupCtrlSpec.js | 39 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/test/spec/groupCtrlSpec.js b/test/spec/groupCtrlSpec.js index 863c9308de..24f6b891f8 100644 --- a/test/spec/groupCtrlSpec.js +++ b/test/spec/groupCtrlSpec.js @@ -65,3 +65,42 @@ describe('Groups Controller', function() { expect(myGuilds).to.be.called }); }); + +describe("Autocomplete controller", function() { + beforeEach(module('habitrpg')); + + var $controller; + + beforeEach(inject(function(_$controller_) { + $controller = _$controller_; + })); + + describe("AutocompleteCtrl", function() { + var $scope, controller; + + beforeEach(function() { + $scope = {query: undefined, $watch: function(task,fn) {}}; // mock watch function + controller = $controller('AutocompleteCtrl', {$scope: $scope}); + }) + + it('filtering with undefined query (not loaded yet) defaults to true', function() { + expect($scope.filterUser({user: "boo"})).to.be.ok + }) + + it('filtering with null query (no typing yet) defaults to true', function() { + $scope.query = null + expect($scope.filterUser({user: "boo"})).to.be.ok + }) + + it('filtering with prefix element will return true', function() { + $scope.query = {text: "pre"} + expect($scope.filterUser({user: "prefix"})).to.be.ok + }) + + it('filtering with nonprefix element will return false', function() { + $scope.query = {text: "noprefix"} + expect($scope.filterUser({user: "prefix"})).to.not.be.ok + }) + + }); +}); \ No newline at end of file