3 * Copyright(c) 2006-2010 Ext JS, Inc.
5 * http://www.extjs.com/license
7 Ext.test.session.addTest( 'Ext', {
17 tearDown: function() {
18 Ext.each( this.es, function( el ) {
19 if ( el instanceof Ext.Element ) {
29 test_from: function() {
31 var el = Ext.getBody().createChild({
38 var tpl1 = Ext.Template.from( el, { complied: true } );
39 var tpl2 = Ext.Template.from( el.dom, { complied: true } );
40 var tpl3 = Ext.Template.from( id, { complied: true } );
41 Y.Assert.areEqual( 'Hello World', tpl1.apply( [ 'Hello', 'World' ] ), 'Test template compiled from textarea value (using Ext.element)' );
42 Y.Assert.areEqual( 'Hello World', tpl2.apply( [ 'Hello', 'World' ] ), 'Test template compiled from textarea value (using Html element)' );
43 Y.Assert.areEqual( 'Hello World', tpl3.apply( [ 'Hello', 'World' ] ), 'Test template compiled from textarea value (using element id)' );
47 test_append: function() {
48 var container = Ext.getBody().createChild({
52 this.es.push( container );
53 var div = container.createChild({
57 var tpl = new Ext.Template( '<div>{0} {1}</div>', {
62 var newel = tpl.append( container, [ 'Hello', 'World' ] );
63 Y.Assert.areEqual( 'Hello World', newel.innerHTML, 'Test if the new element\'s innerHTML matches the template' );
64 Y.Assert.areSame( newel, div.dom.nextSibling, 'Test if nextSibling is the created element' );
65 Y.Assert.areSame( newel, container.dom.lastChild, 'Test if container\'s lastChild is the created element' );
66 Y.Assert.areEqual( 'Hello World', div.dom.nextSibling.innerHTML, 'Test if nextSibling\'s innerHTML is from the template' );
67 Y.Assert.areEqual( 'Hello World', container.dom.lastChild.innerHTML, 'Test if the container\'s firstChild innerHTML is from the template' );
71 test_apply: function() {
72 var tpl1 = new Ext.Template( '{0}{hello} {1}{world}. How are you {2}{name}?', {
76 var tpl2 = new Ext.Template( '{hello} {world}. How are you {name:ellipsis(8)}?', {
79 Y.Assert.areEqual( 'Hello World. How are you TestyMcTester?', tpl1.apply( [ 'Hello', 'World', 'TestyMcTester' ] ), 'Test apply with an array, no formats' );
80 Y.Assert.areEqual( 'Hello World. How are you TestyMcTester?', tpl1.apply( { hello: 'Hello', world: 'World', name: 'TestyMcTester' } ), 'Test apply with an object, no formats' );
81 Y.Assert.areEqual( 'Hello World. How are you Testy...?', tpl2.apply( { hello: 'Hello', world: 'World', name: 'TestyMcTester' } ), 'Test apply with an object, with formats' );
84 // apply is an alias for applyTemplate
87 test_insertAfter: function() {
88 var container = Ext.getBody().createChild({
92 this.es.push( container );
93 var div = container.createChild({
97 var tpl = new Ext.Template( '<div>{0} {1}</div>', {
102 var newel = tpl.insertAfter( div, [ 'Hello', 'World' ] );
103 Y.Assert.areEqual( 'Hello World', newel.innerHTML, 'Test if the new element\'s innerHTML matches the template' );
104 Y.Assert.areSame( newel, div.dom.nextSibling, 'Test if nextSibling is the created element' );
105 Y.Assert.areEqual( 'Hello World', div.dom.nextSibling.innerHTML, 'Test if nextSibling\'s innerHTML is from the template' );
109 test_insertBefore: function() {
110 var container = Ext.getBody().createChild({
114 this.es.push( container );
115 var div = container.createChild({
119 var tpl = new Ext.Template( '<div>{0} {1}</div>', {
124 var newel = tpl.insertBefore( div, [ 'Hello', 'World' ] );
125 Y.Assert.areEqual( 'Hello World', newel.innerHTML, 'Test if the new element\'s innerHTML matches the template' );
126 Y.Assert.areSame( newel, container.dom.firstChild, 'Test if the container\'s firstChild is the created element' );
127 Y.Assert.areEqual( 'Hello World', container.dom.firstChild.innerHTML, 'Test if the container\s firstChild innerHTML is from the template' );
131 test_insertFirst: function() {
132 var container = Ext.getBody().createChild({
136 this.es.push( container );
137 container.createChild({
141 var tpl = new Ext.Template( '<div>{0} {1}</div>', {
146 var newel = tpl.insertFirst( container, [ 'Hello', 'World' ] );
147 Y.Assert.areEqual( 'Hello World', newel.innerHTML, 'Test if the new element\'s innerHTML matches the template' );
148 Y.Assert.areSame( newel, container.dom.firstChild, 'Test if the container\'s firstChild is the created element' );
149 Y.Assert.areEqual( 'Hello World', container.dom.firstChild.innerHTML, 'Test if the container\s firstChild innerHTML is from the template' );
153 test_overwrite: function() {
154 var container = Ext.getBody().createChild({
158 this.es.push( container );
159 container.createChild({
163 var tpl = new Ext.Template( '{0} {1}', {
168 var newel = tpl.overwrite( container, [ 'Hello', 'World' ] );
169 Y.Assert.areEqual( 'Hello World', container.dom.innerHTML, 'Test if the container innerHTML matches the template' );
173 test_set: function() {
174 var foo = new Ext.Template( '{1}{0}' );
175 foo.set( '{0}{1}', true );
176 Y.Assert.areEqual( 'foobar', foo.apply( [ 'foo', 'bar' ] ), 'Test recompiled template using set' );