/
WebComponentCommandBuilderTest.class.st
299 lines (188 loc) · 9.05 KB
/
WebComponentCommandBuilderTest.class.st
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
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
"
A WebComponentCommandBuilderTest is a test class for testing the behavior of WebComponentCommandBuilder
"
Class {
#name : #WebComponentCommandBuilderTest,
#superclass : #WARenderingTest,
#category : 'Willow-Tests-Frontend'
}
{ #category : #private }
WebComponentCommandBuilderTest >> commandBuilder [
^ WebComponentCommandBuilder new
]
{ #category : #tests }
WebComponentCommandBuilderTest >> testAccessibilityEnrichmentCommands [
| html |
html := self apply: (self commandBuilder setARIAAttribute: 'describedBy' to: 'helpBlock') toComponentDefinedBy: [ :canvas | canvas textInput ].
self assert: html equals: '<input aria-describedBy="helpBlock" type="text"/>'
]
{ #category : #tests }
WebComponentCommandBuilderTest >> testAttributeCommands [
| html |
html := self apply: (self commandBuilder setAttribute: 'rows' to: 5) toComponentDefinedBy: [ :canvas | canvas div ].
self assert: html equals: '<div rows="5"></div>'
]
{ #category : #tests }
WebComponentCommandBuilderTest >> testAutofocusCommand [
| html |
html := self apply: self commandBuilder beAutofocused toComponentDefinedBy: [ :canvas | canvas div ].
self assert: html equals: '<div autofocus="autofocus"></div>'
]
{ #category : #tests }
WebComponentCommandBuilderTest >> testBlockExtension [
| html |
html := self
apply: [ :command | (command addScript js: [ :canvas | canvas jQuery this clone ]) + command bePasswordInput ] asWebComponentCommand
toComponentDefinedBy: [ :canvas | canvas textInput ].
self assert: html equals: '<input id="id1" type="password"/><script type="text/javascript">$("#id1").clone();</script>'
]
{ #category : #tests }
WebComponentCommandBuilderTest >> testBoundaryCommands [
| html |
html := self apply: self commandBuilder boundNotNegative toComponentDefinedBy: [ :canvas | canvas numberInput ].
self assert: html equals: '<input min="0" type="number"/>'.
html := self
apply: (self commandBuilder boundBetween: 15 and: 20)
toComponentDefinedBy: [ :canvas | canvas numberInput ].
self assert: html equals: '<input min="15" max="20" type="number"/>'
]
{ #category : #tests }
WebComponentCommandBuilderTest >> testCallbackSettingCommand [
| html |
html := self
apply: (self commandBuilder setCallbackTo: [ "Do something in real life." ])
toComponentDefinedBy: [ :canvas | canvas anchor ].
self assert: html equals: '<a href="/?1"></a>'
]
{ #category : #tests }
WebComponentCommandBuilderTest >> testClassificationCommands [
| html |
html := self apply: self commandBuilder addClass loading toComponentDefinedBy: [ :canvas | canvas div ].
self assert: html equals: '<div class="willow-loading"></div>'.
html := self apply: self commandBuilder addClass willow toComponentDefinedBy: [ :canvas | canvas div ].
self assert: html equals: '<div class="willow"></div>'.
html := self apply: self commandBuilder addClass dialogContainer toComponentDefinedBy: [ :canvas | canvas div ].
self assert: html equals: '<div class="willow-dialog-container"></div>'.
html := self apply: self commandBuilder addClass disabledComponent toComponentDefinedBy: [ :canvas | canvas div ].
self assert: html equals: '<div class="willow-disabled-component"></div>'.
html := self apply: self commandBuilder addClass fadingNotification toComponentDefinedBy: [ :canvas | canvas div ].
self assert: html equals: '<div class="willow-fading-notification"></div>'
]
{ #category : #tests }
WebComponentCommandBuilderTest >> testCompositeCommand [
| html |
html := self
apply: [ :field | (field addScript js: [ :canvas | canvas jQuery this clone ]) + field bePasswordInput ] asWebComponentCommand
toComponentDefinedBy: [ :canvas | canvas textInput ].
self assert: html equals: '<input id="id1" type="password"/><script type="text/javascript">$("#id1").clone();</script>'
]
{ #category : #tests }
WebComponentCommandBuilderTest >> testConditionalCommand [
| html |
html := self apply: [ :field | field when: [ true ] apply: field beReadOnly ] asWebComponentCommand toComponentDefinedBy: [ :canvas | canvas textInput ].
self assert: html equals: '<input readonly="readonly" type="text"/>'.
html := self apply: [ :field | field when: [ false ] apply: field beReadOnly ] asWebComponentCommand toComponentDefinedBy: [ :canvas | canvas textInput ].
self assert: html equals: '<input type="text"/>'
]
{ #category : #tests }
WebComponentCommandBuilderTest >> testDeselectAllOptionsCommands [
| html |
html := self apply: self commandBuilder deselectAllOptions toComponentDefinedBy: [ :canvas | canvas select ].
self
assert: html
equals: '<select id="id1"></select><script type="text/javascript">$("#id1").prop("selectedIndex",-1);</script>'
]
{ #category : #tests }
WebComponentCommandBuilderTest >> testDisableCommand [
| html |
html := self apply: self commandBuilder beDisabled toComponentDefinedBy: [ :canvas | canvas div ].
self assert: html equals: '<div disabled="disabled"></div>'
]
{ #category : #tests }
WebComponentCommandBuilderTest >> testDisableTabCycleCommand [
| html |
html := self apply: self commandBuilder disableTabCycle toComponentDefinedBy: [ :canvas | canvas div ].
self assert: html equals: '<div tabindex="-1"></div>'
]
{ #category : #tests }
WebComponentCommandBuilderTest >> testInputModeCommands [
| html |
html := self apply: self commandBuilder beDateInput toComponentDefinedBy: [ :canvas | canvas textInput ].
self assert: html equals: (self renderUsing: [ :canvas | canvas dateInput5 ]).
html := self apply: self commandBuilder beNumberInput toComponentDefinedBy: [ :canvas | canvas textInput ].
self assert: html equals: (self renderUsing: [ :canvas | canvas numberInput ]).
html := self apply: self commandBuilder bePasswordInput toComponentDefinedBy: [ :canvas | canvas textInput ].
self assert: html equals: '<input type="password"/>'.
html := self apply: self commandBuilder beEmailInput toComponentDefinedBy: [ :canvas | canvas textInput ].
self assert: html equals: '<input type="email"/>'
]
{ #category : #tests }
WebComponentCommandBuilderTest >> testListLabelingCommand [
| html |
html := self
apply: (self commandBuilder labelItemsWith: [ :string | string asUppercase ])
toComponentDefinedBy: [ :canvas | canvas select list: #('one' 'two') ].
self assert: html equals: '<select><option>ONE</option><option>TWO</option></select>'
]
{ #category : #tests }
WebComponentCommandBuilderTest >> testMaxLengthCommand [
| html |
html := self apply: (self commandBuilder setMaximumLengthTo: 25) toComponentDefinedBy: [ :canvas | canvas textInput ].
self assert: html equals: '<input maxlength="25" type="text"/>'
]
{ #category : #tests }
WebComponentCommandBuilderTest >> testMetadataCommands [
| html |
html := self apply: (self commandBuilder setData: 'content' to: 15) toComponentDefinedBy: [ :canvas | canvas div ].
self assert: html equals: '<div data-content="15"></div>'
]
{ #category : #tests }
WebComponentCommandBuilderTest >> testNamingCommand [
| html |
html := self apply: (self commandBuilder setNameTo: 'name') toComponentDefinedBy: [ :canvas | canvas anchor ].
self assert: html equals: '<a name="name"></a>'
]
{ #category : #tests }
WebComponentCommandBuilderTest >> testPlaceholderCommands [
| html |
html := self apply: (self commandBuilder setPlaceholderTo: 'user') toComponentDefinedBy: [ :canvas | canvas textInput ].
self assert: html equals: '<input placeholder="user" type="text"/>'
]
{ #category : #tests }
WebComponentCommandBuilderTest >> testReadOnlyCommand [
| html |
html := self apply: self commandBuilder beReadOnly toComponentDefinedBy: [ :canvas | canvas textInput ].
self assert: html equals: '<input readonly="readonly" type="text"/>'
]
{ #category : #tests }
WebComponentCommandBuilderTest >> testRequiredCommand [
| html |
html := self apply: self commandBuilder beRequired toComponentDefinedBy: [ :canvas | canvas textInput ].
self assert: html equals: '<input required="required" type="text"/>'
]
{ #category : #tests }
WebComponentCommandBuilderTest >> testScriptCommands [
| html |
html := self
apply: (self commandBuilder addScript js: [ :canvas | canvas jQuery this clone ])
toComponentDefinedBy: [ :canvas | canvas textInput ].
self assert: html equals: '<input id="id1" type="text"/><script type="text/javascript">$("#id1").clone();</script>'
]
{ #category : #tests }
WebComponentCommandBuilderTest >> testSetComponentStyleCommands [
| html |
html := self apply: (self commandBuilder setStyleTo: [ :style :constants | style background: constants >> #colors >> #blue ]) toComponentDefinedBy: [ :canvas | canvas div ].
self assert: html equals: '<div style="background: blue;"></div>'
]
{ #category : #tests }
WebComponentCommandBuilderTest >> testTabIndexCommand [
| html |
html := self apply: (self commandBuilder setTabIndexTo: 3) toComponentDefinedBy: [ :canvas | canvas select ].
self assert: html equals: '<select tabindex="3"></select>'
]
{ #category : #tests }
WebComponentCommandBuilderTest >> testTitleCommand [
| html |
html := self apply: (self commandBuilder setTitleTo: 'image') toComponentDefinedBy: [ :canvas | canvas image ].
self assert: html equals: '<img alt="" title="image"/>'
]