From 0f104317dff5628765e26cc68df7dd1175b2aa5e Mon Sep 17 00:00:00 2001 From: Misko Hevery Date: Wed, 13 Oct 2010 23:09:26 -0700 Subject: Added support for date filter Date filter now supports: yyyy: four digit year yy: two digit year MM: two digit month dd: two digit day of month HH: two digit hour in 0-23 KK: two digit hour in 0-12 mm: two digit minute ss: two digit second a: am/pm Z: four digit timezone offset example {{ timestamp | date:'yyyy-MM-dd HH:mm:ss' }} becomes 2010-10-13 14:45:23 --- test/FiltersSpec.js | 106 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 106 insertions(+) create mode 100644 test/FiltersSpec.js (limited to 'test/FiltersSpec.js') diff --git a/test/FiltersSpec.js b/test/FiltersSpec.js new file mode 100644 index 00000000..1767bede --- /dev/null +++ b/test/FiltersSpec.js @@ -0,0 +1,106 @@ +describe('filter', function(){ + + var filter = angular.filter; + + describe('Currency', function(){ + it('should do basic filter', function(){ + var html = jqLite(''); + var context = {$element:html}; + var currency = bind(context, filter.currency); + + assertEquals(currency(0), '$0.00'); + assertEquals(html.hasClass('ng:format-negative'), false); + assertEquals(currency(-999), '$-999.00'); + assertEquals(html.hasClass('ng:format-negative'), true); + assertEquals(currency(1234.5678), '$1,234.57'); + assertEquals(html.hasClass('ng:format-negative'), false); + }); + }); + + describe('FilterThisIsContext', function(){ + it('should do basic filter', function(){ + expectAsserts(1); + var scope = createScope(); + scope.name = 'misko'; + filter.testFn = function () { + assertEquals('scope not equal', 'misko', this.name); + }; + scope.$eval("0|testFn"); + delete angular.filter['testFn']; + }); + }); + + describe('NumberFormat', function(){ + it('should do basic filter', function(){ + var context = {jqElement:jqLite('')}; + var number = bind(context, filter.number); + + assertEquals('0', number(0, 0)); + assertEquals('0.00', number(0)); + assertEquals('-999.00', number(-999)); + assertEquals('1,234.57', number(1234.5678)); + assertEquals('', number(Number.NaN)); + assertEquals('1,234.57', number("1234.5678")); + assertEquals("", number(1/0)); + }); + }); + + describe('Json', function () { + it('should do basic filter', function(){ + assertEquals(toJson({a:"b"}, true), filter.json.call({$element:jqLite('
')}, {a:"b"})); + }); + }); + + describe('Lowercase', function() { + it('should do basic filter', function(){ + assertEquals('abc', filter.lowercase('AbC')); + assertEquals(null, filter.lowercase(null)); + }); + }); + + describe('Uppercase', function() { + it('should do basic filter', function(){ + assertEquals('ABC', filter.uppercase('AbC')); + assertEquals(null, filter.uppercase(null)); + }); + }); + + describe('Html', function() { + it('should do basic filter', function(){ + var html = filter.html("acd"); + expect(html instanceof HTML).toBeTruthy(); + expect(html.html).toEqual("acd"); + }); + }); + + describe('Linky', function() { + it('should do basic filter', function(){ + var linky = filter.linky; + assertEquals( + 'http://ab/ ' + + '(http://a/) ' + + '<http://a/> ' + + 'http://1.2/v:~-123. c', + linky("http://ab/ (http://a/)