Software /
code /
prosody
Annotate
spec/util_dataforms_spec.lua @ 11430:56a282ecdcf1
net.resolvers.basic: Fix completion condition when IPv6 is disabled
Fixes mistake introduced in 5a71f14ab77c that made it so this ready()
newer got called and thus it would be stuck waiting for it.
Looks like the kind of thing that could have been introduced by a merge
or rebase.
Thanks MattJ
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Mon, 15 Mar 2021 23:09:42 +0100 |
parent | 11070:f7f30a3464fe |
child | 11874:84f4c6957d62 |
rev | line source |
---|---|
8862 | 1 local dataforms = require "util.dataforms"; |
2 local st = require "util.stanza"; | |
3 local jid = require "util.jid"; | |
4 local iter = require "util.iterators"; | |
5 | |
6 describe("util.dataforms", function () | |
7 local some_form, xform; | |
8 setup(function () | |
9 some_form = dataforms.new({ | |
10 title = "form-title", | |
11 instructions = "form-instructions", | |
12 { | |
13 type = "hidden", | |
14 name = "FORM_TYPE", | |
15 value = "xmpp:prosody.im/spec/util.dataforms#1", | |
16 }; | |
17 { | |
9046
7cdc718312c8
util.dataforms: Include a fixed field in test
Kim Alvefur <zash@zash.se>
parents:
8864
diff
changeset
|
18 type = "fixed"; |
7cdc718312c8
util.dataforms: Include a fixed field in test
Kim Alvefur <zash@zash.se>
parents:
8864
diff
changeset
|
19 value = "Fixed field"; |
7cdc718312c8
util.dataforms: Include a fixed field in test
Kim Alvefur <zash@zash.se>
parents:
8864
diff
changeset
|
20 }, |
7cdc718312c8
util.dataforms: Include a fixed field in test
Kim Alvefur <zash@zash.se>
parents:
8864
diff
changeset
|
21 { |
8862 | 22 type = "boolean", |
23 label = "boolean-label", | |
24 name = "boolean-field", | |
25 value = true, | |
26 }, | |
27 { | |
28 type = "fixed", | |
29 label = "fixed-label", | |
30 name = "fixed-field", | |
31 value = "fixed-value", | |
32 }, | |
33 { | |
34 type = "hidden", | |
35 label = "hidden-label", | |
36 name = "hidden-field", | |
37 value = "hidden-value", | |
38 }, | |
39 { | |
40 type = "jid-multi", | |
41 label = "jid-multi-label", | |
42 name = "jid-multi-field", | |
43 value = { | |
44 "jid@multi/value#1", | |
45 "jid@multi/value#2", | |
46 }, | |
47 }, | |
48 { | |
49 type = "jid-single", | |
50 label = "jid-single-label", | |
51 name = "jid-single-field", | |
52 value = "jid@single/value", | |
53 }, | |
54 { | |
55 type = "list-multi", | |
56 label = "list-multi-label", | |
57 name = "list-multi-field", | |
58 value = { | |
59 "list-multi-option-value#1", | |
60 "list-multi-option-value#3", | |
61 }, | |
62 options = { | |
63 { | |
64 label = "list-multi-option-label#1", | |
65 value = "list-multi-option-value#1", | |
66 default = true, | |
67 }, | |
68 { | |
69 label = "list-multi-option-label#2", | |
70 value = "list-multi-option-value#2", | |
71 default = false, | |
72 }, | |
73 { | |
74 label = "list-multi-option-label#3", | |
75 value = "list-multi-option-value#3", | |
76 default = true, | |
77 }, | |
78 } | |
79 }, | |
80 { | |
81 type = "list-single", | |
82 label = "list-single-label", | |
83 name = "list-single-field", | |
84 value = "list-single-value", | |
85 options = { | |
86 "list-single-value", | |
87 "list-single-value#2", | |
88 "list-single-value#3", | |
89 } | |
90 }, | |
91 { | |
92 type = "text-multi", | |
93 label = "text-multi-label", | |
94 name = "text-multi-field", | |
95 value = "text\nmulti\nvalue", | |
96 }, | |
97 { | |
98 type = "text-private", | |
99 label = "text-private-label", | |
100 name = "text-private-field", | |
101 value = "text-private-value", | |
102 }, | |
103 { | |
104 type = "text-single", | |
105 label = "text-single-label", | |
106 name = "text-single-field", | |
107 value = "text-single-value", | |
108 }, | |
11026
a086825ed73a
util.dataforms: Convert media element sizes to avoid error on Lua 5.3
Kim Alvefur <zash@zash.se>
parents:
10512
diff
changeset
|
109 { |
a086825ed73a
util.dataforms: Convert media element sizes to avoid error on Lua 5.3
Kim Alvefur <zash@zash.se>
parents:
10512
diff
changeset
|
110 -- XEP-0221 |
a086825ed73a
util.dataforms: Convert media element sizes to avoid error on Lua 5.3
Kim Alvefur <zash@zash.se>
parents:
10512
diff
changeset
|
111 -- TODO Validate the XML produced by this. |
a086825ed73a
util.dataforms: Convert media element sizes to avoid error on Lua 5.3
Kim Alvefur <zash@zash.se>
parents:
10512
diff
changeset
|
112 type = "text-single", |
a086825ed73a
util.dataforms: Convert media element sizes to avoid error on Lua 5.3
Kim Alvefur <zash@zash.se>
parents:
10512
diff
changeset
|
113 label = "text-single-with-media-label", |
a086825ed73a
util.dataforms: Convert media element sizes to avoid error on Lua 5.3
Kim Alvefur <zash@zash.se>
parents:
10512
diff
changeset
|
114 name = "text-single-with-media-field", |
a086825ed73a
util.dataforms: Convert media element sizes to avoid error on Lua 5.3
Kim Alvefur <zash@zash.se>
parents:
10512
diff
changeset
|
115 media = { |
a086825ed73a
util.dataforms: Convert media element sizes to avoid error on Lua 5.3
Kim Alvefur <zash@zash.se>
parents:
10512
diff
changeset
|
116 height = 24, |
a086825ed73a
util.dataforms: Convert media element sizes to avoid error on Lua 5.3
Kim Alvefur <zash@zash.se>
parents:
10512
diff
changeset
|
117 width = 32, |
a086825ed73a
util.dataforms: Convert media element sizes to avoid error on Lua 5.3
Kim Alvefur <zash@zash.se>
parents:
10512
diff
changeset
|
118 { |
a086825ed73a
util.dataforms: Convert media element sizes to avoid error on Lua 5.3
Kim Alvefur <zash@zash.se>
parents:
10512
diff
changeset
|
119 type = "image/png", |
a086825ed73a
util.dataforms: Convert media element sizes to avoid error on Lua 5.3
Kim Alvefur <zash@zash.se>
parents:
10512
diff
changeset
|
120 uri = "data:", |
a086825ed73a
util.dataforms: Convert media element sizes to avoid error on Lua 5.3
Kim Alvefur <zash@zash.se>
parents:
10512
diff
changeset
|
121 }, |
a086825ed73a
util.dataforms: Convert media element sizes to avoid error on Lua 5.3
Kim Alvefur <zash@zash.se>
parents:
10512
diff
changeset
|
122 }, |
a086825ed73a
util.dataforms: Convert media element sizes to avoid error on Lua 5.3
Kim Alvefur <zash@zash.se>
parents:
10512
diff
changeset
|
123 }, |
8862 | 124 }); |
125 xform = some_form:form(); | |
126 end); | |
127 | |
10512
3089086d31fa
util.dataforms: Improve descriptions in tests
Kim Alvefur <zash@zash.se>
parents:
9243
diff
changeset
|
128 it("XML serialization looks like it should", function () |
8862 | 129 assert.truthy(xform); |
130 assert.truthy(st.is_stanza(xform)); | |
131 assert.equal("x", xform.name); | |
132 assert.equal("jabber:x:data", xform.attr.xmlns); | |
133 assert.equal("FORM_TYPE", xform:find("field@var")); | |
134 assert.equal("xmpp:prosody.im/spec/util.dataforms#1", xform:find("field/value#")); | |
135 local allowed_direct_children = { | |
136 title = true, | |
137 instructions = true, | |
138 field = true, | |
139 } | |
140 for tag in xform:childtags() do | |
141 assert.truthy(allowed_direct_children[tag.name], "unknown direct child"); | |
142 end | |
143 end); | |
144 | |
145 it("produced boolean field correctly", function () | |
146 local f; | |
147 for field in xform:childtags("field") do | |
148 if field.attr.var == "boolean-field" then | |
149 f = field; | |
150 break; | |
151 end | |
152 end | |
153 | |
154 assert.truthy(st.is_stanza(f)); | |
155 assert.equal("boolean-field", f.attr.var); | |
156 assert.equal("boolean", f.attr.type); | |
157 assert.equal("boolean-label", f.attr.label); | |
158 assert.equal(1, iter.count(f:childtags("value"))); | |
159 local val = f:get_child_text("value"); | |
160 assert.truthy(val == "true" or val == "1"); | |
161 end); | |
162 | |
163 it("produced fixed field correctly", function () | |
164 local f; | |
165 for field in xform:childtags("field") do | |
166 if field.attr.var == "fixed-field" then | |
167 f = field; | |
168 break; | |
169 end | |
170 end | |
171 | |
172 assert.truthy(st.is_stanza(f)); | |
173 assert.equal("fixed-field", f.attr.var); | |
174 assert.equal("fixed", f.attr.type); | |
175 assert.equal("fixed-label", f.attr.label); | |
176 assert.equal(1, iter.count(f:childtags("value"))); | |
177 assert.equal("fixed-value", f:get_child_text("value")); | |
178 end); | |
179 | |
180 it("produced hidden field correctly", function () | |
181 local f; | |
182 for field in xform:childtags("field") do | |
183 if field.attr.var == "hidden-field" then | |
184 f = field; | |
185 break; | |
186 end | |
187 end | |
188 | |
189 assert.truthy(st.is_stanza(f)); | |
190 assert.equal("hidden-field", f.attr.var); | |
191 assert.equal("hidden", f.attr.type); | |
192 assert.equal("hidden-label", f.attr.label); | |
193 assert.equal(1, iter.count(f:childtags("value"))); | |
194 assert.equal("hidden-value", f:get_child_text("value")); | |
195 end); | |
196 | |
197 it("produced jid-multi field correctly", function () | |
198 local f; | |
199 for field in xform:childtags("field") do | |
200 if field.attr.var == "jid-multi-field" then | |
201 f = field; | |
202 break; | |
203 end | |
204 end | |
205 | |
206 assert.truthy(st.is_stanza(f)); | |
207 assert.equal("jid-multi-field", f.attr.var); | |
208 assert.equal("jid-multi", f.attr.type); | |
209 assert.equal("jid-multi-label", f.attr.label); | |
210 assert.equal(2, iter.count(f:childtags("value"))); | |
211 | |
212 local i = 0; | |
213 for value in f:childtags("value") do | |
214 i = i + 1; | |
215 assert.equal(("jid@multi/value#%d"):format(i), value:get_text()); | |
216 end | |
217 end); | |
218 | |
219 it("produced jid-single field correctly", function () | |
220 local f; | |
221 for field in xform:childtags("field") do | |
222 if field.attr.var == "jid-single-field" then | |
223 f = field; | |
224 break; | |
225 end | |
226 end | |
227 | |
228 assert.truthy(st.is_stanza(f)); | |
229 assert.equal("jid-single-field", f.attr.var); | |
230 assert.equal("jid-single", f.attr.type); | |
231 assert.equal("jid-single-label", f.attr.label); | |
232 assert.equal(1, iter.count(f:childtags("value"))); | |
233 assert.equal("jid@single/value", f:get_child_text("value")); | |
234 assert.truthy(jid.prep(f:get_child_text("value"))); | |
235 end); | |
236 | |
237 it("produced list-multi field correctly", function () | |
238 local f; | |
239 for field in xform:childtags("field") do | |
240 if field.attr.var == "list-multi-field" then | |
241 f = field; | |
242 break; | |
243 end | |
244 end | |
245 | |
246 assert.truthy(st.is_stanza(f)); | |
247 assert.equal("list-multi-field", f.attr.var); | |
248 assert.equal("list-multi", f.attr.type); | |
249 assert.equal("list-multi-label", f.attr.label); | |
250 assert.equal(2, iter.count(f:childtags("value"))); | |
251 assert.equal("list-multi-option-value#1", f:get_child_text("value")); | |
252 assert.equal(3, iter.count(f:childtags("option"))); | |
253 end); | |
254 | |
255 it("produced list-single field correctly", function () | |
256 local f; | |
257 for field in xform:childtags("field") do | |
258 if field.attr.var == "list-single-field" then | |
259 f = field; | |
260 break; | |
261 end | |
262 end | |
263 | |
264 assert.truthy(st.is_stanza(f)); | |
265 assert.equal("list-single-field", f.attr.var); | |
266 assert.equal("list-single", f.attr.type); | |
267 assert.equal("list-single-label", f.attr.label); | |
268 assert.equal(1, iter.count(f:childtags("value"))); | |
269 assert.equal("list-single-value", f:get_child_text("value")); | |
270 assert.equal(3, iter.count(f:childtags("option"))); | |
271 end); | |
272 | |
273 it("produced text-multi field correctly", function () | |
274 local f; | |
275 for field in xform:childtags("field") do | |
276 if field.attr.var == "text-multi-field" then | |
277 f = field; | |
278 break; | |
279 end | |
280 end | |
281 | |
282 assert.truthy(st.is_stanza(f)); | |
283 assert.equal("text-multi-field", f.attr.var); | |
284 assert.equal("text-multi", f.attr.type); | |
285 assert.equal("text-multi-label", f.attr.label); | |
286 assert.equal(3, iter.count(f:childtags("value"))); | |
287 end); | |
288 | |
289 it("produced text-private field correctly", function () | |
290 local f; | |
291 for field in xform:childtags("field") do | |
292 if field.attr.var == "text-private-field" then | |
293 f = field; | |
294 break; | |
295 end | |
296 end | |
297 | |
298 assert.truthy(st.is_stanza(f)); | |
299 assert.equal("text-private-field", f.attr.var); | |
300 assert.equal("text-private", f.attr.type); | |
301 assert.equal("text-private-label", f.attr.label); | |
302 assert.equal(1, iter.count(f:childtags("value"))); | |
303 assert.equal("text-private-value", f:get_child_text("value")); | |
304 end); | |
305 | |
306 it("produced text-single field correctly", function () | |
307 local f; | |
308 for field in xform:childtags("field") do | |
309 if field.attr.var == "text-single-field" then | |
310 f = field; | |
311 break; | |
312 end | |
313 end | |
314 | |
315 assert.truthy(st.is_stanza(f)); | |
316 assert.equal("text-single-field", f.attr.var); | |
317 assert.equal("text-single", f.attr.type); | |
318 assert.equal("text-single-label", f.attr.label); | |
319 assert.equal(1, iter.count(f:childtags("value"))); | |
320 assert.equal("text-single-value", f:get_child_text("value")); | |
321 end); | |
322 | |
8864
cf2f66b233d1
util.dataforms: Add a simple function for identifying form types
Kim Alvefur <zash@zash.se>
parents:
8862
diff
changeset
|
323 describe("get_type()", function () |
cf2f66b233d1
util.dataforms: Add a simple function for identifying form types
Kim Alvefur <zash@zash.se>
parents:
8862
diff
changeset
|
324 it("identifes dataforms", function () |
cf2f66b233d1
util.dataforms: Add a simple function for identifying form types
Kim Alvefur <zash@zash.se>
parents:
8862
diff
changeset
|
325 assert.equal(nil, dataforms.get_type(nil)); |
cf2f66b233d1
util.dataforms: Add a simple function for identifying form types
Kim Alvefur <zash@zash.se>
parents:
8862
diff
changeset
|
326 assert.equal(nil, dataforms.get_type("")); |
cf2f66b233d1
util.dataforms: Add a simple function for identifying form types
Kim Alvefur <zash@zash.se>
parents:
8862
diff
changeset
|
327 assert.equal(nil, dataforms.get_type({})); |
cf2f66b233d1
util.dataforms: Add a simple function for identifying form types
Kim Alvefur <zash@zash.se>
parents:
8862
diff
changeset
|
328 assert.equal(nil, dataforms.get_type(st.stanza("no-a-form"))); |
cf2f66b233d1
util.dataforms: Add a simple function for identifying form types
Kim Alvefur <zash@zash.se>
parents:
8862
diff
changeset
|
329 assert.equal("xmpp:prosody.im/spec/util.dataforms#1", dataforms.get_type(xform)); |
cf2f66b233d1
util.dataforms: Add a simple function for identifying form types
Kim Alvefur <zash@zash.se>
parents:
8862
diff
changeset
|
330 end); |
cf2f66b233d1
util.dataforms: Add a simple function for identifying form types
Kim Alvefur <zash@zash.se>
parents:
8862
diff
changeset
|
331 end); |
9046
7cdc718312c8
util.dataforms: Include a fixed field in test
Kim Alvefur <zash@zash.se>
parents:
8864
diff
changeset
|
332 |
7cdc718312c8
util.dataforms: Include a fixed field in test
Kim Alvefur <zash@zash.se>
parents:
8864
diff
changeset
|
333 describe(":data", function () |
10512
3089086d31fa
util.dataforms: Improve descriptions in tests
Kim Alvefur <zash@zash.se>
parents:
9243
diff
changeset
|
334 it("returns something", function () |
9046
7cdc718312c8
util.dataforms: Include a fixed field in test
Kim Alvefur <zash@zash.se>
parents:
8864
diff
changeset
|
335 assert.truthy(some_form:data(xform)); |
7cdc718312c8
util.dataforms: Include a fixed field in test
Kim Alvefur <zash@zash.se>
parents:
8864
diff
changeset
|
336 end); |
7cdc718312c8
util.dataforms: Include a fixed field in test
Kim Alvefur <zash@zash.se>
parents:
8864
diff
changeset
|
337 end); |
9083
5d3639e415bd
util.dataforms: Add failing test for #1177
Kim Alvefur <zash@zash.se>
parents:
9046
diff
changeset
|
338 |
5d3639e415bd
util.dataforms: Add failing test for #1177
Kim Alvefur <zash@zash.se>
parents:
9046
diff
changeset
|
339 describe("issue1177", function () |
5d3639e415bd
util.dataforms: Add failing test for #1177
Kim Alvefur <zash@zash.se>
parents:
9046
diff
changeset
|
340 local form_with_stuff; |
5d3639e415bd
util.dataforms: Add failing test for #1177
Kim Alvefur <zash@zash.se>
parents:
9046
diff
changeset
|
341 setup(function () |
5d3639e415bd
util.dataforms: Add failing test for #1177
Kim Alvefur <zash@zash.se>
parents:
9046
diff
changeset
|
342 form_with_stuff = dataforms.new({ |
5d3639e415bd
util.dataforms: Add failing test for #1177
Kim Alvefur <zash@zash.se>
parents:
9046
diff
changeset
|
343 { |
5d3639e415bd
util.dataforms: Add failing test for #1177
Kim Alvefur <zash@zash.se>
parents:
9046
diff
changeset
|
344 type = "list-single"; |
5d3639e415bd
util.dataforms: Add failing test for #1177
Kim Alvefur <zash@zash.se>
parents:
9046
diff
changeset
|
345 name = "abtest"; |
5d3639e415bd
util.dataforms: Add failing test for #1177
Kim Alvefur <zash@zash.se>
parents:
9046
diff
changeset
|
346 label = "A or B?"; |
5d3639e415bd
util.dataforms: Add failing test for #1177
Kim Alvefur <zash@zash.se>
parents:
9046
diff
changeset
|
347 options = { |
5d3639e415bd
util.dataforms: Add failing test for #1177
Kim Alvefur <zash@zash.se>
parents:
9046
diff
changeset
|
348 { label = "A", value = "a", default = true }, |
5d3639e415bd
util.dataforms: Add failing test for #1177
Kim Alvefur <zash@zash.se>
parents:
9046
diff
changeset
|
349 { label = "B", value = "b" }, |
5d3639e415bd
util.dataforms: Add failing test for #1177
Kim Alvefur <zash@zash.se>
parents:
9046
diff
changeset
|
350 }; |
5d3639e415bd
util.dataforms: Add failing test for #1177
Kim Alvefur <zash@zash.se>
parents:
9046
diff
changeset
|
351 }, |
5d3639e415bd
util.dataforms: Add failing test for #1177
Kim Alvefur <zash@zash.se>
parents:
9046
diff
changeset
|
352 }); |
5d3639e415bd
util.dataforms: Add failing test for #1177
Kim Alvefur <zash@zash.se>
parents:
9046
diff
changeset
|
353 end); |
5d3639e415bd
util.dataforms: Add failing test for #1177
Kim Alvefur <zash@zash.se>
parents:
9046
diff
changeset
|
354 |
5d3639e415bd
util.dataforms: Add failing test for #1177
Kim Alvefur <zash@zash.se>
parents:
9046
diff
changeset
|
355 it("includes options when value is included", function () |
5d3639e415bd
util.dataforms: Add failing test for #1177
Kim Alvefur <zash@zash.se>
parents:
9046
diff
changeset
|
356 local f = form_with_stuff:form({ abtest = "a" }); |
5d3639e415bd
util.dataforms: Add failing test for #1177
Kim Alvefur <zash@zash.se>
parents:
9046
diff
changeset
|
357 assert.truthy(f:find("field/option")); |
5d3639e415bd
util.dataforms: Add failing test for #1177
Kim Alvefur <zash@zash.se>
parents:
9046
diff
changeset
|
358 end); |
5d3639e415bd
util.dataforms: Add failing test for #1177
Kim Alvefur <zash@zash.se>
parents:
9046
diff
changeset
|
359 |
5d3639e415bd
util.dataforms: Add failing test for #1177
Kim Alvefur <zash@zash.se>
parents:
9046
diff
changeset
|
360 it("includes options when value is excluded", function () |
5d3639e415bd
util.dataforms: Add failing test for #1177
Kim Alvefur <zash@zash.se>
parents:
9046
diff
changeset
|
361 local f = form_with_stuff:form({}); |
5d3639e415bd
util.dataforms: Add failing test for #1177
Kim Alvefur <zash@zash.se>
parents:
9046
diff
changeset
|
362 assert.truthy(f:find("field/option")); |
5d3639e415bd
util.dataforms: Add failing test for #1177
Kim Alvefur <zash@zash.se>
parents:
9046
diff
changeset
|
363 end); |
5d3639e415bd
util.dataforms: Add failing test for #1177
Kim Alvefur <zash@zash.se>
parents:
9046
diff
changeset
|
364 end); |
9121
e5eb36ee07a2
util.dataforms: Allow passing the current values to be used in stead of omitted fields
Kim Alvefur <zash@zash.se>
parents:
9083
diff
changeset
|
365 |
e5eb36ee07a2
util.dataforms: Allow passing the current values to be used in stead of omitted fields
Kim Alvefur <zash@zash.se>
parents:
9083
diff
changeset
|
366 describe("using current values in place of missing fields", function () |
e5eb36ee07a2
util.dataforms: Allow passing the current values to be used in stead of omitted fields
Kim Alvefur <zash@zash.se>
parents:
9083
diff
changeset
|
367 it("gets back the previous values when given an empty form", function () |
e5eb36ee07a2
util.dataforms: Allow passing the current values to be used in stead of omitted fields
Kim Alvefur <zash@zash.se>
parents:
9083
diff
changeset
|
368 local current = { |
e5eb36ee07a2
util.dataforms: Allow passing the current values to be used in stead of omitted fields
Kim Alvefur <zash@zash.se>
parents:
9083
diff
changeset
|
369 ["list-multi-field"] = { |
e5eb36ee07a2
util.dataforms: Allow passing the current values to be used in stead of omitted fields
Kim Alvefur <zash@zash.se>
parents:
9083
diff
changeset
|
370 "list-multi-option-value#2"; |
e5eb36ee07a2
util.dataforms: Allow passing the current values to be used in stead of omitted fields
Kim Alvefur <zash@zash.se>
parents:
9083
diff
changeset
|
371 }; |
e5eb36ee07a2
util.dataforms: Allow passing the current values to be used in stead of omitted fields
Kim Alvefur <zash@zash.se>
parents:
9083
diff
changeset
|
372 ["list-single-field"] = "list-single-value#2"; |
e5eb36ee07a2
util.dataforms: Allow passing the current values to be used in stead of omitted fields
Kim Alvefur <zash@zash.se>
parents:
9083
diff
changeset
|
373 ["hidden-field"] = "hidden-value"; |
e5eb36ee07a2
util.dataforms: Allow passing the current values to be used in stead of omitted fields
Kim Alvefur <zash@zash.se>
parents:
9083
diff
changeset
|
374 ["boolean-field"] = false; |
e5eb36ee07a2
util.dataforms: Allow passing the current values to be used in stead of omitted fields
Kim Alvefur <zash@zash.se>
parents:
9083
diff
changeset
|
375 ["text-multi-field"] = "words\ngo\nhere"; |
e5eb36ee07a2
util.dataforms: Allow passing the current values to be used in stead of omitted fields
Kim Alvefur <zash@zash.se>
parents:
9083
diff
changeset
|
376 ["jid-single-field"] = "alice@example.com"; |
e5eb36ee07a2
util.dataforms: Allow passing the current values to be used in stead of omitted fields
Kim Alvefur <zash@zash.se>
parents:
9083
diff
changeset
|
377 ["text-private-field"] = "hunter2"; |
e5eb36ee07a2
util.dataforms: Allow passing the current values to be used in stead of omitted fields
Kim Alvefur <zash@zash.se>
parents:
9083
diff
changeset
|
378 ["text-single-field"] = "text-single-value"; |
e5eb36ee07a2
util.dataforms: Allow passing the current values to be used in stead of omitted fields
Kim Alvefur <zash@zash.se>
parents:
9083
diff
changeset
|
379 ["jid-multi-field"] = { |
e5eb36ee07a2
util.dataforms: Allow passing the current values to be used in stead of omitted fields
Kim Alvefur <zash@zash.se>
parents:
9083
diff
changeset
|
380 "bob@example.net"; |
e5eb36ee07a2
util.dataforms: Allow passing the current values to be used in stead of omitted fields
Kim Alvefur <zash@zash.se>
parents:
9083
diff
changeset
|
381 }; |
e5eb36ee07a2
util.dataforms: Allow passing the current values to be used in stead of omitted fields
Kim Alvefur <zash@zash.se>
parents:
9083
diff
changeset
|
382 }; |
e5eb36ee07a2
util.dataforms: Allow passing the current values to be used in stead of omitted fields
Kim Alvefur <zash@zash.se>
parents:
9083
diff
changeset
|
383 local expect = { |
e5eb36ee07a2
util.dataforms: Allow passing the current values to be used in stead of omitted fields
Kim Alvefur <zash@zash.se>
parents:
9083
diff
changeset
|
384 -- FORM_TYPE = "xmpp:prosody.im/spec/util.dataforms#1"; -- does this need to be included? |
e5eb36ee07a2
util.dataforms: Allow passing the current values to be used in stead of omitted fields
Kim Alvefur <zash@zash.se>
parents:
9083
diff
changeset
|
385 ["list-multi-field"] = { |
e5eb36ee07a2
util.dataforms: Allow passing the current values to be used in stead of omitted fields
Kim Alvefur <zash@zash.se>
parents:
9083
diff
changeset
|
386 "list-multi-option-value#2"; |
e5eb36ee07a2
util.dataforms: Allow passing the current values to be used in stead of omitted fields
Kim Alvefur <zash@zash.se>
parents:
9083
diff
changeset
|
387 }; |
e5eb36ee07a2
util.dataforms: Allow passing the current values to be used in stead of omitted fields
Kim Alvefur <zash@zash.se>
parents:
9083
diff
changeset
|
388 ["list-single-field"] = "list-single-value#2"; |
e5eb36ee07a2
util.dataforms: Allow passing the current values to be used in stead of omitted fields
Kim Alvefur <zash@zash.se>
parents:
9083
diff
changeset
|
389 ["hidden-field"] = "hidden-value"; |
e5eb36ee07a2
util.dataforms: Allow passing the current values to be used in stead of omitted fields
Kim Alvefur <zash@zash.se>
parents:
9083
diff
changeset
|
390 ["boolean-field"] = false; |
e5eb36ee07a2
util.dataforms: Allow passing the current values to be used in stead of omitted fields
Kim Alvefur <zash@zash.se>
parents:
9083
diff
changeset
|
391 ["text-multi-field"] = "words\ngo\nhere"; |
e5eb36ee07a2
util.dataforms: Allow passing the current values to be used in stead of omitted fields
Kim Alvefur <zash@zash.se>
parents:
9083
diff
changeset
|
392 ["jid-single-field"] = "alice@example.com"; |
e5eb36ee07a2
util.dataforms: Allow passing the current values to be used in stead of omitted fields
Kim Alvefur <zash@zash.se>
parents:
9083
diff
changeset
|
393 ["text-private-field"] = "hunter2"; |
e5eb36ee07a2
util.dataforms: Allow passing the current values to be used in stead of omitted fields
Kim Alvefur <zash@zash.se>
parents:
9083
diff
changeset
|
394 ["text-single-field"] = "text-single-value"; |
e5eb36ee07a2
util.dataforms: Allow passing the current values to be used in stead of omitted fields
Kim Alvefur <zash@zash.se>
parents:
9083
diff
changeset
|
395 ["jid-multi-field"] = { |
e5eb36ee07a2
util.dataforms: Allow passing the current values to be used in stead of omitted fields
Kim Alvefur <zash@zash.se>
parents:
9083
diff
changeset
|
396 "bob@example.net"; |
e5eb36ee07a2
util.dataforms: Allow passing the current values to be used in stead of omitted fields
Kim Alvefur <zash@zash.se>
parents:
9083
diff
changeset
|
397 }; |
e5eb36ee07a2
util.dataforms: Allow passing the current values to be used in stead of omitted fields
Kim Alvefur <zash@zash.se>
parents:
9083
diff
changeset
|
398 }; |
e5eb36ee07a2
util.dataforms: Allow passing the current values to be used in stead of omitted fields
Kim Alvefur <zash@zash.se>
parents:
9083
diff
changeset
|
399 local data, err = some_form:data(st.stanza("x", {xmlns="jabber:x:data"}), current); |
e5eb36ee07a2
util.dataforms: Allow passing the current values to be used in stead of omitted fields
Kim Alvefur <zash@zash.se>
parents:
9083
diff
changeset
|
400 assert.is.table(data, err); |
e5eb36ee07a2
util.dataforms: Allow passing the current values to be used in stead of omitted fields
Kim Alvefur <zash@zash.se>
parents:
9083
diff
changeset
|
401 assert.same(expect, data, "got back the same data"); |
e5eb36ee07a2
util.dataforms: Allow passing the current values to be used in stead of omitted fields
Kim Alvefur <zash@zash.se>
parents:
9083
diff
changeset
|
402 end); |
e5eb36ee07a2
util.dataforms: Allow passing the current values to be used in stead of omitted fields
Kim Alvefur <zash@zash.se>
parents:
9083
diff
changeset
|
403 end); |
9242
68694c1bd960
util.dataforms: Allow field names to be different from the 'var' attribute
Kim Alvefur <zash@zash.se>
parents:
9121
diff
changeset
|
404 |
68694c1bd960
util.dataforms: Allow field names to be different from the 'var' attribute
Kim Alvefur <zash@zash.se>
parents:
9121
diff
changeset
|
405 describe("field 'var' property", function () |
68694c1bd960
util.dataforms: Allow field names to be different from the 'var' attribute
Kim Alvefur <zash@zash.se>
parents:
9121
diff
changeset
|
406 it("works as expected", function () |
68694c1bd960
util.dataforms: Allow field names to be different from the 'var' attribute
Kim Alvefur <zash@zash.se>
parents:
9121
diff
changeset
|
407 local f = dataforms.new { |
68694c1bd960
util.dataforms: Allow field names to be different from the 'var' attribute
Kim Alvefur <zash@zash.se>
parents:
9121
diff
changeset
|
408 { |
68694c1bd960
util.dataforms: Allow field names to be different from the 'var' attribute
Kim Alvefur <zash@zash.se>
parents:
9121
diff
changeset
|
409 var = "someprefix#the-field", |
68694c1bd960
util.dataforms: Allow field names to be different from the 'var' attribute
Kim Alvefur <zash@zash.se>
parents:
9121
diff
changeset
|
410 name = "the_field", |
68694c1bd960
util.dataforms: Allow field names to be different from the 'var' attribute
Kim Alvefur <zash@zash.se>
parents:
9121
diff
changeset
|
411 type = "text-single", |
68694c1bd960
util.dataforms: Allow field names to be different from the 'var' attribute
Kim Alvefur <zash@zash.se>
parents:
9121
diff
changeset
|
412 } |
68694c1bd960
util.dataforms: Allow field names to be different from the 'var' attribute
Kim Alvefur <zash@zash.se>
parents:
9121
diff
changeset
|
413 }; |
68694c1bd960
util.dataforms: Allow field names to be different from the 'var' attribute
Kim Alvefur <zash@zash.se>
parents:
9121
diff
changeset
|
414 local x = f:form({the_field = "hello"}); |
68694c1bd960
util.dataforms: Allow field names to be different from the 'var' attribute
Kim Alvefur <zash@zash.se>
parents:
9121
diff
changeset
|
415 assert.equal("someprefix#the-field", x:find"field@var"); |
68694c1bd960
util.dataforms: Allow field names to be different from the 'var' attribute
Kim Alvefur <zash@zash.se>
parents:
9121
diff
changeset
|
416 assert.equal("hello", x:find"field/value#"); |
68694c1bd960
util.dataforms: Allow field names to be different from the 'var' attribute
Kim Alvefur <zash@zash.se>
parents:
9121
diff
changeset
|
417 end); |
68694c1bd960
util.dataforms: Allow field names to be different from the 'var' attribute
Kim Alvefur <zash@zash.se>
parents:
9121
diff
changeset
|
418 end); |
9243
a4c52e304e6f
util.dataforms: Add support for XEP-0122: Data Forms Validation
Kim Alvefur <zash@zash.se>
parents:
9242
diff
changeset
|
419 |
10512
3089086d31fa
util.dataforms: Improve descriptions in tests
Kim Alvefur <zash@zash.se>
parents:
9243
diff
changeset
|
420 describe("datatype validation", function () |
9243
a4c52e304e6f
util.dataforms: Add support for XEP-0122: Data Forms Validation
Kim Alvefur <zash@zash.se>
parents:
9242
diff
changeset
|
421 local f = dataforms.new { |
a4c52e304e6f
util.dataforms: Add support for XEP-0122: Data Forms Validation
Kim Alvefur <zash@zash.se>
parents:
9242
diff
changeset
|
422 { |
a4c52e304e6f
util.dataforms: Add support for XEP-0122: Data Forms Validation
Kim Alvefur <zash@zash.se>
parents:
9242
diff
changeset
|
423 name = "number", |
a4c52e304e6f
util.dataforms: Add support for XEP-0122: Data Forms Validation
Kim Alvefur <zash@zash.se>
parents:
9242
diff
changeset
|
424 type = "text-single", |
a4c52e304e6f
util.dataforms: Add support for XEP-0122: Data Forms Validation
Kim Alvefur <zash@zash.se>
parents:
9242
diff
changeset
|
425 datatype = "xs:integer", |
11070
f7f30a3464fe
util.dataforms: Add support for validating (integer) ranges
Kim Alvefur <zash@zash.se>
parents:
11027
diff
changeset
|
426 range_min = -10, |
f7f30a3464fe
util.dataforms: Add support for validating (integer) ranges
Kim Alvefur <zash@zash.se>
parents:
11027
diff
changeset
|
427 range_max = 10, |
9243
a4c52e304e6f
util.dataforms: Add support for XEP-0122: Data Forms Validation
Kim Alvefur <zash@zash.se>
parents:
9242
diff
changeset
|
428 }, |
a4c52e304e6f
util.dataforms: Add support for XEP-0122: Data Forms Validation
Kim Alvefur <zash@zash.se>
parents:
9242
diff
changeset
|
429 }; |
a4c52e304e6f
util.dataforms: Add support for XEP-0122: Data Forms Validation
Kim Alvefur <zash@zash.se>
parents:
9242
diff
changeset
|
430 |
10512
3089086d31fa
util.dataforms: Improve descriptions in tests
Kim Alvefur <zash@zash.se>
parents:
9243
diff
changeset
|
431 it("integer roundtrip works", function () |
9243
a4c52e304e6f
util.dataforms: Add support for XEP-0122: Data Forms Validation
Kim Alvefur <zash@zash.se>
parents:
9242
diff
changeset
|
432 local d = f:data(f:form({number = 1})); |
a4c52e304e6f
util.dataforms: Add support for XEP-0122: Data Forms Validation
Kim Alvefur <zash@zash.se>
parents:
9242
diff
changeset
|
433 assert.equal(1, d.number); |
a4c52e304e6f
util.dataforms: Add support for XEP-0122: Data Forms Validation
Kim Alvefur <zash@zash.se>
parents:
9242
diff
changeset
|
434 end); |
a4c52e304e6f
util.dataforms: Add support for XEP-0122: Data Forms Validation
Kim Alvefur <zash@zash.se>
parents:
9242
diff
changeset
|
435 |
10512
3089086d31fa
util.dataforms: Improve descriptions in tests
Kim Alvefur <zash@zash.se>
parents:
9243
diff
changeset
|
436 it("integer error handling works", function () |
9243
a4c52e304e6f
util.dataforms: Add support for XEP-0122: Data Forms Validation
Kim Alvefur <zash@zash.se>
parents:
9242
diff
changeset
|
437 local d,e = f:data(f:form({number = "nan"})); |
a4c52e304e6f
util.dataforms: Add support for XEP-0122: Data Forms Validation
Kim Alvefur <zash@zash.se>
parents:
9242
diff
changeset
|
438 assert.not_equal(1, d.number); |
a4c52e304e6f
util.dataforms: Add support for XEP-0122: Data Forms Validation
Kim Alvefur <zash@zash.se>
parents:
9242
diff
changeset
|
439 assert.table(e); |
a4c52e304e6f
util.dataforms: Add support for XEP-0122: Data Forms Validation
Kim Alvefur <zash@zash.se>
parents:
9242
diff
changeset
|
440 assert.string(e.number); |
a4c52e304e6f
util.dataforms: Add support for XEP-0122: Data Forms Validation
Kim Alvefur <zash@zash.se>
parents:
9242
diff
changeset
|
441 end); |
11070
f7f30a3464fe
util.dataforms: Add support for validating (integer) ranges
Kim Alvefur <zash@zash.se>
parents:
11027
diff
changeset
|
442 |
f7f30a3464fe
util.dataforms: Add support for validating (integer) ranges
Kim Alvefur <zash@zash.se>
parents:
11027
diff
changeset
|
443 it("works", function () |
f7f30a3464fe
util.dataforms: Add support for validating (integer) ranges
Kim Alvefur <zash@zash.se>
parents:
11027
diff
changeset
|
444 local d,e = f:data(f:form({number = 100})); |
f7f30a3464fe
util.dataforms: Add support for validating (integer) ranges
Kim Alvefur <zash@zash.se>
parents:
11027
diff
changeset
|
445 assert.not_equal(100, d.number); |
f7f30a3464fe
util.dataforms: Add support for validating (integer) ranges
Kim Alvefur <zash@zash.se>
parents:
11027
diff
changeset
|
446 assert.table(e); |
f7f30a3464fe
util.dataforms: Add support for validating (integer) ranges
Kim Alvefur <zash@zash.se>
parents:
11027
diff
changeset
|
447 assert.string(e.number); |
f7f30a3464fe
util.dataforms: Add support for validating (integer) ranges
Kim Alvefur <zash@zash.se>
parents:
11027
diff
changeset
|
448 end); |
9243
a4c52e304e6f
util.dataforms: Add support for XEP-0122: Data Forms Validation
Kim Alvefur <zash@zash.se>
parents:
9242
diff
changeset
|
449 end); |
11027
8ed6c5bdbb21
util.dataforms: Add more XEP-0211 media element test coverage
Kim Alvefur <zash@zash.se>
parents:
11026
diff
changeset
|
450 describe("media element", function () |
8ed6c5bdbb21
util.dataforms: Add more XEP-0211 media element test coverage
Kim Alvefur <zash@zash.se>
parents:
11026
diff
changeset
|
451 it("produced media element correctly", function () |
8ed6c5bdbb21
util.dataforms: Add more XEP-0211 media element test coverage
Kim Alvefur <zash@zash.se>
parents:
11026
diff
changeset
|
452 local f; |
8ed6c5bdbb21
util.dataforms: Add more XEP-0211 media element test coverage
Kim Alvefur <zash@zash.se>
parents:
11026
diff
changeset
|
453 for field in xform:childtags("field") do |
8ed6c5bdbb21
util.dataforms: Add more XEP-0211 media element test coverage
Kim Alvefur <zash@zash.se>
parents:
11026
diff
changeset
|
454 if field.attr.var == "text-single-with-media-field" then |
8ed6c5bdbb21
util.dataforms: Add more XEP-0211 media element test coverage
Kim Alvefur <zash@zash.se>
parents:
11026
diff
changeset
|
455 f = field; |
8ed6c5bdbb21
util.dataforms: Add more XEP-0211 media element test coverage
Kim Alvefur <zash@zash.se>
parents:
11026
diff
changeset
|
456 break; |
8ed6c5bdbb21
util.dataforms: Add more XEP-0211 media element test coverage
Kim Alvefur <zash@zash.se>
parents:
11026
diff
changeset
|
457 end |
8ed6c5bdbb21
util.dataforms: Add more XEP-0211 media element test coverage
Kim Alvefur <zash@zash.se>
parents:
11026
diff
changeset
|
458 end |
8ed6c5bdbb21
util.dataforms: Add more XEP-0211 media element test coverage
Kim Alvefur <zash@zash.se>
parents:
11026
diff
changeset
|
459 |
8ed6c5bdbb21
util.dataforms: Add more XEP-0211 media element test coverage
Kim Alvefur <zash@zash.se>
parents:
11026
diff
changeset
|
460 assert.truthy(st.is_stanza(f)); |
8ed6c5bdbb21
util.dataforms: Add more XEP-0211 media element test coverage
Kim Alvefur <zash@zash.se>
parents:
11026
diff
changeset
|
461 assert.equal("text-single-with-media-field", f.attr.var); |
8ed6c5bdbb21
util.dataforms: Add more XEP-0211 media element test coverage
Kim Alvefur <zash@zash.se>
parents:
11026
diff
changeset
|
462 assert.equal("text-single", f.attr.type); |
8ed6c5bdbb21
util.dataforms: Add more XEP-0211 media element test coverage
Kim Alvefur <zash@zash.se>
parents:
11026
diff
changeset
|
463 assert.equal("text-single-with-media-label", f.attr.label); |
8ed6c5bdbb21
util.dataforms: Add more XEP-0211 media element test coverage
Kim Alvefur <zash@zash.se>
parents:
11026
diff
changeset
|
464 assert.equal(0, iter.count(f:childtags("value"))); |
8ed6c5bdbb21
util.dataforms: Add more XEP-0211 media element test coverage
Kim Alvefur <zash@zash.se>
parents:
11026
diff
changeset
|
465 |
8ed6c5bdbb21
util.dataforms: Add more XEP-0211 media element test coverage
Kim Alvefur <zash@zash.se>
parents:
11026
diff
changeset
|
466 local m = f:get_child("media", "urn:xmpp:media-element"); |
8ed6c5bdbb21
util.dataforms: Add more XEP-0211 media element test coverage
Kim Alvefur <zash@zash.se>
parents:
11026
diff
changeset
|
467 assert.truthy(st.is_stanza(m)); |
8ed6c5bdbb21
util.dataforms: Add more XEP-0211 media element test coverage
Kim Alvefur <zash@zash.se>
parents:
11026
diff
changeset
|
468 assert.equal("24", m.attr.height); |
8ed6c5bdbb21
util.dataforms: Add more XEP-0211 media element test coverage
Kim Alvefur <zash@zash.se>
parents:
11026
diff
changeset
|
469 assert.equal("32", m.attr.width); |
8ed6c5bdbb21
util.dataforms: Add more XEP-0211 media element test coverage
Kim Alvefur <zash@zash.se>
parents:
11026
diff
changeset
|
470 assert.equal(1, iter.count(m:childtags("uri"))); |
8ed6c5bdbb21
util.dataforms: Add more XEP-0211 media element test coverage
Kim Alvefur <zash@zash.se>
parents:
11026
diff
changeset
|
471 |
8ed6c5bdbb21
util.dataforms: Add more XEP-0211 media element test coverage
Kim Alvefur <zash@zash.se>
parents:
11026
diff
changeset
|
472 local u = m:get_child("uri"); |
8ed6c5bdbb21
util.dataforms: Add more XEP-0211 media element test coverage
Kim Alvefur <zash@zash.se>
parents:
11026
diff
changeset
|
473 assert.truthy(st.is_stanza(u)); |
8ed6c5bdbb21
util.dataforms: Add more XEP-0211 media element test coverage
Kim Alvefur <zash@zash.se>
parents:
11026
diff
changeset
|
474 assert.equal("image/png", u.attr.type); |
8ed6c5bdbb21
util.dataforms: Add more XEP-0211 media element test coverage
Kim Alvefur <zash@zash.se>
parents:
11026
diff
changeset
|
475 assert.equal("data:", u:get_text()); |
8ed6c5bdbb21
util.dataforms: Add more XEP-0211 media element test coverage
Kim Alvefur <zash@zash.se>
parents:
11026
diff
changeset
|
476 end); |
8ed6c5bdbb21
util.dataforms: Add more XEP-0211 media element test coverage
Kim Alvefur <zash@zash.se>
parents:
11026
diff
changeset
|
477 end); |
8862 | 478 end); |
479 |