#5085 restructured unit tests for AutocompleteCtrl

This commit is contained in:
Joy Clark
2015-04-25 23:22:39 +02:00
parent 3458815f28
commit 913afc8f39

View File

@@ -67,40 +67,29 @@ describe('Groups Controller', function() {
}); });
describe("Autocomplete controller", function() { describe("Autocomplete controller", function() {
beforeEach(module('habitrpg')); var $scope, controller;
var $controller; beforeEach(inject(function($controller) {
$scope = {query: undefined, $watch: function(task,fn) {}}; // mock watch & t function
beforeEach(inject(function(_$controller_) { controller = $controller('AutocompleteCtrl', {$scope: $scope});
$controller = _$controller_;
})); }));
describe("AutocompleteCtrl", function() { it('filtering with undefined query (not loaded yet) defaults to true', 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 expect($scope.filterUser({user: "boo"})).to.be.ok
}) })
it('filtering with null query (no typing yet) defaults to true', function() { it('filtering with null query (no typing yet) defaults to true', function() {
$scope.query = null $scope.query = null
expect($scope.filterUser({user: "boo"})).to.be.ok expect($scope.filterUser({user: "boo"})).to.be.ok
}) })
it('filtering with prefix element will return true', function() { it('filtering with prefix element will return true', function() {
$scope.query = {text: "pre"} $scope.query = {text: "pre"}
expect($scope.filterUser({user: "prefix"})).to.be.ok expect($scope.filterUser({user: "prefix"})).to.be.ok
}) })
it('filtering with nonprefix element will return false', function() { it('filtering with nonprefix element will return false', function() {
$scope.query = {text: "noprefix"} $scope.query = {text: "noprefix"}
expect($scope.filterUser({user: "prefix"})).to.not.be.ok expect($scope.filterUser({user: "prefix"})).to.not.be.ok
}) })
});
}); });