-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathsection.js
210 lines (209 loc) · 6.33 KB
/
section.js
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
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
let suite = {
name: 'Section',
tests: [
{
description: 'Section alone (no other HTML), with text inside, reference is not an array',
template: '{#name}name exists{/name}',
context: {name: 'Dorothy'},
expectedHTML: 'name exists'
},
{
description: 'Section alone (no other HTML), with text inside, reference is an array',
template: '{#name}name exists{/name}',
context: {name: [1, 2]},
expectedHTML: 'name existsname exists'
},
{
description: 'Section alone (no other HTML), with text and refernce inside, reference is not an array',
template: '{#name}{.} exists{/name}',
context: {name: 'Dorothy'},
expectedHTML: 'Dorothy exists'
},
{
description: 'Section alone (no other HTML), with text inside, reference is an array',
template: '{#name}{.} exists{/name}',
context: {name: [1, 2]},
expectedHTML: '1 exists2 exists'
},
{
description: 'Section with HTML inside',
template: '{#name}<div>Hello, <span>world</span></div>{/name}',
context: {name: 'Dorothy'},
expectedHTML: '<div>Hello, <span>world</span></div>'
},
{
description: 'Section inside HTML',
template: '<div>Hello, {#name}<span>world</span>{/name}</div>',
context: {name: 'Dorothy'},
expectedHTML: '<div>Hello, <span>world</span></div>'
},
{
description: 'Section inside HTML',
template: '<div>Hello, ({#name}{.} {/name}). Good numbers.</div>',
context: {name: [1,2,3,4]},
expectedHTML: '<div>Hello, (1 2 3 4 ). Good numbers.</div>'
},
{
description: 'Section in an attribute',
template: '<div class="{#colors}{.} {/colors}"></div>',
context: {colors: ['red', 'blue']},
expectedHTML: '<div class="red blue "></div>'
},
{
description: 'Section in an attribute with an else',
template: '<div class="{#colors}{.}{:else}colorless{/colors}"></div>',
context: {colors: []},
expectedHTML: '<div class="colorless"></div>'
},
{
description: 'Section changes context',
template: 'Hello, {#member}{lastName}{/member}',
context: {member: { lastName: 'Smith'} },
expectedHTML: 'Hello, Smith'
},
{
description: 'Section where reference has dots',
template: 'Hello, {#member.lastName}{.}{/member.lastName}',
context: {member: { lastName: 'Smith'} },
expectedHTML: 'Hello, Smith'
},
{
description: 'Section where reference is a promise',
template: 'Hello, {#now}{.}{/now}',
context: {
now: new Promise((resolve) => {
resolve('and later');
})
},
expectedHTML: 'Hello, and later'
},
{
description: 'Section where reference is a promise that resolves to a falsy value',
template: 'Hello, {#now}later{/now}',
context: {
now: new Promise((resolve) => {
resolve('');
})
},
expectedHTML: 'Hello, '
},
{
description: 'Section with a pending where reference is a promise',
template: 'Hello, {#now}later{:pending}coming soon{/now}',
context: {
now: function() {
return new Promise((resolve) => {
setTimeout(function() {
resolve(true);
}, 100);
});
}
},
expectedHTML: 'Hello, <div class="tornado-pending">coming soon</div>',
expectedHTMLResolved: 'Hello, later'
},
{
description: 'Section with an else where reference is a promise that resolves to a falsy value',
template: 'Hello, {#now}later{:else}never{/now}',
context: {
now: new Promise((resolve) => {
resolve('');
})
},
expectedHTML: 'Hello, never'
},
{
description: 'Section with an else where reference is a promise that rejects',
template: 'Hello, {#now}later{:else}never{/now}',
context: {
now: new Promise((resolve, reject) => {
reject();
})
},
expectedHTML: 'Hello, never'
},
{
description: 'Section with dotted reference where first part is a promise',
template: 'Hello, {#right.now}later{/right.now}',
context: {
right: new Promise((resolve) => {
resolve({now: true});
})
},
expectedHTML: 'Hello, later'
},
{
description: 'Section with sibling exists',
template: '<div>{#brother}brother{/brother}</div><div>{#sister} and sister{/sister}</div>',
context: {
brother: true,
sister: true
},
expectedHTML: '<div>brother</div><div> and sister</div>'
},
{
description: 'Section with sibling exists in attribute',
template: '<div class="{#brother}brother{/brother}{#sister} sister{/sister}"></div>',
context: {
brother: true,
sister: true
},
expectedHTML: '<div class="brother sister"></div>'
},
{
description: 'Section where reference is a function',
template: '{#fun}Way fun!{/fun}',
context: {
fun: function() {
return true;
}
},
expectedHTML: 'Way fun!'
},
{
description: 'Section where dotted reference contains a function',
template: '{#fun.fun}Way fun!{/fun.fun}',
context: {
fun: function() {
return {
fun: true
};
}
},
expectedHTML: 'Way fun!'
},
{
description: 'Section where reference is a function that returns a Promise',
template: '{#fun}Way fun!{/fun}',
context: {
fun: function() {
return new Promise(function(resolve) {
resolve(true);
});
}
},
expectedHTML: 'Way fun!'
},
{
description: 'Section where dotted reference contains a function that returns a Promise',
template: '{#fun.fun}Way fun!{/fun.fun}',
context: {
fun: function() {
return new Promise(function(resolve) {
resolve({fun: true});
});
}
},
expectedHTML: 'Way fun!'
},
{
description: 'Section using the helper syntax ( {@section key="key"}...{/section})',
template: '<span>{@section key="names"}{.} {/section}</span>',
context: {
names: ['Jimmy', 'Prash', 'Steven']
},
expectedHTML: '<span>Jimmy Prash Steven </span>'
}
]
};
export default suite;