File: Template.js

package info (click to toggle)
libjs-extjs 3.4.0%2Bdfsg1-1
  • links: PTS, VCS
  • area: main
  • in suites: buster, jessie, jessie-kfreebsd, stretch
  • size: 53,188 kB
  • ctags: 3,384
  • sloc: php: 819; xml: 537; python: 60; sql: 44; makefile: 35
file content (179 lines) | stat: -rw-r--r-- 6,991 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
/*!
 * Ext JS Library 3.4.0
 * Copyright(c) 2006-2011 Sencha Inc.
 * licensing@sencha.com
 * http://www.sencha.com/license
 */
Ext.test.session.addTest( 'Ext', {

    name: 'Template',

    planned: 22,

    setUp: function() {
        this.es = [];
    },

    tearDown: function() {
        Ext.each( this.es, function( el ) {
            if ( el instanceof Ext.Element ) {
                el.remove();
            } else {
                Ext.removeNode( el );
            }
        });
        this.es.length = 0;
    }, 

    // 3
    test_from: function() {
        var id = Ext.id();
        var el = Ext.getBody().createChild({
            tag: 'textarea',
            cls: 'x-hidden',
            id: id,
            html: '{0} {1}'
        });
        this.es.push( el );
        var tpl1 = Ext.Template.from( el, { complied: true } );
        var tpl2 = Ext.Template.from( el.dom, { complied: true } );
        var tpl3 = Ext.Template.from( id, { complied: true } );
        Y.Assert.areEqual( 'Hello World', tpl1.apply( [ 'Hello', 'World' ] ), 'Test template compiled from textarea value (using Ext.element)' );
        Y.Assert.areEqual( 'Hello World', tpl2.apply( [ 'Hello', 'World' ] ), 'Test template compiled from textarea value (using Html element)' );
        Y.Assert.areEqual( 'Hello World', tpl3.apply( [ 'Hello', 'World' ] ), 'Test template compiled from textarea value (using element id)' );
    },

    // 5
    test_append: function() {
        var container = Ext.getBody().createChild({
            tag: 'div',
            cls: 'x-hidden'
        });
        this.es.push( container );
        var div = container.createChild({
            tag: 'div',
            html: 'foobar'
        });
        var tpl = new Ext.Template( '<div>{0} {1}</div>', {
            compiled: true,
            disableFormats: true
        });

        var newel = tpl.append( container, [ 'Hello', 'World' ] );
        Y.Assert.areEqual( 'Hello World', newel.innerHTML, 'Test if the new element\'s innerHTML matches the template' );
        Y.Assert.areSame( newel, div.dom.nextSibling, 'Test if nextSibling is the created element' );
        Y.Assert.areSame( newel, container.dom.lastChild, 'Test if container\'s lastChild is the created element' );
        Y.Assert.areEqual( 'Hello World', div.dom.nextSibling.innerHTML, 'Test if nextSibling\'s innerHTML is from the template' );
        Y.Assert.areEqual( 'Hello World', container.dom.lastChild.innerHTML, 'Test if the container\'s firstChild innerHTML is from the template' );
    },

    // 3
    test_apply: function() {
        var tpl1 = new Ext.Template( '{0}{hello} {1}{world}. How are you {2}{name}?', {
            compiled: true,
            disableFormats: true
        });
        var tpl2 = new Ext.Template( '{hello} {world}. How are you {name:ellipsis(8)}?', {
            compiled: true
        });
        Y.Assert.areEqual( 'Hello World. How are you TestyMcTester?', tpl1.apply( [ 'Hello', 'World', 'TestyMcTester' ] ), 'Test apply with an array, no formats' );
        Y.Assert.areEqual( 'Hello World. How are you TestyMcTester?', tpl1.apply( { hello: 'Hello', world: 'World', name: 'TestyMcTester' } ), 'Test apply with an object, no formats' );
        Y.Assert.areEqual( 'Hello World. How are you Testy...?', tpl2.apply( { hello: 'Hello', world: 'World', name: 'TestyMcTester' } ), 'Test apply with an object, with formats' );
    },

    // apply is an alias for applyTemplate

    // 3
    test_insertAfter: function() {
        var container = Ext.getBody().createChild({
            tag: 'div',
            cls: 'x-hidden'
        });
        this.es.push( container );
        var div = container.createChild({
            tag: 'div',
            html: 'foobar'
        });
        var tpl = new Ext.Template( '<div>{0} {1}</div>', {
            compiled: true,
            disableFormats: true
        });

        var newel = tpl.insertAfter( div, [ 'Hello', 'World' ] );
        Y.Assert.areEqual( 'Hello World', newel.innerHTML, 'Test if the new element\'s innerHTML matches the template' );
        Y.Assert.areSame( newel, div.dom.nextSibling, 'Test if nextSibling is the created element' );
        Y.Assert.areEqual( 'Hello World', div.dom.nextSibling.innerHTML, 'Test if nextSibling\'s innerHTML is from the template' );
    },
    
    // 3
    test_insertBefore: function() {
        var container = Ext.getBody().createChild({
            tag: 'div',
            cls: 'x-hidden'
        });
        this.es.push( container );
        var div = container.createChild({
            tag: 'div',
            html: 'foobar'
        });
        var tpl = new Ext.Template( '<div>{0} {1}</div>', {
            compiled: true,
            disableFormats: true
        });

        var newel = tpl.insertBefore( div, [ 'Hello', 'World' ] );
        Y.Assert.areEqual( 'Hello World', newel.innerHTML, 'Test if the new element\'s innerHTML matches the template' );
        Y.Assert.areSame( newel, container.dom.firstChild, 'Test if the container\'s firstChild is the created element' );
        Y.Assert.areEqual( 'Hello World', container.dom.firstChild.innerHTML, 'Test if the container\s firstChild innerHTML is from the template' );
    },
    
    // 3
    test_insertFirst: function() {
        var container = Ext.getBody().createChild({
            tag: 'div',
            cls: 'x-hidden'
        });
        this.es.push( container );
        container.createChild({
            tag: 'div',
            html: 'foobar'
        });
        var tpl = new Ext.Template( '<div>{0} {1}</div>', {
            compiled: true,
            disableFormats: true
        });

        var newel = tpl.insertFirst( container, [ 'Hello', 'World' ] );
        Y.Assert.areEqual( 'Hello World', newel.innerHTML, 'Test if the new element\'s innerHTML matches the template' );
        Y.Assert.areSame( newel, container.dom.firstChild, 'Test if the container\'s firstChild is the created element' );
        Y.Assert.areEqual( 'Hello World', container.dom.firstChild.innerHTML, 'Test if the container\s firstChild innerHTML is from the template' );
    },

    // 1
    test_overwrite: function() {
        var container = Ext.getBody().createChild({
            tag: 'div',
            cls: 'x-hidden'
        });
        this.es.push( container );
        container.createChild({
            tag: 'div',
            html: 'foobar'
        });
        var tpl = new Ext.Template( '{0} {1}', {
            compiled: true,
            disableFormats: true
        });

        var newel = tpl.overwrite( container, [ 'Hello', 'World' ] );
        Y.Assert.areEqual( 'Hello World', container.dom.innerHTML, 'Test if the container innerHTML matches the template' );
    },

    // 1
    test_set: function() {
        var foo = new Ext.Template( '{1}{0}' );
        foo.set( '{0}{1}', true );
        Y.Assert.areEqual( 'foobar', foo.apply( [ 'foo', 'bar' ] ), 'Test recompiled template using set' );
    }

});