]> git.proxmox.com Git - extjs.git/blame - extjs/packages/core/test/specs/util/ObjectTemplate.js
add extjs 6.0.1 sources
[extjs.git] / extjs / packages / core / test / specs / util / ObjectTemplate.js
CommitLineData
6527f429
DM
1describe('Ext.util.ObjectTemplate', function () {\r
2 var tpl, output,\r
3 context = Ext.Object.chain({\r
4 direct: false,\r
5 object: {\r
6 property: 456\r
7 }\r
8 });\r
9\r
10 context.text = 'Don';\r
11\r
12 var fn1 = function() {},\r
13 fn2 = function() {},\r
14 fn3 = function() {},\r
15 fn4 = function() {},\r
16 fn5 = function() {};\r
17\r
18 beforeEach(function () {\r
19 tpl = new Ext.util.ObjectTemplate({\r
20 foo: 42,\r
21 rootFn: fn1,\r
22 bar: 'Hello {text}',\r
23 baz: '{direct}',\r
24 array: [\r
25 427,\r
26 'Hey {text} {object.property}',\r
27 '{object.property}',\r
28 '{direct}',\r
29 fn2,\r
30 null,\r
31 0,\r
32 false\r
33 ],\r
34 object: {\r
35 prop: 3,\r
36 objFn: fn3,\r
37 tpl: 'Yo {text}',\r
38 value: '{direct}',\r
39 items: [\r
40 77,\r
41 '{direct}',\r
42 {\r
43 v: '{direct}',\r
44 x: 1,\r
45 s: '-- {text}',\r
46 innerFn: fn4\r
47 },\r
48 'Oy {text}',\r
49 fn5\r
50 ],\r
51 aNull: null,\r
52 aZero: 0, \r
53 aBool: false\r
54 },\r
55 aNull: null,\r
56 aZero: 0,\r
57 aBool: false\r
58 });\r
59\r
60 output = tpl.apply(context);\r
61 });\r
62\r
63 describe('the root', function () {\r
64 it('should pass through numbers', function () {\r
65 expect(output.foo).toBe(42);\r
66 });\r
67\r
68 it('should apply Ext.Template', function () {\r
69 expect(output.bar).toBe('Hello Don');\r
70 });\r
71\r
72 it('should map values', function () {\r
73 expect(output.baz).toBe(false);\r
74 });\r
75\r
76 it('should pass through functions', function() {\r
77 expect(output.rootFn).toBe(fn1);\r
78 });\r
79\r
80 it('should pass through null', function() {\r
81 expect(output.aNull).toBeNull();\r
82 });\r
83\r
84 it('should pass through 0', function() {\r
85 expect(output.aZero).toBe(0);\r
86 });\r
87\r
88 it('should pass through false', function() {\r
89 expect(output.aBool).toBe(false);\r
90 });\r
91 });\r
92\r
93 describe('array on the root', function () {\r
94 it('should have the correct length', function () {\r
95 expect(output.array.length).toBe(8);\r
96 });\r
97\r
98 it('should pass through numbers', function () {\r
99 expect(output.array[0]).toBe(427);\r
100 });\r
101\r
102 it('should apply templates', function () {\r
103 expect(output.array[1]).toBe('Hey Don 456');\r
104 });\r
105\r
106 it('should pull single values through dotted template expansions', function () {\r
107 expect(output.array[2]).toBe(456);\r
108 });\r
109\r
110 it('should pull primitives through simple name expansions', function () {\r
111 expect(output.array[3]).toBe(false);\r
112 });\r
113\r
114 it('should pass through functions', function() {\r
115 expect(output.array[4]).toBe(fn2);\r
116 });\r
117\r
118 it('should pass through null', function() {\r
119 expect(output.array[5]).toBeNull();\r
120 });\r
121\r
122 it('should pass through 0', function() {\r
123 expect(output.array[6]).toBe(0);\r
124 });\r
125\r
126 it('should pass through false', function() {\r
127 expect(output.array[7]).toBe(false);\r
128 });\r
129 });\r
130\r
131 describe('object off the root', function () {\r
132 describe('properties', function () {\r
133 it('should pass through numbers', function () {\r
134 expect(output.object.prop).toBe(3);\r
135 });\r
136\r
137 it('should apply XTemplate', function () {\r
138 expect(output.object.tpl).toBe('Yo Don');\r
139 });\r
140\r
141 it('should map values', function () {\r
142 expect(output.object.value).toBe(false);\r
143 });\r
144\r
145 it('should pass through functions', function () {\r
146 expect(output.object.objFn).toBe(fn3);\r
147 });\r
148\r
149 it('should pass through null', function() {\r
150 expect(output.object.aNull).toBeNull();\r
151 });\r
152\r
153 it('should pass through 0', function() {\r
154 expect(output.object.aZero).toBe(0);\r
155 });\r
156\r
157 it('should pass through false', function() {\r
158 expect(output.object.aBool).toBe(false);\r
159 });\r
160 });\r
161\r
162 describe('an array property', function () {\r
163 it('should have the correct length', function () {\r
164 expect(output.object.items.length).toBe(5);\r
165 });\r
166 it('should pass through numbers', function () {\r
167 expect(output.object.items[0]).toBe(77);\r
168 });\r
169 it('should pull primitives through simple name expansions', function () {\r
170 expect(output.object.items[1]).toBe(false);\r
171 });\r
172 it('should apply XTemplate', function () {\r
173 expect(output.object.items[3]).toBe('Oy Don');\r
174 });\r
175 it('should pass through functions', function () {\r
176 expect(output.object.items[4]).toBe(fn5);\r
177 });\r
178 });\r
179\r
180 describe('an object element of an array property', function () {\r
181 it('should pull primitives through simple name expansions', function () {\r
182 expect(output.object.items[2].v).toBe(false);\r
183 });\r
184 it('should pass through numbers', function () {\r
185 expect(output.object.items[2].x).toBe(1);\r
186 });\r
187 it('should apply XTemplate', function () {\r
188 expect(output.object.items[2].s).toBe('-- Don');\r
189 });\r
190 it('should pass through numbers', function () {\r
191 expect(output.object.items[2].innerFn).toBe(fn4);\r
192 });\r
193 });\r
194 });\r
195});\r