2014-11-27 10:42:27 +01:00
|
|
|
(function (root, factory) {
|
2017-07-11 10:41:11 +02:00
|
|
|
define(["jquery.noconflict", "jasmine", "mock", "converse-core", "test-utils"], factory);
|
|
|
|
} (this, function ($, jasmine, mock, converse, test_utils) {
|
2016-12-20 10:30:20 +01:00
|
|
|
var Strophe = converse.env.Strophe;
|
|
|
|
var $iq = converse.env.$iq;
|
2017-08-16 12:31:17 +02:00
|
|
|
var _ = converse.env._;
|
2014-11-27 10:42:27 +01:00
|
|
|
|
2016-04-13 17:11:04 +02:00
|
|
|
describe("The Registration Panel", function () {
|
|
|
|
|
2017-08-16 12:31:17 +02:00
|
|
|
it("is not available unless allow_registration=true",
|
|
|
|
mock.initConverseWithPromises(
|
|
|
|
null, ['connectionInitialized', 'chatBoxesInitialized'],
|
|
|
|
{ auto_login: false,
|
|
|
|
allow_registration: false },
|
|
|
|
function (done, _converse) {
|
|
|
|
|
|
|
|
test_utils.waitUntil(function () {
|
|
|
|
return _converse.chatboxviews.get('controlbox');
|
|
|
|
}, 300)
|
|
|
|
.then(function () {
|
|
|
|
|
2017-04-05 11:01:31 +02:00
|
|
|
test_utils.openControlBox();
|
|
|
|
var cbview = _converse.chatboxviews.get('controlbox');
|
|
|
|
expect(cbview.$('#controlbox-tabs li').length).toBe(1);
|
|
|
|
expect(cbview.$('#controlbox-tabs li').text().trim()).toBe("Sign in");
|
2017-08-16 12:31:17 +02:00
|
|
|
done();
|
|
|
|
});
|
2017-04-05 11:01:31 +02:00
|
|
|
}));
|
2016-11-03 11:01:09 +01:00
|
|
|
|
2017-08-16 12:31:17 +02:00
|
|
|
it("can be opened by clicking on the registration tab",
|
|
|
|
mock.initConverseWithPromises(
|
|
|
|
null, ['connectionInitialized', 'chatBoxesInitialized'],
|
|
|
|
{ auto_login: false,
|
|
|
|
allow_registration: true },
|
|
|
|
function (done, _converse) {
|
|
|
|
|
|
|
|
test_utils.waitUntil(function () {
|
|
|
|
return _.get(_converse.chatboxviews.get('controlbox'), 'registerpanel');
|
|
|
|
}, 300)
|
|
|
|
.then(function () {
|
|
|
|
|
2016-12-20 10:30:20 +01:00
|
|
|
var cbview = _converse.chatboxviews.get('controlbox');
|
2017-04-05 11:01:31 +02:00
|
|
|
test_utils.openControlBox();
|
|
|
|
var $tabs = cbview.$('#controlbox-tabs');
|
|
|
|
var $panels = cbview.$('.controlbox-panes');
|
|
|
|
var $login = $panels.children().first();
|
|
|
|
var $registration = $panels.children().last();
|
|
|
|
expect($tabs.find('li').first().text()).toBe('Sign in');
|
|
|
|
expect($tabs.find('li').last().text()).toBe('Register');
|
|
|
|
|
|
|
|
spyOn(cbview, 'switchTab').and.callThrough();
|
|
|
|
cbview.delegateEvents(); // We need to rebind all events otherwise our spy won't be called
|
|
|
|
$tabs.find('li').last().find('a').click(); // Click the Register tab
|
|
|
|
expect($login.is(':visible')).toBe(false);
|
|
|
|
expect($registration.is(':visible')).toBe(true);
|
|
|
|
expect(cbview.switchTab).toHaveBeenCalled();
|
2017-08-16 12:31:17 +02:00
|
|
|
done();
|
|
|
|
});
|
2017-04-05 11:01:31 +02:00
|
|
|
}));
|
2016-11-03 11:01:09 +01:00
|
|
|
|
2017-08-16 12:31:17 +02:00
|
|
|
it("allows the user to choose an XMPP provider's domain",
|
|
|
|
mock.initConverseWithPromises(
|
|
|
|
null, ['connectionInitialized', 'chatBoxesInitialized'],
|
|
|
|
{ auto_login: false,
|
|
|
|
allow_registration: true },
|
|
|
|
function (done, _converse) {
|
|
|
|
|
|
|
|
test_utils.waitUntil(function () {
|
|
|
|
return _.get(_converse.chatboxviews.get('controlbox'), 'registerpanel');
|
|
|
|
}, 300)
|
|
|
|
.then(function () {
|
|
|
|
|
2016-12-20 10:30:20 +01:00
|
|
|
var cbview = _converse.chatboxviews.get('controlbox');
|
2016-11-03 11:01:09 +01:00
|
|
|
var registerview = cbview.registerpanel;
|
2017-04-05 11:01:31 +02:00
|
|
|
spyOn(registerview, 'onProviderChosen').and.callThrough();
|
2016-11-03 11:01:09 +01:00
|
|
|
registerview.delegateEvents(); // We need to rebind all events otherwise our spy won't be called
|
2016-12-20 10:30:20 +01:00
|
|
|
spyOn(_converse.connection, 'connect');
|
2016-11-03 11:01:09 +01:00
|
|
|
var $tabs = cbview.$('#controlbox-tabs');
|
|
|
|
$tabs.find('li').last().find('a').click(); // Click the Register tab
|
|
|
|
// Check the form layout
|
|
|
|
var $form = cbview.$('#converse-register');
|
|
|
|
expect($form.find('input').length).toEqual(2);
|
|
|
|
expect($form.find('input').first().attr('name')).toEqual('domain');
|
|
|
|
expect($form.find('input').last().attr('type')).toEqual('submit');
|
|
|
|
// Check that the input[type=domain] input is required
|
|
|
|
$form.find('input[type=submit]').click();
|
|
|
|
expect(registerview.onProviderChosen).toHaveBeenCalled();
|
|
|
|
expect($form.find('input[name=domain]').hasClass('error')).toBeTruthy();
|
|
|
|
// Check that the form is accepted if input[type=domain] has a value
|
|
|
|
$form.find('input[name=domain]').val('conversejs.org');
|
|
|
|
$form.find('input[type=submit]').click();
|
|
|
|
expect(registerview.onProviderChosen).toHaveBeenCalled();
|
2016-12-20 10:30:20 +01:00
|
|
|
expect(_converse.connection.connect).toHaveBeenCalled();
|
2017-08-16 12:31:17 +02:00
|
|
|
done();
|
|
|
|
});
|
|
|
|
}));
|
|
|
|
|
|
|
|
it("will render a registration form as received from the XMPP provider",
|
|
|
|
mock.initConverseWithPromises(
|
|
|
|
null, ['connectionInitialized', 'chatBoxesInitialized'],
|
|
|
|
{ auto_login: false,
|
|
|
|
allow_registration: true },
|
|
|
|
function (done, _converse) {
|
|
|
|
|
|
|
|
test_utils.waitUntil(function () {
|
|
|
|
return _.get(_converse.chatboxviews.get('controlbox'), 'registerpanel');
|
|
|
|
}, 300)
|
|
|
|
.then(function () {
|
2016-11-03 11:01:09 +01:00
|
|
|
|
2016-12-20 10:30:20 +01:00
|
|
|
var cbview = _converse.chatboxviews.get('controlbox');
|
2016-11-03 11:01:09 +01:00
|
|
|
cbview.$('#controlbox-tabs').find('li').last().find('a').click(); // Click the Register tab
|
2016-12-20 10:30:20 +01:00
|
|
|
var registerview = _converse.chatboxviews.get('controlbox').registerpanel;
|
2017-04-05 11:01:31 +02:00
|
|
|
spyOn(registerview, 'onProviderChosen').and.callThrough();
|
|
|
|
spyOn(registerview, 'getRegistrationFields').and.callThrough();
|
|
|
|
spyOn(registerview, 'onRegistrationFields').and.callThrough();
|
|
|
|
spyOn(registerview, 'renderRegistrationForm').and.callThrough();
|
2016-11-03 11:01:09 +01:00
|
|
|
registerview.delegateEvents(); // We need to rebind all events otherwise our spy won't be called
|
2017-04-05 11:01:31 +02:00
|
|
|
spyOn(_converse.connection, 'connect').and.callThrough();
|
2016-11-03 11:01:09 +01:00
|
|
|
|
|
|
|
expect(registerview._registering).toBeFalsy();
|
2016-12-20 10:30:20 +01:00
|
|
|
expect(_converse.connection.connected).toBeFalsy();
|
2016-11-03 11:01:09 +01:00
|
|
|
registerview.$('input[name=domain]').val('conversejs.org');
|
|
|
|
registerview.$('input[type=submit]').click();
|
|
|
|
expect(registerview.onProviderChosen).toHaveBeenCalled();
|
|
|
|
expect(registerview._registering).toBeTruthy();
|
2016-12-20 10:30:20 +01:00
|
|
|
expect(_converse.connection.connect).toHaveBeenCalled();
|
2016-11-03 11:01:09 +01:00
|
|
|
|
|
|
|
var stanza = new Strophe.Builder("stream:features", {
|
|
|
|
'xmlns:stream': "http://etherx.jabber.org/streams",
|
|
|
|
'xmlns': "jabber:client"
|
|
|
|
})
|
|
|
|
.c('register', {xmlns: "http://jabber.org/features/iq-register"}).up()
|
|
|
|
.c('mechanisms', {xmlns: "urn:ietf:params:xml:ns:xmpp-sasl"});
|
2016-12-20 10:30:20 +01:00
|
|
|
_converse.connection._connect_cb(test_utils.createRequest(stanza));
|
2016-11-03 11:01:09 +01:00
|
|
|
|
|
|
|
expect(registerview.getRegistrationFields).toHaveBeenCalled();
|
|
|
|
|
|
|
|
stanza = $iq({
|
|
|
|
'type': 'result',
|
|
|
|
'id': 'reg1'
|
|
|
|
}).c('query', {'xmlns': 'jabber:iq:register'})
|
|
|
|
.c('instructions')
|
|
|
|
.t('Please choose a username, password and provide your email address').up()
|
|
|
|
.c('username').up()
|
|
|
|
.c('password').up()
|
|
|
|
.c('email');
|
2016-12-20 10:30:20 +01:00
|
|
|
_converse.connection._dataRecv(test_utils.createRequest(stanza));
|
2016-11-03 11:01:09 +01:00
|
|
|
expect(registerview.onRegistrationFields).toHaveBeenCalled();
|
|
|
|
expect(registerview.renderRegistrationForm).toHaveBeenCalled();
|
|
|
|
expect(registerview.$('input').length).toBe(5);
|
|
|
|
expect(registerview.$('input[type=submit]').length).toBe(1);
|
|
|
|
expect(registerview.$('input[type=button]').length).toBe(1);
|
2017-08-16 12:31:17 +02:00
|
|
|
done();
|
|
|
|
});
|
|
|
|
}));
|
|
|
|
|
|
|
|
it("will set form_type to legacy and submit it as legacy",
|
|
|
|
mock.initConverseWithPromises(
|
|
|
|
null, ['connectionInitialized', 'chatBoxesInitialized'],
|
|
|
|
{ auto_login: false,
|
|
|
|
allow_registration: true },
|
|
|
|
function (done, _converse) {
|
|
|
|
|
|
|
|
test_utils.waitUntil(function () {
|
|
|
|
return _.get(_converse.chatboxviews.get('controlbox'), 'registerpanel');
|
|
|
|
}, 300)
|
|
|
|
.then(function () {
|
2016-11-03 11:01:09 +01:00
|
|
|
|
2016-12-20 10:30:20 +01:00
|
|
|
var cbview = _converse.chatboxviews.get('controlbox');
|
2016-11-03 11:01:09 +01:00
|
|
|
cbview.$('#controlbox-tabs').find('li').last().find('a').click(); // Click the Register tab
|
2017-08-16 12:31:17 +02:00
|
|
|
var registerview = cbview.registerpanel;
|
2017-04-05 11:01:31 +02:00
|
|
|
spyOn(registerview, 'onProviderChosen').and.callThrough();
|
|
|
|
spyOn(registerview, 'getRegistrationFields').and.callThrough();
|
|
|
|
spyOn(registerview, 'onRegistrationFields').and.callThrough();
|
|
|
|
spyOn(registerview, 'renderRegistrationForm').and.callThrough();
|
2016-11-03 11:01:09 +01:00
|
|
|
registerview.delegateEvents(); // We need to rebind all events otherwise our spy won't be called
|
2017-04-05 11:01:31 +02:00
|
|
|
spyOn(_converse.connection, 'connect').and.callThrough();
|
2016-11-03 11:01:09 +01:00
|
|
|
|
|
|
|
registerview.$('input[name=domain]').val('conversejs.org');
|
|
|
|
registerview.$('input[type=submit]').click();
|
|
|
|
|
|
|
|
var stanza = new Strophe.Builder("stream:features", {
|
|
|
|
'xmlns:stream': "http://etherx.jabber.org/streams",
|
|
|
|
'xmlns': "jabber:client"
|
|
|
|
})
|
|
|
|
.c('register', {xmlns: "http://jabber.org/features/iq-register"}).up()
|
|
|
|
.c('mechanisms', {xmlns: "urn:ietf:params:xml:ns:xmpp-sasl"});
|
2016-12-20 10:30:20 +01:00
|
|
|
_converse.connection._connect_cb(test_utils.createRequest(stanza));
|
2016-11-03 11:01:09 +01:00
|
|
|
stanza = $iq({
|
|
|
|
'type': 'result',
|
|
|
|
'id': 'reg1'
|
|
|
|
}).c('query', {'xmlns': 'jabber:iq:register'})
|
|
|
|
.c('instructions')
|
|
|
|
.t('Please choose a username, password and provide your email address').up()
|
|
|
|
.c('username').up()
|
|
|
|
.c('password').up()
|
|
|
|
.c('email');
|
2016-12-20 10:30:20 +01:00
|
|
|
_converse.connection._dataRecv(test_utils.createRequest(stanza));
|
2016-11-03 11:01:09 +01:00
|
|
|
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');
|
|
|
|
|
2016-12-20 10:30:20 +01:00
|
|
|
spyOn(_converse.connection, 'send');
|
2016-11-03 11:01:09 +01:00
|
|
|
|
|
|
|
registerview.$('input[type=submit]').click();
|
|
|
|
|
2016-12-20 10:30:20 +01:00
|
|
|
expect(_converse.connection.send).toHaveBeenCalled();
|
2017-04-05 11:01:31 +02:00
|
|
|
var $stanza = $(_converse.connection.send.calls.argsFor(0)[0].tree());
|
2016-11-03 11:01:09 +01:00
|
|
|
expect($stanza.children('query').children().length).toBe(3);
|
|
|
|
expect($stanza.children('query').children()[0].tagName).toBe('username');
|
2017-08-16 12:31:17 +02:00
|
|
|
done();
|
|
|
|
});
|
|
|
|
}));
|
|
|
|
|
|
|
|
it("will set form_type to xform and submit it as xform",
|
|
|
|
mock.initConverseWithPromises(
|
|
|
|
null, ['connectionInitialized', 'chatBoxesInitialized'],
|
|
|
|
{ auto_login: false,
|
|
|
|
allow_registration: true },
|
|
|
|
function (done, _converse) {
|
|
|
|
|
|
|
|
test_utils.waitUntil(function () {
|
|
|
|
return _.get(_converse.chatboxviews.get('controlbox'), 'registerpanel');
|
|
|
|
}, 300)
|
|
|
|
.then(function () {
|
2016-11-03 11:01:09 +01:00
|
|
|
|
2016-12-20 10:30:20 +01:00
|
|
|
var cbview = _converse.chatboxviews.get('controlbox');
|
2016-11-03 11:01:09 +01:00
|
|
|
cbview.$('#controlbox-tabs').find('li').last().find('a').click(); // Click the Register tab
|
2016-12-20 10:30:20 +01:00
|
|
|
var registerview = _converse.chatboxviews.get('controlbox').registerpanel;
|
2017-04-05 11:01:31 +02:00
|
|
|
spyOn(registerview, 'onProviderChosen').and.callThrough();
|
|
|
|
spyOn(registerview, 'getRegistrationFields').and.callThrough();
|
|
|
|
spyOn(registerview, 'onRegistrationFields').and.callThrough();
|
|
|
|
spyOn(registerview, 'renderRegistrationForm').and.callThrough();
|
2016-11-03 11:01:09 +01:00
|
|
|
registerview.delegateEvents(); // We need to rebind all events otherwise our spy won't be called
|
2017-04-05 11:01:31 +02:00
|
|
|
spyOn(_converse.connection, 'connect').and.callThrough();
|
2016-11-03 11:01:09 +01:00
|
|
|
|
|
|
|
registerview.$('input[name=domain]').val('conversejs.org');
|
|
|
|
registerview.$('input[type=submit]').click();
|
|
|
|
|
|
|
|
var stanza = new Strophe.Builder("stream:features", {
|
|
|
|
'xmlns:stream': "http://etherx.jabber.org/streams",
|
|
|
|
'xmlns': "jabber:client"
|
|
|
|
})
|
|
|
|
.c('register', {xmlns: "http://jabber.org/features/iq-register"}).up()
|
|
|
|
.c('mechanisms', {xmlns: "urn:ietf:params:xml:ns:xmpp-sasl"});
|
2016-12-20 10:30:20 +01:00
|
|
|
_converse.connection._connect_cb(test_utils.createRequest(stanza));
|
2016-11-03 11:01:09 +01:00
|
|
|
stanza = $iq({
|
|
|
|
'type': 'result',
|
|
|
|
'id': 'reg1'
|
|
|
|
}).c('query', {'xmlns': 'jabber:iq:register'})
|
|
|
|
.c('instructions')
|
|
|
|
.t('Using xform data').up()
|
|
|
|
.c('x', { 'xmlns': 'jabber:x:data', 'type': 'form' })
|
|
|
|
.c('instructions').t('xform instructions').up()
|
|
|
|
.c('field', {'type': 'text-single', 'var': 'username'}).c('required').up().up()
|
|
|
|
.c('field', {'type': 'text-private', 'var': 'password'}).c('required').up().up()
|
|
|
|
.c('field', {'type': 'text-single', 'var': 'email'}).c('required').up().up();
|
2016-12-20 10:30:20 +01:00
|
|
|
_converse.connection._dataRecv(test_utils.createRequest(stanza));
|
2016-11-03 11:01:09 +01:00
|
|
|
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');
|
|
|
|
|
2016-12-20 10:30:20 +01:00
|
|
|
spyOn(_converse.connection, 'send');
|
2016-11-03 11:01:09 +01:00
|
|
|
|
|
|
|
registerview.$('input[type=submit]').click();
|
|
|
|
|
2016-12-20 10:30:20 +01:00
|
|
|
expect(_converse.connection.send).toHaveBeenCalled();
|
2017-04-05 11:01:31 +02:00
|
|
|
var $stanza = $(_converse.connection.send.calls.argsFor(0)[0].tree());
|
2016-11-03 11:01:09 +01:00
|
|
|
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');
|
2017-08-16 12:31:17 +02:00
|
|
|
done();
|
|
|
|
});
|
|
|
|
}));
|
2016-04-13 17:11:04 +02:00
|
|
|
});
|
2014-11-27 10:42:27 +01:00
|
|
|
}));
|