Comparison

mod_adhoc_test/mod_adhoc_test.lua @ 3211:2969ed764fe8

mod_adhoc_test: A module to test dataforms generation and rendering
author Kim Alvefur <zash@zash.se>
date Fri, 03 Aug 2018 19:30:15 +0200
comparison
equal deleted inserted replaced
3210:9505282ad24f 3211:2969ed764fe8
1 local dataforms = require "util.dataforms";
2 local adhoc_util = require "util.adhoc";
3 local serialization = require "util.serialization";
4
5 local adhoc_new = module:require "adhoc".new;
6
7 -- Dataform borrowed from Prosodys busted test for util.dataforms
8 local form = dataforms.new({
9 title = "form-title",
10 instructions = "form-instructions",
11 {
12 type = "hidden",
13 name = "FORM_TYPE",
14 value = "xmpp:prosody.im/spec/util.dataforms#1",
15 };
16 {
17 type = "fixed";
18 value = "Fixed field";
19 },
20 {
21 type = "boolean",
22 label = "boolean-label",
23 name = "boolean-field",
24 value = true,
25 },
26 {
27 type = "fixed",
28 label = "fixed-label",
29 name = "fixed-field",
30 value = "fixed-value",
31 },
32 {
33 type = "hidden",
34 label = "hidden-label",
35 name = "hidden-field",
36 value = "hidden-value",
37 },
38 {
39 type = "jid-multi",
40 label = "jid-multi-label",
41 name = "jid-multi-field",
42 value = {
43 "jid@multi/value#1",
44 "jid@multi/value#2",
45 },
46 },
47 {
48 type = "jid-single",
49 label = "jid-single-label",
50 name = "jid-single-field",
51 value = "jid@single/value",
52 },
53 {
54 type = "list-multi",
55 label = "list-multi-label",
56 name = "list-multi-field",
57 value = {
58 "list-multi-option-value#1",
59 "list-multi-option-value#3",
60 },
61 options = {
62 {
63 label = "list-multi-option-label#1",
64 value = "list-multi-option-value#1",
65 default = true,
66 },
67 {
68 label = "list-multi-option-label#2",
69 value = "list-multi-option-value#2",
70 default = false,
71 },
72 {
73 label = "list-multi-option-label#3",
74 value = "list-multi-option-value#3",
75 default = true,
76 },
77 }
78 },
79 {
80 type = "list-single",
81 label = "list-single-label",
82 name = "list-single-field",
83 value = "list-single-value",
84 options = {
85 "list-single-value",
86 "list-single-value#2",
87 "list-single-value#3",
88 }
89 },
90 {
91 type = "text-multi",
92 label = "text-multi-label",
93 name = "text-multi-field",
94 value = "text\nmulti\nvalue",
95 },
96 {
97 type = "text-private",
98 label = "text-private-label",
99 name = "text-private-field",
100 value = "text-private-value",
101 },
102 {
103 type = "text-single",
104 label = "text-single-label",
105 name = "text-single-field",
106 value = "text-single-value",
107 },
108 })
109
110 local function handler(fields, err, data)
111 return {
112 status = "completed",
113 info = "Data was:\n"
114 .. serialization.serialize(err or fields),
115 };
116 end
117
118 module:provides("adhoc",
119 adhoc_new("Dataforms Demo",
120 "xmpp:zash.se/mod_adhoc_test",
121 adhoc_util.new_simple_form(form, handler)));