diff --git a/static/js/search_suggestion.js b/static/js/search_suggestion.js index 426bb73a2a..a791b536aa 100644 --- a/static/js/search_suggestion.js +++ b/static/js/search_suggestion.js @@ -195,6 +195,7 @@ function get_topic_suggestions(query_operators) { var last_term = query_operators.slice(-1)[0]; var operator = Filter.canonicalize_operator(last_term.operator); var operand = last_term.operand; + var negated = (operator === 'topic') && (last_term.negated); var stream; var guess; var filter; @@ -277,7 +278,7 @@ function get_topic_suggestions(query_operators) { topics.sort(); return _.map(topics, function (topic) { - var topic_term = {operator: 'topic', operand: topic}; + var topic_term = {operator: 'topic', operand: topic, negated: negated}; var operators = query_operators.concat([topic_term]); var search_string = Filter.unparse(operators); var description = Filter.describe(operators); diff --git a/zerver/tests/frontend/node/search_suggestion.js b/zerver/tests/frontend/node/search_suggestion.js index 19ec5e362f..58f7ffe2fe 100644 --- a/zerver/tests/frontend/node/search_suggestion.js +++ b/zerver/tests/frontend/node/search_suggestion.js @@ -16,7 +16,9 @@ add_dependencies({ var search = require('js/search_suggestion.js'); -set_global('feature_flags', {}); +set_global('feature_flags', { + negated_search: true +}); set_global('page_params', { email: 'bob@zulip.com' }); @@ -262,6 +264,22 @@ set_global('narrow', {}); 'stream:devel' ]; assert.deepEqual(suggestions.strings, expected); + + suggestions = search.get_suggestions('stream:devel -topic:'); + expected = [ + 'stream:devel -topic:', + 'stream:devel -topic:REXX', + 'stream:devel' + ]; + assert.deepEqual(suggestions.strings, expected); + + suggestions = search.get_suggestions('-topic:te'); + expected = [ + '-topic:te', + 'stream:office -topic:team', + 'stream:office -topic:test' + ]; + assert.deepEqual(suggestions.strings, expected); }()); (function test_whitespace_glitch() {