Commit 8934043d authored by Guillermo Bonvehí's avatar Guillermo Bonvehí

Submit registration form as xform or legacy

Support to send the registration form as legacy or xform, we
use the same variable form_type that was already being used when
calling render
Added submission tests
parent b08776a1
......@@ -5060,11 +5060,19 @@
var $inputs = $(ev.target).find(':input:not([type=button]):not([type=submit])'),
iq = $iq({type: "set"})
.c("query", {xmlns:Strophe.NS.REGISTER})
.c("x", {xmlns: Strophe.NS.XFORM, type: 'submit'});
if (this.form_type == 'xform') {
iq.c("x", {xmlns: Strophe.NS.XFORM, type: 'submit'});
$inputs.each(function () {
iq.cnode(utils.webForm2xForm(this)).up();
});
} else {
$inputs.each(function () {
var $input = $(this);
iq.c($input.attr('name'), {}, $input.val());
});
}
converse.connection._addSysHandler(this._onRegisterIQ.bind(this), null, "iq", null, null);
converse.connection.send(iq);
this.setFields(iq.tree());
......
......@@ -160,7 +160,7 @@
expect(registerview.$('input[type=button]').length).toBe(1);
}, converse));
it("will set form_type to legacy", $.proxy(function () {
it("will set form_type to legacy and submit it as legacy", $.proxy(function () {
var cbview = this.chatboxviews.get('controlbox');
cbview.$('#controlbox-tabs').find('li').last().find('a').click(); // Click the Register tab
var registerview = this.chatboxviews.get('controlbox').registerpanel;
......@@ -192,9 +192,22 @@
.c('email');
this.connection._dataRecv(test_utils.createRequest(stanza));
expect(registerview.form_type).toBe('legacy');
registerview.$('input[name=username]').val('testusername');
registerview.$('input[name=password]').val('testpassword');
registerview.$('input[name=email]').val('test@email.local');
spyOn(converse.connection, 'send');
registerview.$('input[type=submit]').click();
expect(converse.connection.send).toHaveBeenCalled();
var $stanza = $(converse.connection.send.argsForCall[0][0].tree());
expect($stanza.children('query').children().length).toBe(3);
expect($stanza.children('query').children()[0].tagName).toBe('username');
}, converse));
it("will set form_type to xform", $.proxy(function () {
it("will set form_type to xform and submit it as xform", $.proxy(function () {
var cbview = this.chatboxviews.get('controlbox');
cbview.$('#controlbox-tabs').find('li').last().find('a').click(); // Click the Register tab
var registerview = this.chatboxviews.get('controlbox').registerpanel;
......@@ -228,6 +241,20 @@
.c('field', {'type': 'text-single', 'var': 'email'}).c('required').up().up()
this.connection._dataRecv(test_utils.createRequest(stanza));
expect(registerview.form_type).toBe('xform');
registerview.$('input[name=username]').val('testusername');
registerview.$('input[name=password]').val('testpassword');
registerview.$('input[name=email]').val('test@email.local');
spyOn(converse.connection, 'send');
registerview.$('input[type=submit]').click();
expect(converse.connection.send).toHaveBeenCalled();
var $stanza = $(converse.connection.send.argsForCall[0][0].tree());
expect($stanza.children('query').children().length).toBe(1);
expect($stanza.children('query').children().children().length).toBe(3);
expect($stanza.children('query').children().children()[0].tagName).toBe('field');
}, converse));
}, converse, mock, test_utils));
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment