Annotate

spec/util_dataforms_spec.lua @ 8934:365bcf899093

mod_pubsub: Retrieve the node object
author Kim Alvefur <zash@zash.se>
date Tue, 26 Jun 2018 19:34:35 +0200
parent 8864:cf2f66b233d1
child 9046:7cdc718312c8
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
8862
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
1 local dataforms = require "util.dataforms";
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
2 local st = require "util.stanza";
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
3 local jid = require "util.jid";
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
4 local iter = require "util.iterators";
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
5
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
6 describe("util.dataforms", function ()
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
7 local some_form, xform;
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
8 setup(function ()
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
9 some_form = dataforms.new({
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
10 title = "form-title",
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
11 instructions = "form-instructions",
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
12 {
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
13 type = "hidden",
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
14 name = "FORM_TYPE",
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
15 value = "xmpp:prosody.im/spec/util.dataforms#1",
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
16 };
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
17 {
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
18 type = "boolean",
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
19 label = "boolean-label",
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
20 name = "boolean-field",
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
21 value = true,
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
22 },
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
23 {
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
24 type = "fixed",
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
25 label = "fixed-label",
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
26 name = "fixed-field",
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
27 value = "fixed-value",
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
28 },
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
29 {
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
30 type = "hidden",
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
31 label = "hidden-label",
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
32 name = "hidden-field",
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
33 value = "hidden-value",
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
34 },
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
35 {
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
36 type = "jid-multi",
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
37 label = "jid-multi-label",
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
38 name = "jid-multi-field",
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
39 value = {
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
40 "jid@multi/value#1",
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
41 "jid@multi/value#2",
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
42 },
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
43 },
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
44 {
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
45 type = "jid-single",
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
46 label = "jid-single-label",
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
47 name = "jid-single-field",
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
48 value = "jid@single/value",
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
49 },
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
50 {
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
51 type = "list-multi",
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
52 label = "list-multi-label",
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
53 name = "list-multi-field",
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
54 value = {
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
55 "list-multi-option-value#1",
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
56 "list-multi-option-value#3",
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
57 },
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
58 options = {
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
59 {
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
60 label = "list-multi-option-label#1",
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
61 value = "list-multi-option-value#1",
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
62 default = true,
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
63 },
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
64 {
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
65 label = "list-multi-option-label#2",
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
66 value = "list-multi-option-value#2",
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
67 default = false,
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
68 },
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
69 {
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
70 label = "list-multi-option-label#3",
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
71 value = "list-multi-option-value#3",
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
72 default = true,
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
73 },
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
74 }
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
75 },
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
76 {
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
77 type = "list-single",
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
78 label = "list-single-label",
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
79 name = "list-single-field",
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
80 value = "list-single-value",
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
81 options = {
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
82 "list-single-value",
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
83 "list-single-value#2",
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
84 "list-single-value#3",
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
85 }
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
86 },
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
87 {
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
88 type = "text-multi",
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
89 label = "text-multi-label",
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
90 name = "text-multi-field",
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
91 value = "text\nmulti\nvalue",
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
92 },
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
93 {
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
94 type = "text-private",
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
95 label = "text-private-label",
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
96 name = "text-private-field",
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
97 value = "text-private-value",
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
98 },
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
99 {
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
100 type = "text-single",
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
101 label = "text-single-label",
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
102 name = "text-single-field",
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
103 value = "text-single-value",
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
104 },
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
105 });
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
106 xform = some_form:form();
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
107 end);
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
108
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
109 it("works", function ()
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
110 assert.truthy(xform);
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
111 assert.truthy(st.is_stanza(xform));
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
112 assert.equal("x", xform.name);
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
113 assert.equal("jabber:x:data", xform.attr.xmlns);
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
114 assert.equal("FORM_TYPE", xform:find("field@var"));
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
115 assert.equal("xmpp:prosody.im/spec/util.dataforms#1", xform:find("field/value#"));
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
116 local allowed_direct_children = {
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
117 title = true,
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
118 instructions = true,
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
119 field = true,
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
120 }
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
121 for tag in xform:childtags() do
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
122 assert.truthy(allowed_direct_children[tag.name], "unknown direct child");
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
123 end
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
124 end);
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
125
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
126 it("produced boolean field correctly", function ()
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
127 local f;
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
128 for field in xform:childtags("field") do
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
129 if field.attr.var == "boolean-field" then
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
130 f = field;
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
131 break;
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
132 end
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
133 end
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
134
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
135 assert.truthy(st.is_stanza(f));
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
136 assert.equal("boolean-field", f.attr.var);
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
137 assert.equal("boolean", f.attr.type);
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
138 assert.equal("boolean-label", f.attr.label);
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
139 assert.equal(1, iter.count(f:childtags("value")));
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
140 local val = f:get_child_text("value");
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
141 assert.truthy(val == "true" or val == "1");
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
142 end);
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
143
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
144 it("produced fixed field correctly", function ()
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
145 local f;
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
146 for field in xform:childtags("field") do
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
147 if field.attr.var == "fixed-field" then
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
148 f = field;
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
149 break;
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
150 end
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
151 end
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
152
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
153 assert.truthy(st.is_stanza(f));
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
154 assert.equal("fixed-field", f.attr.var);
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
155 assert.equal("fixed", f.attr.type);
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
156 assert.equal("fixed-label", f.attr.label);
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
157 assert.equal(1, iter.count(f:childtags("value")));
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
158 assert.equal("fixed-value", f:get_child_text("value"));
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
159 end);
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
160
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
161 it("produced hidden field correctly", function ()
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
162 local f;
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
163 for field in xform:childtags("field") do
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
164 if field.attr.var == "hidden-field" then
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
165 f = field;
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
166 break;
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
167 end
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
168 end
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
169
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
170 assert.truthy(st.is_stanza(f));
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
171 assert.equal("hidden-field", f.attr.var);
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
172 assert.equal("hidden", f.attr.type);
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
173 assert.equal("hidden-label", f.attr.label);
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
174 assert.equal(1, iter.count(f:childtags("value")));
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
175 assert.equal("hidden-value", f:get_child_text("value"));
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
176 end);
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
177
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
178 it("produced jid-multi field correctly", function ()
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
179 local f;
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
180 for field in xform:childtags("field") do
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
181 if field.attr.var == "jid-multi-field" then
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
182 f = field;
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
183 break;
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
184 end
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
185 end
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
186
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
187 assert.truthy(st.is_stanza(f));
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
188 assert.equal("jid-multi-field", f.attr.var);
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
189 assert.equal("jid-multi", f.attr.type);
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
190 assert.equal("jid-multi-label", f.attr.label);
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
191 assert.equal(2, iter.count(f:childtags("value")));
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
192
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
193 local i = 0;
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
194 for value in f:childtags("value") do
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
195 i = i + 1;
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
196 assert.equal(("jid@multi/value#%d"):format(i), value:get_text());
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
197 end
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
198 end);
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
199
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
200 it("produced jid-single field correctly", function ()
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
201 local f;
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
202 for field in xform:childtags("field") do
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
203 if field.attr.var == "jid-single-field" then
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
204 f = field;
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
205 break;
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
206 end
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
207 end
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
208
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
209 assert.truthy(st.is_stanza(f));
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
210 assert.equal("jid-single-field", f.attr.var);
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
211 assert.equal("jid-single", f.attr.type);
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
212 assert.equal("jid-single-label", f.attr.label);
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
213 assert.equal(1, iter.count(f:childtags("value")));
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
214 assert.equal("jid@single/value", f:get_child_text("value"));
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
215 assert.truthy(jid.prep(f:get_child_text("value")));
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
216 end);
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
217
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
218 it("produced list-multi field correctly", function ()
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
219 local f;
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
220 for field in xform:childtags("field") do
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
221 if field.attr.var == "list-multi-field" then
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
222 f = field;
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
223 break;
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
224 end
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
225 end
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
226
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
227 assert.truthy(st.is_stanza(f));
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
228 assert.equal("list-multi-field", f.attr.var);
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
229 assert.equal("list-multi", f.attr.type);
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
230 assert.equal("list-multi-label", f.attr.label);
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
231 assert.equal(2, iter.count(f:childtags("value")));
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
232 assert.equal("list-multi-option-value#1", f:get_child_text("value"));
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
233 assert.equal(3, iter.count(f:childtags("option")));
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
234 end);
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
235
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
236 it("produced list-single field correctly", function ()
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
237 local f;
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
238 for field in xform:childtags("field") do
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
239 if field.attr.var == "list-single-field" then
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
240 f = field;
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
241 break;
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
242 end
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
243 end
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
244
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
245 assert.truthy(st.is_stanza(f));
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
246 assert.equal("list-single-field", f.attr.var);
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
247 assert.equal("list-single", f.attr.type);
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
248 assert.equal("list-single-label", f.attr.label);
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
249 assert.equal(1, iter.count(f:childtags("value")));
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
250 assert.equal("list-single-value", f:get_child_text("value"));
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
251 assert.equal(3, iter.count(f:childtags("option")));
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
252 end);
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
253
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
254 it("produced text-multi field correctly", function ()
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
255 local f;
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
256 for field in xform:childtags("field") do
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
257 if field.attr.var == "text-multi-field" then
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
258 f = field;
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
259 break;
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
260 end
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
261 end
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
262
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
263 assert.truthy(st.is_stanza(f));
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
264 assert.equal("text-multi-field", f.attr.var);
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
265 assert.equal("text-multi", f.attr.type);
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
266 assert.equal("text-multi-label", f.attr.label);
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
267 assert.equal(3, iter.count(f:childtags("value")));
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
268 end);
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
269
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
270 it("produced text-private field correctly", function ()
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
271 local f;
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
272 for field in xform:childtags("field") do
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
273 if field.attr.var == "text-private-field" then
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
274 f = field;
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
275 break;
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
276 end
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
277 end
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
278
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
279 assert.truthy(st.is_stanza(f));
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
280 assert.equal("text-private-field", f.attr.var);
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
281 assert.equal("text-private", f.attr.type);
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
282 assert.equal("text-private-label", f.attr.label);
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
283 assert.equal(1, iter.count(f:childtags("value")));
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
284 assert.equal("text-private-value", f:get_child_text("value"));
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
285 end);
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
286
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
287 it("produced text-single field correctly", function ()
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
288 local f;
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
289 for field in xform:childtags("field") do
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
290 if field.attr.var == "text-single-field" then
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
291 f = field;
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
292 break;
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
293 end
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
294 end
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
295
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
296 assert.truthy(st.is_stanza(f));
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
297 assert.equal("text-single-field", f.attr.var);
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
298 assert.equal("text-single", f.attr.type);
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
299 assert.equal("text-single-label", f.attr.label);
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
300 assert.equal(1, iter.count(f:childtags("value")));
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
301 assert.equal("text-single-value", f:get_child_text("value"));
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
302 end);
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
303
8864
cf2f66b233d1 util.dataforms: Add a simple function for identifying form types
Kim Alvefur <zash@zash.se>
parents: 8862
diff changeset
304 describe("get_type()", function ()
cf2f66b233d1 util.dataforms: Add a simple function for identifying form types
Kim Alvefur <zash@zash.se>
parents: 8862
diff changeset
305 it("identifes dataforms", function ()
cf2f66b233d1 util.dataforms: Add a simple function for identifying form types
Kim Alvefur <zash@zash.se>
parents: 8862
diff changeset
306 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
307 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
308 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
309 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
310 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
311 end);
cf2f66b233d1 util.dataforms: Add a simple function for identifying form types
Kim Alvefur <zash@zash.se>
parents: 8862
diff changeset
312 end);
8862
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
313 end);
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
314