xmppify 0.0.12

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (120) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +17 -0
  3. data/Gemfile +4 -0
  4. data/LICENSE.txt +22 -0
  5. data/README.md +29 -0
  6. data/Rakefile +1 -0
  7. data/app/assets/javascripts/xmpp/index.js +0 -0
  8. data/app/assets/javascripts/xmpp/scripts/checkplayer.js +12 -0
  9. data/app/assets/javascripts/xmpp/scripts/crossdomain.xml +7 -0
  10. data/app/assets/javascripts/xmpp/scripts/flXHR.js +2 -0
  11. data/app/assets/javascripts/xmpp/scripts/flXHR.swf +0 -0
  12. data/app/assets/javascripts/xmpp/scripts/flXHR.vbs +44 -0
  13. data/app/assets/javascripts/xmpp/scripts/flensed.js +12 -0
  14. data/app/assets/javascripts/xmpp/scripts/strophe.flxhr.js +31 -0
  15. data/app/assets/javascripts/xmpp/scripts/strophe.js +3538 -0
  16. data/app/assets/javascripts/xmpp/scripts/swfobject.js +5 -0
  17. data/app/assets/javascripts/xmpp/scripts/updateplayer.swf +0 -0
  18. data/app/assets/javascripts/xmpp/scripts/xmpp.js.coffee +386 -0
  19. data/app/assets/javascripts/xmpp/strophejs-plugins/LICENSE.txt +19 -0
  20. data/app/assets/javascripts/xmpp/strophejs-plugins/README.markdown +95 -0
  21. data/app/assets/javascripts/xmpp/strophejs-plugins/archive/README.markdown +14 -0
  22. data/app/assets/javascripts/xmpp/strophejs-plugins/archive/iso8601_support.js +32 -0
  23. data/app/assets/javascripts/xmpp/strophejs-plugins/archive/strophe.archive.js +88 -0
  24. data/app/assets/javascripts/xmpp/strophejs-plugins/caps/README.markdown +53 -0
  25. data/app/assets/javascripts/xmpp/strophejs-plugins/caps/sha1.js +202 -0
  26. data/app/assets/javascripts/xmpp/strophejs-plugins/caps/strophe.CAPS.coffee +153 -0
  27. data/app/assets/javascripts/xmpp/strophejs-plugins/caps/strophe.CAPS.js +88 -0
  28. data/app/assets/javascripts/xmpp/strophejs-plugins/caps/strophe.caps.jsonly.js +240 -0
  29. data/app/assets/javascripts/xmpp/strophejs-plugins/chatstates/strophe.chatstates.js +80 -0
  30. data/app/assets/javascripts/xmpp/strophejs-plugins/cmds/README.markdown +47 -0
  31. data/app/assets/javascripts/xmpp/strophejs-plugins/cmds/spec/GetUrlComamndSpec.js +66 -0
  32. data/app/assets/javascripts/xmpp/strophejs-plugins/cmds/spec/strophe.cmds.spec.coffee +145 -0
  33. data/app/assets/javascripts/xmpp/strophejs-plugins/cmds/spec/support/jasmine.json +16 -0
  34. data/app/assets/javascripts/xmpp/strophejs-plugins/cmds/src/strophe.cmds.coffee +265 -0
  35. data/app/assets/javascripts/xmpp/strophejs-plugins/cmds/src/strophe.cmds.js +403 -0
  36. data/app/assets/javascripts/xmpp/strophejs-plugins/dataforms/README.markdown +82 -0
  37. data/app/assets/javascripts/xmpp/strophejs-plugins/dataforms/spec/strophe.x.coffee +715 -0
  38. data/app/assets/javascripts/xmpp/strophejs-plugins/dataforms/src/strophe.x.coffee +443 -0
  39. data/app/assets/javascripts/xmpp/strophejs-plugins/dataforms/src/strophe.x.js +854 -0
  40. data/app/assets/javascripts/xmpp/strophejs-plugins/disco/.gitignore +1 -0
  41. data/app/assets/javascripts/xmpp/strophejs-plugins/disco/README.markdown +0 -0
  42. data/app/assets/javascripts/xmpp/strophejs-plugins/disco/convert.js +13 -0
  43. data/app/assets/javascripts/xmpp/strophejs-plugins/disco/jasmine.json +11 -0
  44. data/app/assets/javascripts/xmpp/strophejs-plugins/disco/lib/strophe.disco.js +137 -0
  45. data/app/assets/javascripts/xmpp/strophejs-plugins/disco/public/javascript/strophe.disco.js +137 -0
  46. data/app/assets/javascripts/xmpp/strophejs-plugins/disco/spec/01_querying_information.xml +6 -0
  47. data/app/assets/javascripts/xmpp/strophejs-plugins/disco/spec/02_result_set_for_information_request.xml +22 -0
  48. data/app/assets/javascripts/xmpp/strophejs-plugins/disco/spec/03_target_entity_does_not_exist.xml +10 -0
  49. data/app/assets/javascripts/xmpp/strophejs-plugins/disco/spec/04_service_unavailable.xml +11 -0
  50. data/app/assets/javascripts/xmpp/strophejs-plugins/disco/spec/09_querying_specific_jid_and_node_combination.xml +7 -0
  51. data/app/assets/javascripts/xmpp/strophejs-plugins/disco/spec/10_jid_and_node_result.xml +12 -0
  52. data/app/assets/javascripts/xmpp/strophejs-plugins/disco/spec/11_requesting_all_items.xml +6 -0
  53. data/app/assets/javascripts/xmpp/strophejs-plugins/disco/spec/12_result_set_for_all_items.xml +23 -0
  54. data/app/assets/javascripts/xmpp/strophejs-plugins/disco/spec/13_empty_result_set.xml +7 -0
  55. data/app/assets/javascripts/xmpp/strophejs-plugins/disco/spec/17_service_returns_nodes.xml +16 -0
  56. data/app/assets/javascripts/xmpp/strophejs-plugins/disco/spec/18_requesting_further_nodes.xml +7 -0
  57. data/app/assets/javascripts/xmpp/strophejs-plugins/disco/spec/24_jid_and_node_error.xml +11 -0
  58. data/app/assets/javascripts/xmpp/strophejs-plugins/disco/spec/DiscoNodeSpec.js +50 -0
  59. data/app/assets/javascripts/xmpp/strophejs-plugins/disco/spec/SpecHelper.js +51 -0
  60. data/app/assets/javascripts/xmpp/strophejs-plugins/disco/spec/Stanzas.js +0 -0
  61. data/app/assets/javascripts/xmpp/strophejs-plugins/disco/spec/strophe.disco.spec.helper.js +54 -0
  62. data/app/assets/javascripts/xmpp/strophejs-plugins/disco/spec/strophe.disco.spec.js +0 -0
  63. data/app/assets/javascripts/xmpp/strophejs-plugins/disco/spec/support/jasmine.json +13 -0
  64. data/app/assets/javascripts/xmpp/strophejs-plugins/disco/strophe.disco.js +232 -0
  65. data/app/assets/javascripts/xmpp/strophejs-plugins/epic/public/javascript/jquery.epic.js +61 -0
  66. data/app/assets/javascripts/xmpp/strophejs-plugins/epic/spec/SpecHelper.js +9 -0
  67. data/app/assets/javascripts/xmpp/strophejs-plugins/epic/spec/jquery.epic.js +39 -0
  68. data/app/assets/javascripts/xmpp/strophejs-plugins/epic/spec/support/jasmine.json +22 -0
  69. data/app/assets/javascripts/xmpp/strophejs-plugins/iexdomain/iexdomain.js +36 -0
  70. data/app/assets/javascripts/xmpp/strophejs-plugins/joap/README.markdown +117 -0
  71. data/app/assets/javascripts/xmpp/strophejs-plugins/joap/buster.js +23 -0
  72. data/app/assets/javascripts/xmpp/strophejs-plugins/joap/jid.coffee +64 -0
  73. data/app/assets/javascripts/xmpp/strophejs-plugins/joap/jid.js +92 -0
  74. data/app/assets/javascripts/xmpp/strophejs-plugins/joap/spec/browserSetup.coffee +1 -0
  75. data/app/assets/javascripts/xmpp/strophejs-plugins/joap/spec/jid.spec.coffee +96 -0
  76. data/app/assets/javascripts/xmpp/strophejs-plugins/joap/spec/strophe.joap.spec.coffee +461 -0
  77. data/app/assets/javascripts/xmpp/strophejs-plugins/joap/strophe.joap.coffee +304 -0
  78. data/app/assets/javascripts/xmpp/strophejs-plugins/joap/strophe.joap.js +522 -0
  79. data/app/assets/javascripts/xmpp/strophejs-plugins/mam/LICENSE.txt +19 -0
  80. data/app/assets/javascripts/xmpp/strophejs-plugins/mam/README.markdown +52 -0
  81. data/app/assets/javascripts/xmpp/strophejs-plugins/mam/strophe.mam.js +62 -0
  82. data/app/assets/javascripts/xmpp/strophejs-plugins/muc/LICENSE.txt +20 -0
  83. data/app/assets/javascripts/xmpp/strophejs-plugins/muc/strophe.muc.js +1003 -0
  84. data/app/assets/javascripts/xmpp/strophejs-plugins/ping/README.markdown +28 -0
  85. data/app/assets/javascripts/xmpp/strophejs-plugins/ping/strophe.ping.js +68 -0
  86. data/app/assets/javascripts/xmpp/strophejs-plugins/private/README.markdown +16 -0
  87. data/app/assets/javascripts/xmpp/strophejs-plugins/private/strophe.private.js +192 -0
  88. data/app/assets/javascripts/xmpp/strophejs-plugins/pubsub/strophe.pubsub.js +555 -0
  89. data/app/assets/javascripts/xmpp/strophejs-plugins/receipts/strophe.receipts.js +155 -0
  90. data/app/assets/javascripts/xmpp/strophejs-plugins/register/README.markdown +44 -0
  91. data/app/assets/javascripts/xmpp/strophejs-plugins/register/strophe.register.js +431 -0
  92. data/app/assets/javascripts/xmpp/strophejs-plugins/roster/public/javascript/strophe.roster.js +40 -0
  93. data/app/assets/javascripts/xmpp/strophejs-plugins/roster/spec/strophe.roster.spec.js +65 -0
  94. data/app/assets/javascripts/xmpp/strophejs-plugins/roster/spec/support/jasmine.json +15 -0
  95. data/app/assets/javascripts/xmpp/strophejs-plugins/roster/strophe.roster.js +438 -0
  96. data/app/assets/javascripts/xmpp/strophejs-plugins/rpc/.gitignore +6 -0
  97. data/app/assets/javascripts/xmpp/strophejs-plugins/rpc/README.md +113 -0
  98. data/app/assets/javascripts/xmpp/strophejs-plugins/rpc/buster.js +11 -0
  99. data/app/assets/javascripts/xmpp/strophejs-plugins/rpc/lib/strophe.js +4198 -0
  100. data/app/assets/javascripts/xmpp/strophejs-plugins/rpc/spec/strophe.rpc.spec.helper.js +38 -0
  101. data/app/assets/javascripts/xmpp/strophejs-plugins/rpc/spec/strophe.rpc.spec.js +262 -0
  102. data/app/assets/javascripts/xmpp/strophejs-plugins/rpc/strophe.rpc.js +464 -0
  103. data/app/assets/javascripts/xmpp/strophejs-plugins/rsm/strophe.rsm.js +52 -0
  104. data/app/assets/javascripts/xmpp/strophejs-plugins/serverdate/strophe.serverdate.js +58 -0
  105. data/app/assets/javascripts/xmpp/strophejs-plugins/vcard/examples/index.html +17 -0
  106. data/app/assets/javascripts/xmpp/strophejs-plugins/vcard/examples/strophevcard.js +0 -0
  107. data/app/assets/javascripts/xmpp/strophejs-plugins/vcard/strophe.vcard.coffee +44 -0
  108. data/app/assets/javascripts/xmpp/strophejs-plugins/vcard/strophe.vcard.js +66 -0
  109. data/app/assets/stylesheets/xmpp/index.css +0 -0
  110. data/app/controllers/omniauth_callbacks_controller.rb +15 -0
  111. data/app/controllers/ruby_bosh.rb +221 -0
  112. data/app/models/identity.rb +3 -0
  113. data/app/models/user.rb +40 -0
  114. data/bin/rails +8 -0
  115. data/db/migrate/20140329065635_create_users.rb +10 -0
  116. data/db/migrate/20140329070238_create_identities.rb +11 -0
  117. data/lib/xmppify/version.rb +3 -0
  118. data/lib/xmppify.rb +6 -0
  119. data/xmppify.gemspec +23 -0
  120. metadata +197 -0
@@ -0,0 +1,715 @@
1
+ describe "XMPP Data Forms (0004)", ->
2
+
3
+ mockConnection = ->
4
+ c = new Strophe.Connection()
5
+ c.authenticated = true
6
+ c.jid = 'n@d/r2'
7
+ c._processRequest = ->
8
+ c._changeConnectStatus Strophe.Status.CONNECTED
9
+ c
10
+
11
+ beforeEach ->
12
+ @con = mockConnection()
13
+ @successHandler = jasmine.createSpy "successHandler"
14
+ @errorHandler = jasmine.createSpy "errorHandler"
15
+ @Sx = Strophe.x
16
+
17
+ it "is installed to the connection object", ->
18
+ (expect typeof @con.x).toEqual "object"
19
+
20
+ it "can parse a result", ->
21
+
22
+ res = $build("command").c("x",{type:"result"}).c("title").t("My title").tree()
23
+ form = @con.x.parseFromResult res
24
+
25
+ (expect form.type).toEqual "result"
26
+ (expect form.title).toEqual "My title"
27
+
28
+ describe "Form", ->
29
+
30
+ it "has one of four possible type attributes", ->
31
+ (expect (new @Sx.Form {type:"form" }).type).toEqual "form"
32
+ (expect (new @Sx.Form {type:"submit"}).type).toEqual "submit"
33
+ (expect (new @Sx.Form {type:"cancel"}).type).toEqual "cancel"
34
+ (expect (new @Sx.Form {type:"result"}).type).toEqual "result"
35
+ (expect (new @Sx.Form {type:"foo"}).type).toEqual "form"
36
+
37
+ it "uses 'form' as default type attribute", ->
38
+ (expect (new @Sx.Form).type).toEqual "form"
39
+
40
+ it "has an optional title", ->
41
+ (expect (new @Sx.Form).title).toEqual null
42
+ (expect (new @Sx.Form {title: "foo"}).title).toEqual "foo"
43
+
44
+ it "has an optional instruction property", ->
45
+ (expect (new @Sx.Form).instructions).toEqual null
46
+ (expect (new @Sx.Form {instructions: "foo"}).instructions).toEqual "foo"
47
+
48
+ it "can have items", ->
49
+ f1 = new @Sx.Field
50
+ i = [{ fields: [f1] }]
51
+ form = new @Sx.Form { items:i }
52
+
53
+ (expect (new @Sx.Form).items).toEqual []
54
+ (expect form.items).toEqual [new @Sx.Item i[0]]
55
+
56
+ it "has a reported' property if items are defined", ->
57
+
58
+ f1 = new @Sx.Field {var: "foo"}
59
+ f2 = new @Sx.Field {var: "bar"}
60
+ i = [{ fields: [f1,f2] }]
61
+ form = new @Sx.Form { items:i }
62
+
63
+ (expect (new @Sx.Form).reported).toEqual []
64
+ (expect form.reported).toEqual ["foo","bar"]
65
+
66
+
67
+ it "can have fields", ->
68
+ f1 = new @Sx.Field { var: "foo", value: "bar"}
69
+ f2 = new @Sx.Field { var: "test", value:123, required: true}
70
+ (expect (new @Sx.Form).fields).toEqual []
71
+ (expect (new @Sx.Form {fields: [f1,f2]}).fields).toEqual [f1,f2]
72
+
73
+ it "converts a form into an xml object", ->
74
+
75
+ f1 = new @Sx.Field
76
+ var: "foo"
77
+ value: "bar"
78
+ type: "list-multi"
79
+ options: [ { label:"bla", value:"blub"}, { label:"foo", value:"bar" }]
80
+
81
+ f2 = { var: "test", value:123, required: true}
82
+
83
+ f = new @Sx.Form
84
+ type: "submit"
85
+ title: "foo"
86
+ instructions: "bar"
87
+ fields: [f1,f2 ]
88
+
89
+ xml = f.toXML()
90
+
91
+ (expect xml.nodeName).toEqual "x"
92
+ (expect xml.getAttribute "xmlns" ).toEqual "jabber:x:data"
93
+ (expect xml.getAttribute "type" ).toEqual "submit"
94
+ (expect xml.childNodes[0].nodeName).toEqual "title"
95
+ (expect xml.childNodes[0].textContent).toEqual "foo"
96
+ (expect xml.childNodes[1].nodeName).toEqual "instructions"
97
+ (expect xml.childNodes[1].textContent).toEqual "bar"
98
+
99
+ f1 = { var: "a", value:"one" }
100
+ f2 = { var: "b", value:"two" }
101
+ f3 = { var: "a", value:"three"}
102
+ f4 = { var: "b", value:"four"}
103
+
104
+ f = new @Sx.Form
105
+ type: "submit"
106
+ items: [{fields:[f1,f2]},{ fields:[ f3,f4]} ]
107
+
108
+ xml = f.toXML()
109
+
110
+ (expect xml.nodeName).toEqual "x"
111
+ (expect xml.getAttribute "xmlns" ).toEqual "jabber:x:data"
112
+ (expect xml.getAttribute "type" ).toEqual "submit"
113
+ (expect xml.childNodes[0].nodeName).toEqual "reported"
114
+ (expect xml.childNodes[1].nodeName).toEqual "item"
115
+
116
+ it "can be convertet into a JSON object", ->
117
+
118
+ f1 = new @Sx.Field
119
+ var: "foo"
120
+ value: "bar"
121
+ type: "list-multi"
122
+ options: [ { label:"bla", value:"blub"}, { label:"foo", value:"bar" }]
123
+
124
+ f2 = { var: "test", value:123, required: true}
125
+
126
+ o = new @Sx.Form
127
+ type: "submit"
128
+ title: "foo"
129
+ instructions: "bar"
130
+ fields: [f1,f2]
131
+
132
+ json = o.toJSON()
133
+ (expect json).toEqual
134
+ type: "submit"
135
+ title: "foo"
136
+ instructions: "bar"
137
+ fields: [ f1.toJSON(), {
138
+ type: "text-single",
139
+ var: "test",
140
+ values:["123"],
141
+ required: true,
142
+ options:[]}
143
+ ]
144
+
145
+ describe "conversion to HTML", ->
146
+
147
+ beforeEach ->
148
+ @f = new @Sx.Form
149
+ title: "My title"
150
+ instructions: "Please fillout the form"
151
+ fields: [{
152
+ type: "list-multi"
153
+ label: "My label"
154
+ var: "alist"
155
+ options: [ {label: "One", value:"one"}, {label: "Two", value:"two"} ] },
156
+
157
+ { type: "text-single", label: "Single label", var: "name" }
158
+ ]
159
+
160
+ it "creates a form as container", ->
161
+
162
+ html = @f.toHTML()
163
+ (expect html.nodeName).toEqual "FORM"
164
+ (expect html.childNodes[0].nodeName).toEqual "H1"
165
+ (expect html.childNodes[1].nodeName).toEqual "P"
166
+
167
+ it "appends the fields with label to the fieldset", ->
168
+ fs = @f.toHTML()
169
+ (expect fs.childNodes[2].nodeName).toEqual "LABEL"
170
+ (expect fs.childNodes[3].nodeName).toEqual "SELECT"
171
+ (expect fs.childNodes[4].nodeName).toEqual "BR"
172
+ (expect fs.childNodes[5].nodeName).toEqual "LABEL"
173
+ (expect fs.childNodes[6].nodeName).toEqual "INPUT"
174
+
175
+ it "appends puts items into fieldsets", ->
176
+
177
+ f1 = new @Sx.Field {var: "foo"}
178
+ f2 = new @Sx.Field {var: "bar"}
179
+ f3 = new @Sx.Field {var: "foo"}
180
+ f4 = new @Sx.Field {var: "bar"}
181
+
182
+ form = new @Sx.Form
183
+ items: [
184
+ { fields: [f1,f2] }
185
+ { fields: [f3,f4] }
186
+ ]
187
+
188
+ html = form.toHTML()
189
+ (expect html.nodeName).toEqual "FORM"
190
+ (expect html.childNodes[0].nodeName).toEqual "FIELDSET"
191
+ (expect html.childNodes[1].nodeName).toEqual "FIELDSET"
192
+
193
+ it "can be created from xml", ->
194
+
195
+ f1 = new @Sx.Field {var: "foo"}
196
+ f2 = new @Sx.Field {var: "bar"}
197
+ f3 = new @Sx.Field {var: "foo"}
198
+ f4 = new @Sx.Field {var: "bar"}
199
+
200
+ form = new @Sx.Form
201
+ title: "test"
202
+ type: "result"
203
+ instructions: "Some text"
204
+ items: [
205
+ { fields: [f1,f2] }
206
+ { fields: [f3,f4] }
207
+ ]
208
+
209
+ (expect @Sx.Form.fromXML( form.toXML()).toJSON() ).toEqual form.toJSON()
210
+
211
+ form = new @Sx.Form
212
+ title: "test"
213
+ type: "result"
214
+ instructions: "Some text"
215
+ fields: [f1,f2, f3,f4]
216
+
217
+ (expect @Sx.Form.fromXML( form.toXML()).toJSON() ).toEqual form.toJSON()
218
+
219
+ it "can be created from HTML", ->
220
+
221
+ f1 = new @Sx.Field {var: "foo"}
222
+ f2 = new @Sx.Field {var: "bar"}
223
+ f3 = new @Sx.Field {var: "foo"}
224
+ f4 = new @Sx.Field {var: "bar"}
225
+
226
+ form = new @Sx.Form
227
+ title: "test"
228
+ type: "result"
229
+ instructions: "Some text"
230
+ items: [
231
+ { fields: [f1,f2] }
232
+ { fields: [f3,f4] }
233
+ ]
234
+
235
+ (expect @Sx.Form.fromHTML( form.toHTML()).toJSON()).toEqual form.toJSON()
236
+
237
+ form = new @Sx.Form
238
+ title: "test"
239
+ type: "result"
240
+ instructions: "Some text"
241
+ fields: [f1,f2, f3,f4]
242
+
243
+ (expect @Sx.Form.fromHTML( form.toHTML()).toJSON() ).toEqual form.toJSON()
244
+
245
+
246
+ describe "Field", ->
247
+
248
+ it "has one of ten possible type attributes", ->
249
+
250
+ types = ["boolean","fixed","hidden","jid-multi","jid-single","list-multi",
251
+ "list-single", "text-multi", "text-private", "text-single"]
252
+ for t in types
253
+ (expect (new @Sx.Field {type:t }).type).toEqual t
254
+
255
+ (expect (new @Sx.Field {type: "foo" }).type).toEqual "text-single"
256
+
257
+ it "uses 'text-single' as default type attribute", ->
258
+ (expect (new @Sx.Field).type).toEqual "text-single"
259
+
260
+ it "must provide a var attribute", ->
261
+ (expect typeof (new @Sx.Field).var).toEqual "string"
262
+ (expect (new @Sx.Field {var: "foo"}).var).toEqual "foo"
263
+
264
+ it "has an optional description", ->
265
+ (expect (new @Sx.Field).desc).toEqual null
266
+ (expect (new @Sx.Field {desc: "foo"}).desc).toEqual "foo"
267
+
268
+ it "has an optional label", ->
269
+ (expect (new @Sx.Field).label).toEqual null
270
+ (expect (new @Sx.Field {label: "foo"}).label).toEqual "foo"
271
+
272
+ it "can be an required filed", ->
273
+ (expect (new @Sx.Field).required).toEqual false
274
+ (expect (new @Sx.Field {required: "foo" }).required).toEqual false
275
+ (expect (new @Sx.Field {required: true}).required).toEqual true
276
+ (expect (new @Sx.Field {required: "true"}).required).toEqual true
277
+
278
+ it "can have a value" , ->
279
+ (expect (new @Sx.Field).values).toEqual []
280
+ (expect (new @Sx.Field {value: "blub"}).values).toEqual ["blub"]
281
+ (expect (new @Sx.Field {values: ["blub","foo"]}).values).toEqual []
282
+
283
+ it "can have multiple values if type is '*-multi' or 'hidden'" , ->
284
+ multiTypes = ["list-multi", "jid-multi","text-multi", "hidden"]
285
+ for t in multiTypes
286
+ (expect (new @Sx.Field {values: ["blub","foo"], type: t}).values).toEqual ["blub","foo"]
287
+
288
+ it "can have options if the type is 'list-single' or 'list-multi'" , ->
289
+ optArray = [ new @Sx.Option { label:"foo", value: "bar"} ]
290
+ (expect (new @Sx.Field).options).toEqual []
291
+ (expect (new @Sx.Field {options: optArray, type: "list-single" }).options).toEqual optArray
292
+ (expect (new @Sx.Field {options: optArray, type: "list-multi" }).options).toEqual optArray
293
+ (expect (new @Sx.Field {options: [{label:"test", value: "text"}], type: "list-multi" }).options)
294
+ .toEqual [new @Sx.Option {label: "test", value: "text"} ]
295
+
296
+ it "can't have options if the type isn't 'list-single' or 'list-multi'" , ->
297
+ opt = [ new @Sx.Option { label:"foo", value: "bar"} ]
298
+ (expect (new @Sx.Field).options).toEqual []
299
+ (expect (new @Sx.Field {options: opt, type: "text-single" }).options).toEqual []
300
+
301
+ it "provides a function to add a value", ->
302
+ f = new @Sx.Field {value: "a" }
303
+ (expect f.addValue("foo").values).toEqual ["a","foo"]
304
+
305
+ it "provides a function to add one option", ->
306
+ f = new @Sx.Field {type: "list-multi"}
307
+ (expect f.addOption({ label: "foo", value: "bar" }).options)
308
+ .toEqual [new @Sx.Option {label: "foo", value: "bar" }]
309
+
310
+ f = new @Sx.Field {type: "text-single"}
311
+ (expect f.addOption({ label: "foo", value: "bar" }).options).toEqual []
312
+
313
+ it "provides a function to add multiple options", ->
314
+ f = new @Sx.Field { type: "list-multi", options: ["a"] }
315
+ (expect f.addOptions(["b","c"]).options)
316
+ .toEqual [
317
+ new @Sx.Option {value: "a"}
318
+ new @Sx.Option {value: "b"}
319
+ new @Sx.Option {value: "c"}
320
+ ]
321
+ f = new @Sx.Field { type: "list-multi" }
322
+
323
+ (expect f.addOptions([
324
+ {label: "a", value: "a"}
325
+ {label: "b", value: "b"}
326
+ ]).options)
327
+ .toEqual [
328
+ new @Sx.Option {label: "a", value: "a"}
329
+ new @Sx.Option {label: "b", value: "b"}
330
+ ]
331
+
332
+ it "can be convertet into an XML object", ->
333
+ o = new @Sx.Field
334
+ type: "list-multi"
335
+ var: "bar"
336
+ label: "myLabel"
337
+ desc: "foo"
338
+ required: true
339
+ values: ["a", 1, false]
340
+ options: [{label:"foo", value: "bar"},{label:"test", value: 321 }]
341
+
342
+ xml = o.toXML()
343
+
344
+ (expect xml.nodeName).toEqual "field"
345
+ (expect xml.getAttribute "label" ).toEqual "myLabel"
346
+ (expect xml.getAttribute "type" ).toEqual "list-multi"
347
+ (expect xml.getAttribute "var" ).toEqual "bar"
348
+ (expect xml.childNodes[0].nodeName).toEqual "desc"
349
+ (expect xml.childNodes[0].textContent).toEqual "foo"
350
+ (expect xml.childNodes[1].nodeName).toEqual "required"
351
+
352
+ it "can be convertet into a JSON object", ->
353
+ f1 = new @Sx.Field
354
+ type: "list-multi"
355
+ var: "bar"
356
+ label: "myLabel"
357
+ desc: "foo"
358
+ required: 123
359
+ values: ["a", 1, false]
360
+
361
+ f2 = new @Sx.Field
362
+ var: "bar"
363
+ required: true
364
+ value: "a"
365
+
366
+ f3 = new @Sx.Field
367
+ var: "bar"
368
+ values: ["a"]
369
+
370
+ (expect f1.toJSON()).toEqual
371
+ type: "list-multi"
372
+ var: "bar"
373
+ label: "myLabel"
374
+ desc: "foo"
375
+ required: false
376
+ values: ["a", "1", "false"]
377
+ options: []
378
+
379
+ (expect f2.toJSON()).toEqual
380
+ type: "text-single"
381
+ var: "bar"
382
+ required: true
383
+ values: ["a"]
384
+ options: []
385
+
386
+ (expect f3.toJSON()).toEqual
387
+ type: "text-single"
388
+ var: "bar"
389
+ required: false
390
+ values: ["a"]
391
+ options: []
392
+
393
+ describe "conversion to HTML", ->
394
+
395
+ beforeEach ->
396
+ @f = new @Sx.Field { var: "bar" }
397
+
398
+ it "uses sets the variable as the name property", ->
399
+ html = @f.toHTML()
400
+ (expect html.getAttribute "name").toEqual "bar"
401
+
402
+ it "sets the required property", ->
403
+ @f.required = true
404
+ html = @f.toHTML()
405
+ (expect html.getAttribute "required").toEqual "required"
406
+
407
+ it "sets the description as placeholder property", ->
408
+ @f.desc = "your name"
409
+ @f.type = "text-single"
410
+ html = @f.toHTML()
411
+ (expect html.getAttribute "placeholder").toEqual "your name"
412
+
413
+ it "converts to a single selection", ->
414
+
415
+ @f.type = "list-single"
416
+ @f.addValue 1
417
+ @f.addOptions ["a", 1, false]
418
+
419
+ html = @f.toHTML()
420
+ (expect html.nodeName.toLowerCase()).toEqual "select"
421
+ (expect html.getAttribute "multiple").toEqual null
422
+ (expect ($ html).children().length).toEqual 3
423
+ (expect ($ "option:selected", html).val() ).toEqual "1"
424
+
425
+ it "converts to a multiple selection", ->
426
+
427
+ @f.type = "list-multi"
428
+ @f.addValues [1, false]
429
+ @f.addOptions ["a", 1, false]
430
+
431
+ html = @f.toHTML()
432
+ (expect html.nodeName.toLowerCase()).toEqual "select"
433
+ (expect html.getAttribute "multiple").toEqual "multiple"
434
+ (expect ($ "option:selected", html).length ).toEqual 2
435
+
436
+ it "converts a boolean field to a checkbox", ->
437
+ @f.type = "boolean"
438
+ @f.addValue { note: "i'm not a valid value for boolean fields" }
439
+ html = @f.toHTML()
440
+ (expect html.nodeName.toLowerCase()).toEqual "input"
441
+ (expect html.getAttribute "type").toEqual "checkbox"
442
+ (expect html.getAttribute "checked").toEqual null
443
+
444
+ it "sets the checked property if the value is 'true'", ->
445
+ @f.type = "boolean"
446
+ @f.addValue true
447
+ (expect @f.toHTML().getAttribute "checked").toEqual "checked"
448
+
449
+ it "sets the checked property if the value is '1'", ->
450
+ @f.type = "boolean"
451
+ @f.addValue 1
452
+ (expect @f.toHTML().getAttribute "checked").toEqual "checked"
453
+
454
+ it "sets the checked property if the value is '1'", ->
455
+ @f.type = "boolean"
456
+ @f.addValue 1
457
+ (expect @f.toHTML().getAttribute "checked").toEqual "checked"
458
+
459
+ it "converts 'text-multi' to a textarea", ->
460
+ @f.type = "text-multi"
461
+ @f.addValues ["This is a multi","line text"]
462
+ html = @f.toHTML()
463
+ (expect html.nodeName).toEqual "TEXTAREA"
464
+ (expect ($ html).text()).toEqual "This is a multi\nline text"
465
+
466
+ it "converts 'jid-multi' to a textarea", ->
467
+ @f.type = "text-multi"
468
+ @f.addValues ["myjid@domain.tld/resource","yourjid@domain.tld"]
469
+ html = @f.toHTML()
470
+ (expect html.nodeName).toEqual "TEXTAREA"
471
+ (expect ($ html).text()).toEqual "myjid@domain.tld/resource\nyourjid@domain.tld"
472
+
473
+ it "converts 'text-private' to a password input field", ->
474
+ @f.type = "text-private"
475
+ html = @f.toHTML()
476
+ (expect html.nodeName).toEqual "INPUT"
477
+ (expect html.getAttribute "type").toEqual "password"
478
+
479
+ it "converts 'hidden' to a hidden input field", ->
480
+ @f.type = "hidden"
481
+ html = @f.toHTML()
482
+ (expect html.nodeName).toEqual "INPUT"
483
+ (expect html.getAttribute "type").toEqual "hidden"
484
+
485
+ it "converts 'fixed' to a read-only input field", ->
486
+ @f.type = "fixed"
487
+ html = @f.toHTML()
488
+ (expect html.nodeName).toEqual "INPUT"
489
+ (expect html.getAttribute "type").toEqual "text"
490
+ (expect html.getAttribute "readonly").toEqual "readonly"
491
+
492
+ it "converts 'jid-single' to an email input field", ->
493
+ @f.type = "jid-single"
494
+ html = @f.toHTML()
495
+ (expect html.nodeName).toEqual "INPUT"
496
+ (expect html.getAttribute "type").toEqual "email"
497
+
498
+ it "can be created by an xml element", ->
499
+ xml = $build("field",{ type:"list-single", label: "News", var: "news" })
500
+ .c("desc").t("My desc").up()
501
+ .c("required").up()
502
+ .c("value").t("blue").up()
503
+ .c("option",{label: "RED" }).t("red").up()
504
+ .c("option",{label: "BLUE"}).t("blue").up()
505
+ .c("option",{label: "YELLOW"}).t("yellow").up()
506
+ .tree()
507
+ field = @Sx.Field.fromXML xml
508
+
509
+ (expect field.type).toEqual "list-single"
510
+ (expect field.var).toEqual "news"
511
+ (expect field.label).toEqual "News"
512
+ (expect field.desc).toEqual "My desc"
513
+ (expect field.required).toEqual true
514
+ (expect field.values).toEqual ["blue"]
515
+ (expect field.options).toEqual [
516
+ new @Sx.Option { label: "RED", value: "red"}
517
+ new @Sx.Option { label: "BLUE", value: "blue"}
518
+ new @Sx.Option { label: "YELLOW", value: "yellow"}
519
+ ]
520
+
521
+ f1 = new @Sx.Field
522
+ type: "list-multi"
523
+ var: "bar"
524
+ label: "myLabel"
525
+ desc: "foo"
526
+ required: false
527
+ values: ["a",false]
528
+ option: ["a", 1, false]
529
+
530
+ (expect @Sx.Field.fromXML( f1.toXML()).toJSON() ).toEqual f1.toJSON()
531
+
532
+ describe "parsing HTML", ->
533
+
534
+ it "detects the correct field type", ->
535
+
536
+ html = $ "<select>"
537
+ (expect @Sx.Field.fromHTML(html).type).toEqual "list-single"
538
+
539
+ html = $ "<select multiple='multiple'>"
540
+ (expect @Sx.Field.fromHTML(html).type).toEqual "list-multi"
541
+
542
+ html = $ "<textarea>"
543
+ (expect @Sx.Field.fromHTML(html).type).toEqual "text-multi"
544
+
545
+ html = $ "<input>"
546
+ (expect @Sx.Field.fromHTML(html).type).toEqual "text-single"
547
+
548
+ html = $ "<input type='email'>"
549
+ (expect @Sx.Field.fromHTML(html).type).toEqual "jid-single"
550
+
551
+ html = $ "<input type='hidden'>"
552
+ (expect @Sx.Field.fromHTML(html).type).toEqual "hidden"
553
+
554
+ html = $ "<input type='password'>"
555
+ (expect @Sx.Field.fromHTML(html).type).toEqual "text-private"
556
+
557
+ html = $ "<input type='text'>"
558
+ (expect @Sx.Field.fromHTML(html).type).toEqual "text-single"
559
+
560
+ html = $ "<input type='checkbox'>"
561
+ (expect @Sx.Field.fromHTML(html).type).toEqual "boolean"
562
+
563
+ it "parses the properties", ->
564
+
565
+ html = $ """<select name ='news' required='required'>
566
+ <option value="red">RED</option>
567
+ <option value="blue" selected='selected'>BLUE</option>
568
+ <option value="yellow">YELLOW</option>"""
569
+
570
+ field = @Sx.Field.fromHTML html
571
+
572
+ (expect field.var).toEqual "news"
573
+ (expect field.required).toEqual true
574
+ (expect field.values).toEqual ["blue"]
575
+ (expect field.options).toEqual [
576
+ new @Sx.Option { label: "RED", value: "red"}
577
+ new @Sx.Option { label: "BLUE", value: "blue"}
578
+ new @Sx.Option { label: "YELLOW", value: "yellow"}
579
+ ]
580
+
581
+ html = $ """<select name ='news' multiple='multiple'>
582
+ <option value="red" selected='selected'>RED</option>
583
+ <option value="blue" selected='selected'>BLUE</option>
584
+ <option value="yellow">YELLOW</option>"""
585
+
586
+ field = @Sx.Field.fromHTML html
587
+
588
+ (expect field.values).toEqual ["red","blue"]
589
+
590
+ it "parses the textarea text", ->
591
+
592
+ l1 = "Hello world!"
593
+ l2 = "A new line"
594
+ html = $ "<textarea>#{l1}\n#{l2}</textarea>"
595
+
596
+ field = @Sx.Field.fromHTML html
597
+
598
+ (expect field.values).toEqual [ l1,l2 ]
599
+
600
+ it "parses the textfield text", ->
601
+
602
+ text = "Hello world!"
603
+ html = $ "<input type='text' value='#{text}' >"
604
+
605
+ field = @Sx.Field.fromHTML html
606
+
607
+ (expect field.values).toEqual [ text ]
608
+
609
+ describe "Option", ->
610
+
611
+ it "has a label attribute", ->
612
+ (expect typeof (new @Sx.Option {label:"foo"})).toEqual "object"
613
+ (expect (new @Sx.Option {label:"foo"}).label).toEqual "foo"
614
+ (expect (new @Sx.Option).label).toEqual ""
615
+
616
+ it "has a value", ->
617
+ (expect (new @Sx.Option {value:"foo"}).value).toEqual "foo"
618
+ (expect (new @Sx.Option).value).toEqual ""
619
+
620
+ it "can be convertet into an XML object", ->
621
+ o = new @Sx.Option
622
+ label: "foo"
623
+ value: 123
624
+
625
+ xml = o.toXML()
626
+
627
+ (expect xml.nodeName).toEqual "option"
628
+ (expect xml.getAttribute "label" ).toEqual "foo"
629
+ (expect xml.childNodes[0].nodeName).toEqual "value"
630
+ (expect xml.childNodes[0].textContent).toEqual "123"
631
+
632
+ it "can be convertet into a JSON object", ->
633
+ o = new @Sx.Option
634
+ label: "foo"
635
+ value: 123
636
+
637
+ json = o.toJSON()
638
+ (expect json.label).toEqual "foo"
639
+ (expect json.value).toEqual "123"
640
+
641
+ it "can be convertet into a HTML option object", ->
642
+ o1 = new @Sx.Option { label: "foo", value: 123 }
643
+ o2 = new @Sx.Option { value: 123 }
644
+
645
+ o1html = o1.toHTML()
646
+ o2html = o2.toHTML()
647
+ (expect o1html.nodeName.toLowerCase()).toEqual "option"
648
+ (expect o1html.getAttribute "value").toEqual "123"
649
+ (expect o1html.textContent).toEqual "foo"
650
+ (expect o2html.textContent).toEqual "123"
651
+
652
+ it "can be created by an xml element", ->
653
+ xml = $build("option",{ label:"news"}).c("value").t("Great news").tree()
654
+ option = @Sx.Option.fromXML xml
655
+
656
+ (expect option.label).toEqual "news"
657
+ (expect option.value).toEqual "Great news"
658
+
659
+ o = new @Sx.Option { label: "foo", value: 123 }
660
+
661
+ (expect @Sx.Option.fromXML( o.toXML()).toJSON()).toEqual o.toJSON()
662
+
663
+ it "can be parsed from HTML", ->
664
+
665
+ html = $ "<option value='news'>Great news</option>"
666
+ option = @Sx.Option.fromHTML html
667
+
668
+ (expect option.value).toEqual "news"
669
+ (expect option.label).toEqual "Great news"
670
+
671
+ o = new @Sx.Option { label: "foo", value: 123 }
672
+
673
+ (expect @Sx.Option.fromHTML( o.toHTML()).toJSON()).toEqual o.toJSON()
674
+
675
+
676
+ describe "Item", ->
677
+
678
+ it "can have multiple fields", ->
679
+ f1 = new @Sx.Field
680
+ f2 = {type: "list-multi", required:"true", var:"foo"}
681
+
682
+ (expect (new @Sx.Item).fields).toEqual []
683
+ (expect (new @Sx.Item {fields: [f1,f2]}).fields).toEqual [f1, new @Sx.Field f2]
684
+
685
+ it "can be convertet into an XML object", ->
686
+
687
+ o = new @Sx.Item {fields: [ new @Sx.Field, {type: "list-multi", required:"true", var:"foo"} ] }
688
+ xml = o.toXML()
689
+
690
+ (expect xml.nodeName).toEqual "item"
691
+ (expect xml.childNodes[0].nodeName).toEqual "field"
692
+
693
+ it "can be convertet into a JSON object", ->
694
+ f1 = new @Sx.Field
695
+ f2 = {type: "list-multi", required: "true" , var:"foo"}
696
+ o = new @Sx.Item { fields: [ f1,f2 ] }
697
+
698
+ json = o.toJSON()
699
+ (expect json.fields).toEqual [f1.toJSON(),{type: "list-multi", required: true , var:"foo", values:[], options: []}]
700
+
701
+ it "can be created from XML", ->
702
+
703
+ f1 = new @Sx.Field
704
+ f2 = {type: "list-multi", required: "true" , var:"foo"}
705
+ o = new @Sx.Item { fields: [ f1,f2 ] }
706
+
707
+ (expect @Sx.Item.fromXML( o.toXML() ).toJSON() ).toEqual o.toJSON()
708
+
709
+ it "can be created from HTML", ->
710
+
711
+ f1 = new @Sx.Field
712
+ f2 = {type: "list-multi", required: "true" , var:"foo"}
713
+ o = new @Sx.Item { fields: [ f1,f2 ] }
714
+
715
+ (expect @Sx.Item.fromHTML( o.toHTML() ).toJSON() ).toEqual o.toJSON()