Mercurial > prosody-hg
comparison spec/util_dataforms_spec.lua @ 11200:bf8f2da84007
Merge 0.11->trunk
| author | Kim Alvefur <zash@zash.se> |
|---|---|
| date | Thu, 05 Nov 2020 22:31:25 +0100 |
| parents | f7f30a3464fe |
| children | 84f4c6957d62 |
comparison
equal
deleted
inserted
replaced
| 11199:6c7c50a4de32 | 11200:bf8f2da84007 |
|---|---|
| 104 type = "text-single", | 104 type = "text-single", |
| 105 label = "text-single-label", | 105 label = "text-single-label", |
| 106 name = "text-single-field", | 106 name = "text-single-field", |
| 107 value = "text-single-value", | 107 value = "text-single-value", |
| 108 }, | 108 }, |
| 109 { | |
| 110 -- XEP-0221 | |
| 111 -- TODO Validate the XML produced by this. | |
| 112 type = "text-single", | |
| 113 label = "text-single-with-media-label", | |
| 114 name = "text-single-with-media-field", | |
| 115 media = { | |
| 116 height = 24, | |
| 117 width = 32, | |
| 118 { | |
| 119 type = "image/png", | |
| 120 uri = "data:", | |
| 121 }, | |
| 122 }, | |
| 123 }, | |
| 109 }); | 124 }); |
| 110 xform = some_form:form(); | 125 xform = some_form:form(); |
| 111 end); | 126 end); |
| 112 | 127 |
| 113 it("works", function () | 128 it("XML serialization looks like it should", function () |
| 114 assert.truthy(xform); | 129 assert.truthy(xform); |
| 115 assert.truthy(st.is_stanza(xform)); | 130 assert.truthy(st.is_stanza(xform)); |
| 116 assert.equal("x", xform.name); | 131 assert.equal("x", xform.name); |
| 117 assert.equal("jabber:x:data", xform.attr.xmlns); | 132 assert.equal("jabber:x:data", xform.attr.xmlns); |
| 118 assert.equal("FORM_TYPE", xform:find("field@var")); | 133 assert.equal("FORM_TYPE", xform:find("field@var")); |
| 314 assert.equal("xmpp:prosody.im/spec/util.dataforms#1", dataforms.get_type(xform)); | 329 assert.equal("xmpp:prosody.im/spec/util.dataforms#1", dataforms.get_type(xform)); |
| 315 end); | 330 end); |
| 316 end); | 331 end); |
| 317 | 332 |
| 318 describe(":data", function () | 333 describe(":data", function () |
| 319 it("works", function () | 334 it("returns something", function () |
| 320 assert.truthy(some_form:data(xform)); | 335 assert.truthy(some_form:data(xform)); |
| 321 end); | 336 end); |
| 322 end); | 337 end); |
| 323 | 338 |
| 324 describe("issue1177", function () | 339 describe("issue1177", function () |
| 400 assert.equal("someprefix#the-field", x:find"field@var"); | 415 assert.equal("someprefix#the-field", x:find"field@var"); |
| 401 assert.equal("hello", x:find"field/value#"); | 416 assert.equal("hello", x:find"field/value#"); |
| 402 end); | 417 end); |
| 403 end); | 418 end); |
| 404 | 419 |
| 405 describe("validation", function () | 420 describe("datatype validation", function () |
| 406 local f = dataforms.new { | 421 local f = dataforms.new { |
| 407 { | 422 { |
| 408 name = "number", | 423 name = "number", |
| 409 type = "text-single", | 424 type = "text-single", |
| 410 datatype = "xs:integer", | 425 datatype = "xs:integer", |
| 426 range_min = -10, | |
| 427 range_max = 10, | |
| 411 }, | 428 }, |
| 412 }; | 429 }; |
| 413 | 430 |
| 414 it("works", function () | 431 it("integer roundtrip works", function () |
| 415 local d = f:data(f:form({number = 1})); | 432 local d = f:data(f:form({number = 1})); |
| 416 assert.equal(1, d.number); | 433 assert.equal(1, d.number); |
| 417 end); | 434 end); |
| 418 | 435 |
| 419 it("works", function () | 436 it("integer error handling works", function () |
| 420 local d,e = f:data(f:form({number = "nan"})); | 437 local d,e = f:data(f:form({number = "nan"})); |
| 421 assert.not_equal(1, d.number); | 438 assert.not_equal(1, d.number); |
| 422 assert.table(e); | 439 assert.table(e); |
| 423 assert.string(e.number); | 440 assert.string(e.number); |
| 424 end); | 441 end); |
| 442 | |
| 443 it("works", function () | |
| 444 local d,e = f:data(f:form({number = 100})); | |
| 445 assert.not_equal(100, d.number); | |
| 446 assert.table(e); | |
| 447 assert.string(e.number); | |
| 448 end); | |
| 449 end); | |
| 450 describe("media element", function () | |
| 451 it("produced media element correctly", function () | |
| 452 local f; | |
| 453 for field in xform:childtags("field") do | |
| 454 if field.attr.var == "text-single-with-media-field" then | |
| 455 f = field; | |
| 456 break; | |
| 457 end | |
| 458 end | |
| 459 | |
| 460 assert.truthy(st.is_stanza(f)); | |
| 461 assert.equal("text-single-with-media-field", f.attr.var); | |
| 462 assert.equal("text-single", f.attr.type); | |
| 463 assert.equal("text-single-with-media-label", f.attr.label); | |
| 464 assert.equal(0, iter.count(f:childtags("value"))); | |
| 465 | |
| 466 local m = f:get_child("media", "urn:xmpp:media-element"); | |
| 467 assert.truthy(st.is_stanza(m)); | |
| 468 assert.equal("24", m.attr.height); | |
| 469 assert.equal("32", m.attr.width); | |
| 470 assert.equal(1, iter.count(m:childtags("uri"))); | |
| 471 | |
| 472 local u = m:get_child("uri"); | |
| 473 assert.truthy(st.is_stanza(u)); | |
| 474 assert.equal("image/png", u.attr.type); | |
| 475 assert.equal("data:", u:get_text()); | |
| 476 end); | |
| 425 end); | 477 end); |
| 426 end); | 478 end); |
| 427 | 479 |
