mirror of
https://github.com/HabitRPG/habitica.git
synced 2025-12-18 15:17:25 +01:00
Fixing #5706 filtering system messages results in errors.
This commit is contained in:
@@ -101,7 +101,7 @@ describe("Autocomplete controller", function() {
|
|||||||
scope.clearUserlist();
|
scope.clearUserlist();
|
||||||
expect(scope.response).to.be.empty; // to.be.empty() doesn't work for some reason. This is the same thing
|
expect(scope.response).to.be.empty; // to.be.empty() doesn't work for some reason. This is the same thing
|
||||||
expect(scope.usernames).to.be.empty;
|
expect(scope.usernames).to.be.empty;
|
||||||
})
|
});
|
||||||
|
|
||||||
it('the function is called upon initialization of the controller', function() {
|
it('the function is called upon initialization of the controller', function() {
|
||||||
scope.response.push("blah");
|
scope.response.push("blah");
|
||||||
@@ -110,33 +110,38 @@ describe("Autocomplete controller", function() {
|
|||||||
|
|
||||||
expect(scope.response).to.be.empty; // to.be.empty() doesn't work for some reason. This is the same thing
|
expect(scope.response).to.be.empty; // to.be.empty() doesn't work for some reason. This is the same thing
|
||||||
expect(scope.usernames).to.be.empty;
|
expect(scope.usernames).to.be.empty;
|
||||||
})
|
});
|
||||||
})
|
})
|
||||||
|
|
||||||
describe("filterUser", function() {
|
describe("filterUser", function() {
|
||||||
it('filters with undefined query (not loaded yet) and returns false (so it will not be rendered)', function() {
|
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);
|
expect(scope.filterUser({user: "boo"})).to.be.eq(false);
|
||||||
})
|
});
|
||||||
|
|
||||||
it('filters with null query (no typing yet) and returns false (so it will not be rendered)', function() {
|
it('filters with null query (no typing yet) and returns false (so it will not be rendered)', function() {
|
||||||
scope.query = null
|
scope.query = null
|
||||||
expect(scope.filterUser({user: "boo"})).to.be.eq(false);
|
expect(scope.filterUser({user: "boo"})).to.be.eq(false);
|
||||||
})
|
});
|
||||||
|
|
||||||
it('filters with empty prefix and returns true', function() {
|
it('filters with empty prefix and returns true', function() {
|
||||||
scope.query = {text: ""}
|
scope.query = {text: ""}
|
||||||
expect(scope.filterUser({user: "prefix"})).to.be.eq(true);
|
expect(scope.filterUser({user: "prefix"})).to.be.eq(true);
|
||||||
})
|
});
|
||||||
|
|
||||||
it('filters with prefix element and returns true', function() {
|
it('filters with prefix element and returns true', function() {
|
||||||
scope.query = {text: "pre"}
|
scope.query = {text: "pre"}
|
||||||
expect(scope.filterUser({user: "prefix"})).to.be.eq(true);
|
expect(scope.filterUser({user: "prefix"})).to.be.eq(true);
|
||||||
})
|
});
|
||||||
|
|
||||||
it('filters with nonprefix element and returns false', function() {
|
it('filters with nonprefix element and returns false', function() {
|
||||||
scope.query = {text: "noprefix"}
|
scope.query = {text: "noprefix"}
|
||||||
expect(scope.filterUser({user: "prefix"})).to.be.eq(false);
|
expect(scope.filterUser({user: "prefix"})).to.be.eq(false);
|
||||||
})
|
});
|
||||||
|
|
||||||
|
it('filters out system messages (messages without username)', function() {
|
||||||
|
scope.query = {text: "myquery"}
|
||||||
|
expect(scope.filterUser({uuid: "system"})).to.be.eq(false);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("addNewUser", function() {
|
describe("addNewUser", function() {
|
||||||
@@ -159,6 +164,6 @@ describe("Autocomplete controller", function() {
|
|||||||
scope.$digest(); // trigger watch
|
scope.$digest(); // trigger watch
|
||||||
scope.group.chat.push({msg: "new chat", user: "boo"});
|
scope.group.chat.push({msg: "new chat", user: "boo"});
|
||||||
expect(chatChanged.callCount).to.be.eq(1);
|
expect(chatChanged.callCount).to.be.eq(1);
|
||||||
})
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -224,6 +224,9 @@ habitrpg.controller("GroupsCtrl", ['$scope', '$rootScope', 'Shared', 'Groups', '
|
|||||||
if ($scope.query === undefined || $scope.query === null) {
|
if ($scope.query === undefined || $scope.query === null) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
if (msg.username == undefined) {
|
||||||
|
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 item.user
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user