Annotate

spec/util_dataforms_spec.lua @ 9733:9ab9aabafa80

core.moduleapi: Add a promise-based API for tracking IQ stanzas (fixes #714)
author Kim Alvefur <zash@zash.se>
date Fri, 28 Dec 2018 20:51:31 +0100
parent 9243:a4c52e304e6f
child 10512:3089086d31fa
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 {
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
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
22 type = "boolean",
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
23 label = "boolean-label",
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
24 name = "boolean-field",
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
25 value = true,
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
26 },
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
27 {
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
28 type = "fixed",
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
29 label = "fixed-label",
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
30 name = "fixed-field",
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
31 value = "fixed-value",
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
32 },
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
33 {
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
34 type = "hidden",
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
35 label = "hidden-label",
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
36 name = "hidden-field",
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
37 value = "hidden-value",
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
38 },
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
39 {
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
40 type = "jid-multi",
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
41 label = "jid-multi-label",
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
42 name = "jid-multi-field",
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
43 value = {
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
44 "jid@multi/value#1",
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
45 "jid@multi/value#2",
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
46 },
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
47 },
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
48 {
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
49 type = "jid-single",
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
50 label = "jid-single-label",
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
51 name = "jid-single-field",
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
52 value = "jid@single/value",
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
53 },
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
54 {
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
55 type = "list-multi",
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
56 label = "list-multi-label",
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
57 name = "list-multi-field",
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
58 value = {
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
59 "list-multi-option-value#1",
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
60 "list-multi-option-value#3",
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
61 },
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
62 options = {
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 label = "list-multi-option-label#1",
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
65 value = "list-multi-option-value#1",
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
66 default = true,
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
67 },
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 label = "list-multi-option-label#2",
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
70 value = "list-multi-option-value#2",
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
71 default = false,
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
72 },
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 label = "list-multi-option-label#3",
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
75 value = "list-multi-option-value#3",
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
76 default = true,
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
77 },
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
78 }
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
79 },
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
80 {
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
81 type = "list-single",
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
82 label = "list-single-label",
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
83 name = "list-single-field",
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
84 value = "list-single-value",
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
85 options = {
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
86 "list-single-value",
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
87 "list-single-value#2",
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
88 "list-single-value#3",
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
89 }
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
90 },
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
91 {
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
92 type = "text-multi",
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
93 label = "text-multi-label",
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
94 name = "text-multi-field",
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
95 value = "text\nmulti\nvalue",
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
96 },
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
97 {
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
98 type = "text-private",
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
99 label = "text-private-label",
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
100 name = "text-private-field",
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
101 value = "text-private-value",
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
102 },
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
103 {
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
104 type = "text-single",
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
105 label = "text-single-label",
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
106 name = "text-single-field",
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
107 value = "text-single-value",
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 });
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
110 xform = some_form:form();
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
111 end);
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
112
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
113 it("works", function ()
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
114 assert.truthy(xform);
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
115 assert.truthy(st.is_stanza(xform));
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
116 assert.equal("x", xform.name);
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
117 assert.equal("jabber:x:data", xform.attr.xmlns);
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
118 assert.equal("FORM_TYPE", xform:find("field@var"));
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
119 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
120 local allowed_direct_children = {
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
121 title = true,
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
122 instructions = true,
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
123 field = true,
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
124 }
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
125 for tag in xform:childtags() do
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
126 assert.truthy(allowed_direct_children[tag.name], "unknown direct child");
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
127 end
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
128 end);
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
129
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
130 it("produced boolean field correctly", function ()
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
131 local f;
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
132 for field in xform:childtags("field") do
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
133 if field.attr.var == "boolean-field" then
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
134 f = field;
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
135 break;
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
136 end
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
137 end
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
138
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
139 assert.truthy(st.is_stanza(f));
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
140 assert.equal("boolean-field", f.attr.var);
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
141 assert.equal("boolean", f.attr.type);
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
142 assert.equal("boolean-label", f.attr.label);
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
143 assert.equal(1, iter.count(f:childtags("value")));
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
144 local val = f:get_child_text("value");
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
145 assert.truthy(val == "true" or val == "1");
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
146 end);
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
147
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
148 it("produced fixed field correctly", function ()
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
149 local f;
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
150 for field in xform:childtags("field") do
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
151 if field.attr.var == "fixed-field" then
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
152 f = field;
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
153 break;
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
154 end
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
155 end
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
156
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
157 assert.truthy(st.is_stanza(f));
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
158 assert.equal("fixed-field", f.attr.var);
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
159 assert.equal("fixed", f.attr.type);
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
160 assert.equal("fixed-label", f.attr.label);
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
161 assert.equal(1, iter.count(f:childtags("value")));
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
162 assert.equal("fixed-value", f:get_child_text("value"));
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
163 end);
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
164
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
165 it("produced hidden field correctly", function ()
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
166 local f;
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
167 for field in xform:childtags("field") do
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
168 if field.attr.var == "hidden-field" then
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
169 f = field;
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
170 break;
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
171 end
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
172 end
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
173
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
174 assert.truthy(st.is_stanza(f));
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
175 assert.equal("hidden-field", f.attr.var);
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
176 assert.equal("hidden", f.attr.type);
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
177 assert.equal("hidden-label", f.attr.label);
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
178 assert.equal(1, iter.count(f:childtags("value")));
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
179 assert.equal("hidden-value", f:get_child_text("value"));
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
180 end);
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
181
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
182 it("produced jid-multi field correctly", function ()
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
183 local f;
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
184 for field in xform:childtags("field") do
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
185 if field.attr.var == "jid-multi-field" then
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
186 f = field;
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
187 break;
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
188 end
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
189 end
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
190
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
191 assert.truthy(st.is_stanza(f));
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
192 assert.equal("jid-multi-field", f.attr.var);
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
193 assert.equal("jid-multi", f.attr.type);
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
194 assert.equal("jid-multi-label", f.attr.label);
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
195 assert.equal(2, iter.count(f:childtags("value")));
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
196
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
197 local i = 0;
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
198 for value in f:childtags("value") do
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
199 i = i + 1;
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
200 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
201 end
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
202 end);
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
203
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
204 it("produced jid-single field correctly", function ()
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
205 local f;
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
206 for field in xform:childtags("field") do
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
207 if field.attr.var == "jid-single-field" then
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
208 f = field;
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
209 break;
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
210 end
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
211 end
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
212
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
213 assert.truthy(st.is_stanza(f));
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
214 assert.equal("jid-single-field", f.attr.var);
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
215 assert.equal("jid-single", f.attr.type);
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
216 assert.equal("jid-single-label", f.attr.label);
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
217 assert.equal(1, iter.count(f:childtags("value")));
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
218 assert.equal("jid@single/value", f:get_child_text("value"));
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
219 assert.truthy(jid.prep(f:get_child_text("value")));
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
220 end);
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
221
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
222 it("produced list-multi field correctly", function ()
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
223 local f;
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
224 for field in xform:childtags("field") do
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
225 if field.attr.var == "list-multi-field" then
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
226 f = field;
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
227 break;
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
228 end
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
229 end
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
230
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
231 assert.truthy(st.is_stanza(f));
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
232 assert.equal("list-multi-field", f.attr.var);
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
233 assert.equal("list-multi", f.attr.type);
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
234 assert.equal("list-multi-label", f.attr.label);
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
235 assert.equal(2, iter.count(f:childtags("value")));
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
236 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
237 assert.equal(3, iter.count(f:childtags("option")));
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
238 end);
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
239
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
240 it("produced list-single field correctly", function ()
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
241 local f;
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
242 for field in xform:childtags("field") do
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
243 if field.attr.var == "list-single-field" then
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
244 f = field;
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
245 break;
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
246 end
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
247 end
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
248
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
249 assert.truthy(st.is_stanza(f));
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
250 assert.equal("list-single-field", f.attr.var);
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
251 assert.equal("list-single", f.attr.type);
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
252 assert.equal("list-single-label", f.attr.label);
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
253 assert.equal(1, iter.count(f:childtags("value")));
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
254 assert.equal("list-single-value", f:get_child_text("value"));
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
255 assert.equal(3, iter.count(f:childtags("option")));
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
256 end);
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
257
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
258 it("produced text-multi field correctly", function ()
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
259 local f;
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
260 for field in xform:childtags("field") do
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
261 if field.attr.var == "text-multi-field" then
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
262 f = field;
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
263 break;
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
264 end
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
265 end
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
266
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
267 assert.truthy(st.is_stanza(f));
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
268 assert.equal("text-multi-field", f.attr.var);
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
269 assert.equal("text-multi", f.attr.type);
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
270 assert.equal("text-multi-label", f.attr.label);
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
271 assert.equal(3, iter.count(f:childtags("value")));
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
272 end);
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
273
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
274 it("produced text-private field correctly", function ()
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
275 local f;
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
276 for field in xform:childtags("field") do
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
277 if field.attr.var == "text-private-field" then
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
278 f = field;
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
279 break;
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
280 end
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
281 end
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
282
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
283 assert.truthy(st.is_stanza(f));
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
284 assert.equal("text-private-field", f.attr.var);
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
285 assert.equal("text-private", f.attr.type);
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
286 assert.equal("text-private-label", f.attr.label);
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
287 assert.equal(1, iter.count(f:childtags("value")));
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
288 assert.equal("text-private-value", f:get_child_text("value"));
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
289 end);
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
290
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
291 it("produced text-single field correctly", function ()
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
292 local f;
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
293 for field in xform:childtags("field") do
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
294 if field.attr.var == "text-single-field" then
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
295 f = field;
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
296 break;
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
297 end
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
298 end
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
299
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
300 assert.truthy(st.is_stanza(f));
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
301 assert.equal("text-single-field", f.attr.var);
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
302 assert.equal("text-single", f.attr.type);
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
303 assert.equal("text-single-label", f.attr.label);
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
304 assert.equal(1, iter.count(f:childtags("value")));
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
305 assert.equal("text-single-value", f:get_child_text("value"));
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
306 end);
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
307
8864
cf2f66b233d1 util.dataforms: Add a simple function for identifying form types
Kim Alvefur <zash@zash.se>
parents: 8862
diff changeset
308 describe("get_type()", function ()
cf2f66b233d1 util.dataforms: Add a simple function for identifying form types
Kim Alvefur <zash@zash.se>
parents: 8862
diff changeset
309 it("identifes dataforms", function ()
cf2f66b233d1 util.dataforms: Add a simple function for identifying form types
Kim Alvefur <zash@zash.se>
parents: 8862
diff changeset
310 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
311 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
312 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
313 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
314 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
315 end);
cf2f66b233d1 util.dataforms: Add a simple function for identifying form types
Kim Alvefur <zash@zash.se>
parents: 8862
diff changeset
316 end);
9046
7cdc718312c8 util.dataforms: Include a fixed field in test
Kim Alvefur <zash@zash.se>
parents: 8864
diff changeset
317
7cdc718312c8 util.dataforms: Include a fixed field in test
Kim Alvefur <zash@zash.se>
parents: 8864
diff changeset
318 describe(":data", function ()
7cdc718312c8 util.dataforms: Include a fixed field in test
Kim Alvefur <zash@zash.se>
parents: 8864
diff changeset
319 it("works", function ()
7cdc718312c8 util.dataforms: Include a fixed field in test
Kim Alvefur <zash@zash.se>
parents: 8864
diff changeset
320 assert.truthy(some_form:data(xform));
7cdc718312c8 util.dataforms: Include a fixed field in test
Kim Alvefur <zash@zash.se>
parents: 8864
diff changeset
321 end);
7cdc718312c8 util.dataforms: Include a fixed field in test
Kim Alvefur <zash@zash.se>
parents: 8864
diff changeset
322 end);
9083
5d3639e415bd util.dataforms: Add failing test for #1177
Kim Alvefur <zash@zash.se>
parents: 9046
diff changeset
323
5d3639e415bd util.dataforms: Add failing test for #1177
Kim Alvefur <zash@zash.se>
parents: 9046
diff changeset
324 describe("issue1177", function ()
5d3639e415bd util.dataforms: Add failing test for #1177
Kim Alvefur <zash@zash.se>
parents: 9046
diff changeset
325 local form_with_stuff;
5d3639e415bd util.dataforms: Add failing test for #1177
Kim Alvefur <zash@zash.se>
parents: 9046
diff changeset
326 setup(function ()
5d3639e415bd util.dataforms: Add failing test for #1177
Kim Alvefur <zash@zash.se>
parents: 9046
diff changeset
327 form_with_stuff = dataforms.new({
5d3639e415bd util.dataforms: Add failing test for #1177
Kim Alvefur <zash@zash.se>
parents: 9046
diff changeset
328 {
5d3639e415bd util.dataforms: Add failing test for #1177
Kim Alvefur <zash@zash.se>
parents: 9046
diff changeset
329 type = "list-single";
5d3639e415bd util.dataforms: Add failing test for #1177
Kim Alvefur <zash@zash.se>
parents: 9046
diff changeset
330 name = "abtest";
5d3639e415bd util.dataforms: Add failing test for #1177
Kim Alvefur <zash@zash.se>
parents: 9046
diff changeset
331 label = "A or B?";
5d3639e415bd util.dataforms: Add failing test for #1177
Kim Alvefur <zash@zash.se>
parents: 9046
diff changeset
332 options = {
5d3639e415bd util.dataforms: Add failing test for #1177
Kim Alvefur <zash@zash.se>
parents: 9046
diff changeset
333 { label = "A", value = "a", default = true },
5d3639e415bd util.dataforms: Add failing test for #1177
Kim Alvefur <zash@zash.se>
parents: 9046
diff changeset
334 { label = "B", value = "b" },
5d3639e415bd util.dataforms: Add failing test for #1177
Kim Alvefur <zash@zash.se>
parents: 9046
diff changeset
335 };
5d3639e415bd util.dataforms: Add failing test for #1177
Kim Alvefur <zash@zash.se>
parents: 9046
diff changeset
336 },
5d3639e415bd util.dataforms: Add failing test for #1177
Kim Alvefur <zash@zash.se>
parents: 9046
diff changeset
337 });
5d3639e415bd util.dataforms: Add failing test for #1177
Kim Alvefur <zash@zash.se>
parents: 9046
diff changeset
338 end);
5d3639e415bd util.dataforms: Add failing test for #1177
Kim Alvefur <zash@zash.se>
parents: 9046
diff changeset
339
5d3639e415bd util.dataforms: Add failing test for #1177
Kim Alvefur <zash@zash.se>
parents: 9046
diff changeset
340 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
341 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
342 assert.truthy(f:find("field/option"));
5d3639e415bd util.dataforms: Add failing test for #1177
Kim Alvefur <zash@zash.se>
parents: 9046
diff changeset
343 end);
5d3639e415bd util.dataforms: Add failing test for #1177
Kim Alvefur <zash@zash.se>
parents: 9046
diff changeset
344
5d3639e415bd util.dataforms: Add failing test for #1177
Kim Alvefur <zash@zash.se>
parents: 9046
diff changeset
345 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
346 local f = form_with_stuff:form({});
5d3639e415bd util.dataforms: Add failing test for #1177
Kim Alvefur <zash@zash.se>
parents: 9046
diff changeset
347 assert.truthy(f:find("field/option"));
5d3639e415bd util.dataforms: Add failing test for #1177
Kim Alvefur <zash@zash.se>
parents: 9046
diff changeset
348 end);
5d3639e415bd util.dataforms: Add failing test for #1177
Kim Alvefur <zash@zash.se>
parents: 9046
diff changeset
349 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
350
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
351 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
352 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
353 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
354 ["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
355 "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
356 };
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
357 ["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
358 ["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
359 ["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
360 ["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
361 ["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
362 ["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
363 ["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
364 ["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
365 "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
366 };
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 };
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 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
369 -- 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
370 ["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
371 "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
372 };
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 ["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
374 ["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
375 ["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
376 ["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
377 ["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
378 ["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
379 ["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
380 ["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
381 "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
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 };
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 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
385 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
386 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
387 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
388 end);
9242
68694c1bd960 util.dataforms: Allow field names to be different from the 'var' attribute
Kim Alvefur <zash@zash.se>
parents: 9121
diff changeset
389
68694c1bd960 util.dataforms: Allow field names to be different from the 'var' attribute
Kim Alvefur <zash@zash.se>
parents: 9121
diff changeset
390 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
391 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
392 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
393 {
68694c1bd960 util.dataforms: Allow field names to be different from the 'var' attribute
Kim Alvefur <zash@zash.se>
parents: 9121
diff changeset
394 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
395 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
396 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
397 }
68694c1bd960 util.dataforms: Allow field names to be different from the 'var' attribute
Kim Alvefur <zash@zash.se>
parents: 9121
diff changeset
398 };
68694c1bd960 util.dataforms: Allow field names to be different from the 'var' attribute
Kim Alvefur <zash@zash.se>
parents: 9121
diff changeset
399 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
400 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
401 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
402 end);
68694c1bd960 util.dataforms: Allow field names to be different from the 'var' attribute
Kim Alvefur <zash@zash.se>
parents: 9121
diff changeset
403 end);
9243
a4c52e304e6f util.dataforms: Add support for XEP-0122: Data Forms Validation
Kim Alvefur <zash@zash.se>
parents: 9242
diff changeset
404
a4c52e304e6f util.dataforms: Add support for XEP-0122: Data Forms Validation
Kim Alvefur <zash@zash.se>
parents: 9242
diff changeset
405 describe("validation", function ()
a4c52e304e6f util.dataforms: Add support for XEP-0122: Data Forms Validation
Kim Alvefur <zash@zash.se>
parents: 9242
diff changeset
406 local f = dataforms.new {
a4c52e304e6f util.dataforms: Add support for XEP-0122: Data Forms Validation
Kim Alvefur <zash@zash.se>
parents: 9242
diff changeset
407 {
a4c52e304e6f util.dataforms: Add support for XEP-0122: Data Forms Validation
Kim Alvefur <zash@zash.se>
parents: 9242
diff changeset
408 name = "number",
a4c52e304e6f util.dataforms: Add support for XEP-0122: Data Forms Validation
Kim Alvefur <zash@zash.se>
parents: 9242
diff changeset
409 type = "text-single",
a4c52e304e6f util.dataforms: Add support for XEP-0122: Data Forms Validation
Kim Alvefur <zash@zash.se>
parents: 9242
diff changeset
410 datatype = "xs:integer",
a4c52e304e6f util.dataforms: Add support for XEP-0122: Data Forms Validation
Kim Alvefur <zash@zash.se>
parents: 9242
diff changeset
411 },
a4c52e304e6f util.dataforms: Add support for XEP-0122: Data Forms Validation
Kim Alvefur <zash@zash.se>
parents: 9242
diff changeset
412 };
a4c52e304e6f util.dataforms: Add support for XEP-0122: Data Forms Validation
Kim Alvefur <zash@zash.se>
parents: 9242
diff changeset
413
a4c52e304e6f util.dataforms: Add support for XEP-0122: Data Forms Validation
Kim Alvefur <zash@zash.se>
parents: 9242
diff changeset
414 it("works", function ()
a4c52e304e6f util.dataforms: Add support for XEP-0122: Data Forms Validation
Kim Alvefur <zash@zash.se>
parents: 9242
diff changeset
415 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
416 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
417 end);
a4c52e304e6f util.dataforms: Add support for XEP-0122: Data Forms Validation
Kim Alvefur <zash@zash.se>
parents: 9242
diff changeset
418
a4c52e304e6f util.dataforms: Add support for XEP-0122: Data Forms Validation
Kim Alvefur <zash@zash.se>
parents: 9242
diff changeset
419 it("works", function ()
a4c52e304e6f util.dataforms: Add support for XEP-0122: Data Forms Validation
Kim Alvefur <zash@zash.se>
parents: 9242
diff changeset
420 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
421 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
422 assert.table(e);
a4c52e304e6f util.dataforms: Add support for XEP-0122: Data Forms Validation
Kim Alvefur <zash@zash.se>
parents: 9242
diff changeset
423 assert.string(e.number);
a4c52e304e6f util.dataforms: Add support for XEP-0122: Data Forms Validation
Kim Alvefur <zash@zash.se>
parents: 9242
diff changeset
424 end);
a4c52e304e6f util.dataforms: Add support for XEP-0122: Data Forms Validation
Kim Alvefur <zash@zash.se>
parents: 9242
diff changeset
425 end);
8862
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
426 end);
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
427