From 6b533ad772fb32d00a2f87cb53a87ee9f3a6d689 Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Mon, 16 Dec 2019 02:02:47 +0100 Subject: util.dataforms: Improve descriptions in tests --- spec/util_dataforms_spec.lua | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'spec/util_dataforms_spec.lua') diff --git a/spec/util_dataforms_spec.lua b/spec/util_dataforms_spec.lua index 89759035..085128d1 100644 --- a/spec/util_dataforms_spec.lua +++ b/spec/util_dataforms_spec.lua @@ -110,7 +110,7 @@ describe("util.dataforms", function () xform = some_form:form(); end); - it("works", function () + it("XML serialization looks like it should", function () assert.truthy(xform); assert.truthy(st.is_stanza(xform)); assert.equal("x", xform.name); @@ -316,7 +316,7 @@ describe("util.dataforms", function () end); describe(":data", function () - it("works", function () + it("returns something", function () assert.truthy(some_form:data(xform)); end); end); @@ -402,7 +402,7 @@ describe("util.dataforms", function () end); end); - describe("validation", function () + describe("datatype validation", function () local f = dataforms.new { { name = "number", @@ -411,12 +411,12 @@ describe("util.dataforms", function () }, }; - it("works", function () + it("integer roundtrip works", function () local d = f:data(f:form({number = 1})); assert.equal(1, d.number); end); - it("works", function () + it("integer error handling works", function () local d,e = f:data(f:form({number = "nan"})); assert.not_equal(1, d.number); assert.table(e); -- cgit v1.2.3 From 1c0e4300ab36e37cb2ba83e5dca9f9247785bed6 Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Sun, 16 Aug 2020 12:55:55 +0200 Subject: util.dataforms: Convert media element sizes to avoid error on Lua 5.3 The stanza API does not accept number values and threw an error due to the height and width attributes of the media element (XEP-0221). This part had no test coverage previously, explaining why it was not discovered until now. --- spec/util_dataforms_spec.lua | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'spec/util_dataforms_spec.lua') diff --git a/spec/util_dataforms_spec.lua b/spec/util_dataforms_spec.lua index 085128d1..ae6098be 100644 --- a/spec/util_dataforms_spec.lua +++ b/spec/util_dataforms_spec.lua @@ -106,6 +106,21 @@ describe("util.dataforms", function () name = "text-single-field", value = "text-single-value", }, + { + -- XEP-0221 + -- TODO Validate the XML produced by this. + type = "text-single", + label = "text-single-with-media-label", + name = "text-single-with-media-field", + media = { + height = 24, + width = 32, + { + type = "image/png", + uri = "data:", + }, + }, + }, }); xform = some_form:form(); end); -- cgit v1.2.3 From 8de93db692033a56ab3a516c9aadf6b27060e2a7 Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Sun, 16 Aug 2020 20:30:02 +0200 Subject: util.dataforms: Add more XEP-0211 media element test coverage --- spec/util_dataforms_spec.lua | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) (limited to 'spec/util_dataforms_spec.lua') diff --git a/spec/util_dataforms_spec.lua b/spec/util_dataforms_spec.lua index ae6098be..0df9fb1d 100644 --- a/spec/util_dataforms_spec.lua +++ b/spec/util_dataforms_spec.lua @@ -438,5 +438,33 @@ describe("util.dataforms", function () assert.string(e.number); end); end); + describe("media element", function () + it("produced media element correctly", function () + local f; + for field in xform:childtags("field") do + if field.attr.var == "text-single-with-media-field" then + f = field; + break; + end + end + + assert.truthy(st.is_stanza(f)); + assert.equal("text-single-with-media-field", f.attr.var); + assert.equal("text-single", f.attr.type); + assert.equal("text-single-with-media-label", f.attr.label); + assert.equal(0, iter.count(f:childtags("value"))); + + local m = f:get_child("media", "urn:xmpp:media-element"); + assert.truthy(st.is_stanza(m)); + assert.equal("24", m.attr.height); + assert.equal("32", m.attr.width); + assert.equal(1, iter.count(m:childtags("uri"))); + + local u = m:get_child("uri"); + assert.truthy(st.is_stanza(u)); + assert.equal("image/png", u.attr.type); + assert.equal("data:", u:get_text()); + end); + end); end); -- cgit v1.2.3 From bc20052a9b53c466db12e7d35cf6c073c0ee5a3e Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Thu, 21 Nov 2019 18:56:43 +0100 Subject: util.dataforms: Add support for validating (integer) ranges --- spec/util_dataforms_spec.lua | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'spec/util_dataforms_spec.lua') diff --git a/spec/util_dataforms_spec.lua b/spec/util_dataforms_spec.lua index 0df9fb1d..d2d1264a 100644 --- a/spec/util_dataforms_spec.lua +++ b/spec/util_dataforms_spec.lua @@ -423,6 +423,8 @@ describe("util.dataforms", function () name = "number", type = "text-single", datatype = "xs:integer", + range_min = -10, + range_max = 10, }, }; @@ -437,6 +439,13 @@ describe("util.dataforms", function () assert.table(e); assert.string(e.number); end); + + it("works", function () + local d,e = f:data(f:form({number = 100})); + assert.not_equal(100, d.number); + assert.table(e); + assert.string(e.number); + end); end); describe("media element", function () it("produced media element correctly", function () -- cgit v1.2.3