mirror of
				https://github.com/zulip/zulip.git
				synced 2025-11-04 05:53:43 +00:00 
			
		
		
		
	Add tests for the Filter class.
(imported from commit ef0917bd7911c5cc6f6d20d356c156d483ba723f)
This commit is contained in:
		@@ -8,6 +8,7 @@ export NODE_PATH=$STATIC_DIR
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
NODEJS=$(which nodejs || which node)
 | 
					NODEJS=$(which nodejs || which node)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					$NODEJS filter.js
 | 
				
			||||||
$NODEJS util.js
 | 
					$NODEJS util.js
 | 
				
			||||||
$NODEJS message_list.js
 | 
					$NODEJS message_list.js
 | 
				
			||||||
$NODEJS message_tour.js
 | 
					$NODEJS message_tour.js
 | 
				
			||||||
 
 | 
				
			|||||||
							
								
								
									
										49
									
								
								zerver/tests/frontend/node/filter.js
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										49
									
								
								zerver/tests/frontend/node/filter.js
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,49 @@
 | 
				
			|||||||
 | 
					var assert = require('assert');
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					(function set_up_dependencies () {
 | 
				
			||||||
 | 
					    global._ = require('third/underscore/underscore.js');
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    // An upcoming change is to put Filter in its own module, but
 | 
				
			||||||
 | 
					    // for now it still lives in narrow.js.  (I'm waiting for a big
 | 
				
			||||||
 | 
					    // commit from Zev to hit master first.  Once that happens,
 | 
				
			||||||
 | 
					    // I will make js/filter.js, update the references here, and
 | 
				
			||||||
 | 
					    // hopefully remember to delete this comment.)
 | 
				
			||||||
 | 
					    global.narrow = require('js/narrow.js');
 | 
				
			||||||
 | 
					    global.$ = function () {}; // for subs.js to load
 | 
				
			||||||
 | 
					    global.subs = require('js/subs.js');
 | 
				
			||||||
 | 
					    global.page_params = {
 | 
				
			||||||
 | 
					        domain: 'zulip.com'
 | 
				
			||||||
 | 
					    };
 | 
				
			||||||
 | 
					}());
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					var Filter = global.narrow.Filter;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					(function test_basics() {
 | 
				
			||||||
 | 
					    var operators = [['stream', 'foo'], ['topic', 'bar']];
 | 
				
			||||||
 | 
					    var filter = new Filter(operators);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    assert.deepEqual(filter.operators(), operators);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    var predicate = filter.predicate();
 | 
				
			||||||
 | 
					    assert(predicate({type: 'stream', stream: 'foo', subject: 'bar'}));
 | 
				
			||||||
 | 
					    assert(!predicate({type: 'stream', stream: 'foo', subject: 'whatever'}));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    assert.deepEqual(filter.operands('stream'), ['foo']);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    assert(filter.has_operator('stream'));
 | 
				
			||||||
 | 
					    assert(!filter.has_operator('search'));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    assert(filter.has_operand('stream', 'foo'));
 | 
				
			||||||
 | 
					    assert(!filter.has_operand('stream', 'nada'));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    assert(!filter.is_search());
 | 
				
			||||||
 | 
					    assert(filter.can_apply_locally());
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    operators = [['stream', 'foo'], ['topic', 'bar'], ['search', 'pizza']];
 | 
				
			||||||
 | 
					    filter = new Filter(operators);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    assert(filter.is_search());
 | 
				
			||||||
 | 
					    assert(! filter.can_apply_locally());
 | 
				
			||||||
 | 
					}());
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		Reference in New Issue
	
	Block a user