2014-11-27 10:42:27 +01:00
|
|
|
(function (root, factory) {
|
2018-06-03 16:40:20 +02:00
|
|
|
define(["jquery", "jasmine", "mock", "test-utils"], factory);
|
|
|
|
} (this, function ($, jasmine, mock, 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) {
|
|
|
|
|
2018-05-17 18:25:12 +02:00
|
|
|
test_utils.waitUntil(() => _converse.chatboxviews.get('controlbox'))
|
2017-08-16 12:31:17 +02:00
|
|
|
.then(function () {
|
2018-05-17 18:25:12 +02:00
|
|
|
test_utils.openControlBox();
|
|
|
|
var cbview = _converse.chatboxviews.get('controlbox');
|
|
|
|
expect($(cbview.el.querySelector('a.register-account')).length).toBe(0);
|
|
|
|
done();
|
2017-08-16 12:31:17 +02:00
|
|
|
});
|
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) {
|
|
|
|
|
2018-05-08 19:24:50 +02:00
|
|
|
test_utils.waitUntil(() => _.get(_converse.chatboxviews.get('controlbox'), 'registerpanel'), 300)
|
2017-08-16 12:31:17 +02:00
|
|
|
.then(function () {
|
2018-05-08 19:24:50 +02:00
|
|
|
var cbview = _converse.chatboxviews.get('controlbox');
|
|
|
|
test_utils.openControlBox();
|
|
|
|
var $panels = $(cbview.el.querySelector('.controlbox-panes'));
|
|
|
|
var $login = $panels.children().first();
|
|
|
|
var $registration = $panels.children().last();
|
|
|
|
|
|
|
|
var register_link = cbview.el.querySelector('a.register-account');
|
|
|
|
expect(register_link.textContent).toBe("Create an account");
|
|
|
|
register_link.click();
|
|
|
|
test_utils.waitUntil(function () {
|
|
|
|
return $registration.is(':visible');
|
|
|
|
}, 300).then(function () {
|
|
|
|
expect($login.is(':visible')).toBe(false);
|
|
|
|
done();
|
|
|
|
});
|
2017-08-16 12:31:17 +02:00
|
|
|
});
|
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 () {
|
|
|
|
|
2017-09-25 12:50:13 +02:00
|
|
|
test_utils.openControlBox();
|
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');
|
2017-09-25 12:50:13 +02:00
|
|
|
|
|
|
|
// Open the register panel
|
|
|
|
cbview.el.querySelector('.toggle-register-login').click();
|
|
|
|
|
2016-11-03 11:01:09 +01:00
|
|
|
// Check the form layout
|
2018-01-03 20:02:05 +01:00
|
|
|
var $form = $(cbview.el.querySelector('#converse-register'));
|
2016-11-03 11:01:09 +01:00
|
|
|
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
|
2018-01-03 20:02:05 +01:00
|
|
|
$form.find('input[type=submit]')[0].click();
|
2017-09-25 12:50:13 +02:00
|
|
|
expect(registerview.onProviderChosen).not.toHaveBeenCalled();
|
|
|
|
|
2016-11-03 11:01:09 +01:00
|
|
|
// Check that the form is accepted if input[type=domain] has a value
|
|
|
|
$form.find('input[name=domain]').val('conversejs.org');
|
2018-01-03 20:02:05 +01:00
|
|
|
$form.find('input[type=submit]')[0].click();
|
2016-11-03 11:01:09 +01:00
|
|
|
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');
|
2018-01-03 20:02:05 +01:00
|
|
|
}, 300).then(function () {
|
|
|
|
test_utils.openControlBox();
|
|
|
|
var cbview = _converse.chatboxviews.get('controlbox');
|
|
|
|
cbview.el.querySelector('.toggle-register-login').click();
|
|
|
|
|
|
|
|
var registerview = _converse.chatboxviews.get('controlbox').registerpanel;
|
|
|
|
spyOn(registerview, 'onProviderChosen').and.callThrough();
|
|
|
|
spyOn(registerview, 'getRegistrationFields').and.callThrough();
|
|
|
|
spyOn(registerview, 'onRegistrationFields').and.callThrough();
|
|
|
|
spyOn(registerview, 'renderRegistrationForm').and.callThrough();
|
|
|
|
registerview.delegateEvents(); // We need to rebind all events otherwise our spy won't be called
|
|
|
|
spyOn(_converse.connection, 'connect').and.callThrough();
|
|
|
|
|
|
|
|
expect(registerview._registering).toBeFalsy();
|
|
|
|
expect(_converse.connection.connected).toBeFalsy();
|
|
|
|
registerview.el.querySelector('input[name=domain]').value = 'conversejs.org';
|
|
|
|
registerview.el.querySelector('input[type=submit]').click();
|
|
|
|
expect(registerview.onProviderChosen).toHaveBeenCalled();
|
|
|
|
expect(registerview._registering).toBeTruthy();
|
|
|
|
expect(_converse.connection.connect).toHaveBeenCalled();
|
|
|
|
|
|
|
|
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"});
|
|
|
|
_converse.connection._connect_cb(test_utils.createRequest(stanza));
|
|
|
|
|
|
|
|
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');
|
|
|
|
_converse.connection._dataRecv(test_utils.createRequest(stanza));
|
|
|
|
expect(registerview.onRegistrationFields).toHaveBeenCalled();
|
|
|
|
expect(registerview.renderRegistrationForm).toHaveBeenCalled();
|
|
|
|
expect(registerview.el.querySelectorAll('input').length).toBe(5);
|
|
|
|
expect(registerview.el.querySelectorAll('input[type=submit]').length).toBe(1);
|
|
|
|
expect(registerview.el.querySelectorAll('input[type=button]').length).toBe(1);
|
|
|
|
done();
|
2017-08-16 12:31:17 +02:00
|
|
|
});
|
|
|
|
}));
|
|
|
|
|
|
|
|
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 () {
|
2018-01-03 20:02:05 +01:00
|
|
|
test_utils.openControlBox();
|
|
|
|
var cbview = _converse.chatboxviews.get('controlbox');
|
|
|
|
cbview.el.querySelector('.toggle-register-login').click();
|
|
|
|
|
|
|
|
var registerview = cbview.registerpanel;
|
|
|
|
spyOn(registerview, 'onProviderChosen').and.callThrough();
|
|
|
|
spyOn(registerview, 'getRegistrationFields').and.callThrough();
|
|
|
|
spyOn(registerview, 'onRegistrationFields').and.callThrough();
|
|
|
|
spyOn(registerview, 'renderRegistrationForm').and.callThrough();
|
|
|
|
registerview.delegateEvents(); // We need to rebind all events otherwise our spy won't be called
|
|
|
|
spyOn(_converse.connection, 'connect').and.callThrough();
|
|
|
|
|
|
|
|
registerview.el.querySelector('input[name=domain]').value = 'conversejs.org';
|
|
|
|
registerview.el.querySelector('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"});
|
|
|
|
_converse.connection._connect_cb(test_utils.createRequest(stanza));
|
|
|
|
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');
|
|
|
|
_converse.connection._dataRecv(test_utils.createRequest(stanza));
|
|
|
|
expect(registerview.form_type).toBe('legacy');
|
|
|
|
|
|
|
|
$(registerview.el.querySelector('input[name=username]')).val('testusername');
|
|
|
|
$(registerview.el.querySelector('input[name=password]')).val('testpassword');
|
|
|
|
$(registerview.el.querySelector('input[name=email]')).val('test@email.local');
|
|
|
|
|
|
|
|
spyOn(_converse.connection, 'send');
|
|
|
|
|
|
|
|
registerview.el.querySelector('input[type=submit]').click();
|
|
|
|
|
|
|
|
expect(_converse.connection.send).toHaveBeenCalled();
|
|
|
|
var $stanza = $(_converse.connection.send.calls.argsFor(0)[0].tree());
|
|
|
|
expect($stanza.children('query').children().length).toBe(3);
|
|
|
|
expect($stanza.children('query').children()[0].tagName).toBe('username');
|
|
|
|
done();
|
2017-08-16 12:31:17 +02:00
|
|
|
});
|
|
|
|
}));
|
|
|
|
|
|
|
|
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');
|
2018-01-03 20:02:05 +01:00
|
|
|
}, 300).then(function () {
|
|
|
|
test_utils.openControlBox();
|
|
|
|
var cbview = _converse.chatboxviews.get('controlbox');
|
|
|
|
cbview.el.querySelector('.toggle-register-login').click();
|
|
|
|
var registerview = _converse.chatboxviews.get('controlbox').registerpanel;
|
|
|
|
spyOn(registerview, 'onProviderChosen').and.callThrough();
|
|
|
|
spyOn(registerview, 'getRegistrationFields').and.callThrough();
|
|
|
|
spyOn(registerview, 'onRegistrationFields').and.callThrough();
|
|
|
|
spyOn(registerview, 'renderRegistrationForm').and.callThrough();
|
|
|
|
registerview.delegateEvents(); // We need to rebind all events otherwise our spy won't be called
|
|
|
|
spyOn(_converse.connection, 'connect').and.callThrough();
|
|
|
|
|
|
|
|
registerview.el.querySelector('input[name=domain]').value = 'conversejs.org';
|
|
|
|
registerview.el.querySelector('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"});
|
|
|
|
_converse.connection._connect_cb(test_utils.createRequest(stanza));
|
|
|
|
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();
|
|
|
|
_converse.connection._dataRecv(test_utils.createRequest(stanza));
|
|
|
|
expect(registerview.form_type).toBe('xform');
|
|
|
|
|
|
|
|
$(registerview.el.querySelector('input[name=username]')).val('testusername');
|
|
|
|
$(registerview.el.querySelector('input[name=password]')).val('testpassword');
|
|
|
|
$(registerview.el.querySelector('input[name=email]')).val('test@email.local');
|
|
|
|
|
|
|
|
spyOn(_converse.connection, 'send');
|
|
|
|
|
|
|
|
registerview.el.querySelector('input[type=submit]').click();
|
|
|
|
|
|
|
|
expect(_converse.connection.send).toHaveBeenCalled();
|
2018-06-04 10:26:44 +02:00
|
|
|
stanza = _converse.connection.send.calls.argsFor(0)[0].tree();
|
2018-10-02 17:01:39 +02:00
|
|
|
expect(Strophe.serialize(stanza).toLocaleString().trim().replace(/(\n|\s{2,})/g, '')).toEqual(
|
|
|
|
'<iq id="'+stanza.getAttribute('id')+'" type="set" xmlns="jabber:client">'+
|
2018-06-04 10:26:44 +02:00
|
|
|
'<query xmlns="jabber:iq:register">'+
|
2018-10-02 17:01:39 +02:00
|
|
|
'<x type="submit" xmlns="jabber:x:data">'+
|
|
|
|
'<field var="username">'+
|
2018-06-04 10:26:44 +02:00
|
|
|
'<value>testusername</value>'+
|
|
|
|
'</field>'+
|
2018-10-02 17:01:39 +02:00
|
|
|
'<field var="password">'+
|
2018-06-04 10:26:44 +02:00
|
|
|
'<value>testpassword</value>'+
|
|
|
|
'</field>'+
|
2018-10-02 17:01:39 +02:00
|
|
|
'<field var="email">'+
|
2018-06-04 10:26:44 +02:00
|
|
|
'<value>test@email.local</value>'+
|
|
|
|
'</field>'+
|
|
|
|
'</x>'+
|
|
|
|
'</query>'+
|
|
|
|
'</iq>'
|
|
|
|
);
|
2018-01-03 20:02:05 +01:00
|
|
|
done();
|
2017-08-16 12:31:17 +02:00
|
|
|
});
|
|
|
|
}));
|
2016-04-13 17:11:04 +02:00
|
|
|
});
|
2014-11-27 10:42:27 +01:00
|
|
|
}));
|