mirror of
				https://github.com/zulip/zulip.git
				synced 2025-11-04 05:53:43 +00:00 
			
		
		
		
	Start using operator/operands internally in Filter class.
By having Filter.canonicalize_tuple() call filter_term(), we make it so that Filter objects get operator/operand fields in their terms when we initialize this. This mostly caused test breakage for tests that were doing assert.deepEqual; now we just check to make sure that the field we need are there. (imported from commit 63b2516dc72edeb11e76a1fa4442570b9c605baa)
This commit is contained in:
		@@ -103,7 +103,7 @@ Filter.canonicalize_tuple = function (tuple) {
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    // We may want to consider allowing mixed-case operators at some point
 | 
			
		||||
    return [operator, operand];
 | 
			
		||||
    return filter_term(operator, operand);
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -27,7 +27,7 @@ function assert_result_matches_legacy_terms(result, terms) {
 | 
			
		||||
    var operators = [['stream', 'foo'], ['topic', 'bar']];
 | 
			
		||||
    var filter = new Filter(operators);
 | 
			
		||||
 | 
			
		||||
    assert.deepEqual(filter.operators(), operators);
 | 
			
		||||
    assert_result_matches_legacy_terms(filter.operators(), operators);
 | 
			
		||||
    assert.deepEqual(filter.operands('stream'), ['foo']);
 | 
			
		||||
 | 
			
		||||
    assert(filter.has_operator('stream'));
 | 
			
		||||
@@ -49,11 +49,11 @@ function assert_result_matches_legacy_terms(result, terms) {
 | 
			
		||||
(function test_public_operators() {
 | 
			
		||||
    var operators = [['stream', 'foo'], ['topic', 'bar']];
 | 
			
		||||
    var filter = new Filter(operators);
 | 
			
		||||
    assert.deepEqual(filter.public_operators(), operators);
 | 
			
		||||
    assert_result_matches_legacy_terms(filter.public_operators(), operators);
 | 
			
		||||
 | 
			
		||||
    operators = [['in', 'all']];
 | 
			
		||||
    filter = new Filter(operators);
 | 
			
		||||
    assert.deepEqual(filter.public_operators(), []);
 | 
			
		||||
    assert_result_matches_legacy_terms(filter.public_operators(), []);
 | 
			
		||||
}());
 | 
			
		||||
 | 
			
		||||
(function test_canonicalizations() {
 | 
			
		||||
@@ -61,10 +61,18 @@ function assert_result_matches_legacy_terms(result, terms) {
 | 
			
		||||
    assert.equal(Filter.canonicalize_operator('Stream'), 'stream');
 | 
			
		||||
    assert.equal(Filter.canonicalize_operator('Subject'), 'topic');
 | 
			
		||||
 | 
			
		||||
    assert.deepEqual(Filter.canonicalize_tuple(['Stream', 'Denmark']), ['stream', 'Denmark']);
 | 
			
		||||
    var term;
 | 
			
		||||
    term = Filter.canonicalize_tuple(['Stream', 'Denmark']);
 | 
			
		||||
    assert.equal(term.operator, 'stream');
 | 
			
		||||
    assert.equal(term.operand, 'Denmark');
 | 
			
		||||
 | 
			
		||||
    assert.deepEqual(Filter.canonicalize_tuple(['sender', 'me']), ['sender', 'hamlet@zulip.com']);
 | 
			
		||||
    assert.deepEqual(Filter.canonicalize_tuple(['pm-with', 'me']), ['pm-with', 'hamlet@zulip.com']);
 | 
			
		||||
    term = Filter.canonicalize_tuple(['sender', 'me']);
 | 
			
		||||
    assert.equal(term.operator, 'sender');
 | 
			
		||||
    assert.equal(term.operand, 'hamlet@zulip.com');
 | 
			
		||||
 | 
			
		||||
    term = Filter.canonicalize_tuple(['pm-with', 'me']);
 | 
			
		||||
    assert.equal(term.operator, 'pm-with');
 | 
			
		||||
    assert.equal(term.operand, 'hamlet@zulip.com');
 | 
			
		||||
}());
 | 
			
		||||
 | 
			
		||||
function get_predicate(operators) {
 | 
			
		||||
 
 | 
			
		||||
@@ -56,9 +56,16 @@ function set_filter(operators) {
 | 
			
		||||
 | 
			
		||||
(function test_operators() {
 | 
			
		||||
    set_filter([['stream', 'Foo'], ['topic', 'Bar'], ['search', 'Yo']]);
 | 
			
		||||
    var canonical_operators = [['stream', 'Foo'], ['topic', 'Bar'], ['search', 'yo']];
 | 
			
		||||
    var result = narrow.operators();
 | 
			
		||||
    assert.equal(result.length, 3);
 | 
			
		||||
    assert.equal(result[0].operator, 'stream');
 | 
			
		||||
    assert.equal(result[0].operand, 'Foo');
 | 
			
		||||
 | 
			
		||||
    assert.deepEqual(narrow.operators(), canonical_operators);
 | 
			
		||||
    assert.equal(result[1].operator, 'topic');
 | 
			
		||||
    assert.equal(result[1].operand, 'Bar');
 | 
			
		||||
 | 
			
		||||
    assert.equal(result[2].operator, 'search');
 | 
			
		||||
    assert.equal(result[2].operand, 'yo');
 | 
			
		||||
}());
 | 
			
		||||
 | 
			
		||||
(function test_muting_enabled() {
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user