X-Git-Url: http://git.ithinksw.org/extjs.git/blobdiff_plain/2e847cf21b8ab9d15fa167b315ca5b2fa92638fc..6a7e4474cba9d8be4b2ec445e10f1691f7277c50:/test/unit/Ext/XTemplate.js diff --git a/test/unit/Ext/XTemplate.js b/test/unit/Ext/XTemplate.js new file mode 100644 index 00000000..1c5d4d25 --- /dev/null +++ b/test/unit/Ext/XTemplate.js @@ -0,0 +1,77 @@ +/*! + * Ext JS Library 3.2.0 + * Copyright(c) 2006-2010 Ext JS, Inc. + * licensing@extjs.com + * http://www.extjs.com/license + */ + +Ext.test.session.addTest( 'Ext', new Y.Test.Case({ + + name: 'XTemplate', + + planned: 3, + + // 3 + test_apply: function() { + var data = { + hello: 'Hello', + world: 'World', + items1: [ + 'test1', + 'test2', + 'test3' + ], + items2: [ + { name: 'test1' }, + { name: 'test2' }, + { name: 'test3' } + ], + kids: [{ + name: 'Sara Grace', + gender: 'f', + age:3 + },{ + name: 'Zachary', + gender: 'm', + age:2 + },{ + name: 'John James', + gender: 'm', + age:.5 + }] + }; + var tpl1 = new Ext.XTemplate( '{hello} {world}. {.}{[ xindex === xcount ? "" : ":" ]}', { compiled: true }); + Y.Assert.areEqual( 'Hello World. test1:test2:test3', tpl1.apply( data ), 'Test apply with an object with an array' ); + + var tpl2 = new Ext.XTemplate( '{name}{[ xindex === xcount ? "" : ":" ]}', { compiled: true }); + Y.Assert.areEqual( 'test1:test2:test3', tpl2.apply( data ), 'Test apply with an object with an array of hashes' ); + + var tpl3 = new Ext.XTemplate( + '', + { + compiled: true, + disableFormats: true, + isGirl: function(gender){ + return gender == 'f'; + } + } + ); + Y.Assert.areEqual( '', + tpl3.apply( data ), 'Test apply with template member functions, basic comparison operators, and math' ); + } + + // apply is an alias for applyTemplate + +}));