33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
|
# File 'lib/vendor/xmpp4r/test/dataforms/tc_data.rb', line 33
def test_create
v = Dataforms::XDataTitle.new "This is the title"
assert_equal("This is the title",v.title)
assert_equal("This is the title", v.to_s)
v = Dataforms::XDataInstructions.new "Instructions"
assert_equal("Instructions",v.instructions)
assert_equal("Instructions", v.to_s)
f = Dataforms::XDataField.new "botname", :text_single
assert_nil(f.label)
assert_equal("botname", f.var)
assert_equal(:text_single, f.type)
assert_equal(false, f.required?)
assert_equal([], f.values)
assert_equal({}, f.options)
f.label = "The name of your bot"
assert_equal("The name of your bot", f.label)
[:boolean, :fixed, :hidden, :jid_multi, :jid_single,
:list_multi, :list_single, :text_multi, :text_private,
:text_single].each do |type|
f.type = type
assert_equal(type, f.type)
end
f.type = :wrong_type
assert_nil(f.type)
f.required= true
assert_equal(true, f.required?)
f.values = ["the value"]
assert_equal(["the value"], f.values)
f.options = { "option 1" => "Label 1", "option 2" => "Label 2", "option 3" => nil }
assert_equal({ "option 1" => "Label 1", "option 2" => "Label 2", "option 3" => nil }, f.options)
f = Dataforms::XDataField.new "test", :text_single
v = Dataforms::XData.new :form
assert_equal([], v.fields)
assert_equal(:form, v.type)
[:form, :result, :submit, :cancel].each do |type|
v.type = type
assert_equal(type, v.type)
end
v.add f
assert_equal(f, v.field('test'))
assert_nil(v.field('wrong field'))
assert_equal([f], v.fields)
end
|