Use async/await and remove jquery in some tests

This commit is contained in:
JC Brand 2018-11-29 11:39:00 +01:00
parent 6358fd7c97
commit 36d2db78c4
2 changed files with 273 additions and 301 deletions

View File

@ -2,10 +2,10 @@
define(["jasmine", "mock", "test-utils"], factory); define(["jasmine", "mock", "test-utils"], factory);
} (this, function (jasmine, mock, test_utils) { } (this, function (jasmine, mock, test_utils) {
"use strict"; "use strict";
var $iq = converse.env.$iq; const $iq = converse.env.$iq;
var Strophe = converse.env.Strophe; const Strophe = converse.env.Strophe;
var _ = converse.env._; const _ = converse.env._;
var f = converse.env.f; const f = converse.env.f;
describe("XEP-0357 Push Notifications", function () { describe("XEP-0357 Push Notifications", function () {
@ -16,40 +16,36 @@
'jid': 'push-5@client.example', 'jid': 'push-5@client.example',
'node': 'yxs32uqsflafdk3iuqo' 'node': 'yxs32uqsflafdk3iuqo'
}] }]
}, function (done, _converse) { }, async function (done, _converse) {
const IQ_stanzas = _converse.connection.IQ_stanzas; const IQ_stanzas = _converse.connection.IQ_stanzas;
let stanza;
expect(_converse.session.get('push_enabled')).toBeFalsy(); expect(_converse.session.get('push_enabled')).toBeFalsy();
test_utils.waitUntilDiscoConfirmed( await test_utils.waitUntilDiscoConfirmed(
_converse, _converse.push_app_servers[0].jid, _converse, _converse.push_app_servers[0].jid,
[{'category': 'pubsub', 'type':'push'}], [{'category': 'pubsub', 'type':'push'}],
['urn:xmpp:push:0'], [], 'info') ['urn:xmpp:push:0'], [], 'info');
.then(() => test_utils.waitUntilDiscoConfirmed( await test_utils.waitUntilDiscoConfirmed(
_converse, _converse,
_converse.bare_jid, _converse.bare_jid,
[{'category': 'account', 'type':'registered'}], [{'category': 'account', 'type':'registered'}],
['urn:xmpp:push:0'], [], 'info')) ['urn:xmpp:push:0'], [], 'info');
.then(() => { const node = await test_utils.waitUntil(() =>
return test_utils.waitUntil(() => _.filter(IQ_stanzas, iq => iq.nodeTree.querySelector('iq[type="set"] enable[xmlns="urn:xmpp:push:0"]')).pop()
_.filter(IQ_stanzas, iq => iq.nodeTree.querySelector('iq[type="set"] enable[xmlns="urn:xmpp:push:0"]')).pop() );
) const stanza = node.nodeTree;
}).then(node => { expect(node.toLocaleString()).toEqual(
const stanza = node.nodeTree; `<iq id="${stanza.getAttribute('id')}" type="set" xmlns="jabber:client">`+
expect(node.toLocaleString()).toEqual( '<enable jid="push-5@client.example" node="yxs32uqsflafdk3iuqo" xmlns="urn:xmpp:push:0"/>'+
`<iq id="${stanza.getAttribute('id')}" type="set" xmlns="jabber:client">`+ '</iq>'
'<enable jid="push-5@client.example" node="yxs32uqsflafdk3iuqo" xmlns="urn:xmpp:push:0"/>'+ )
'</iq>' _converse.connection._dataRecv(test_utils.createRequest($iq({
) 'to': _converse.connection.jid,
_converse.connection._dataRecv(test_utils.createRequest($iq({ 'type': 'result',
'to': _converse.connection.jid, 'id': stanza.getAttribute('id')
'type': 'result', })));
'id': stanza.getAttribute('id') await test_utils.waitUntil(() => _converse.session.get('push_enabled'));
}))); done();
return test_utils.waitUntil(() => _converse.session.get('push_enabled'))
}).then(done).catch(_.partial(_converse.log, _, Strophe.LogLevel.FATAL));
})); }));
it("can be enabled for a MUC domain", it("can be enabled for a MUC domain",
@ -60,38 +56,36 @@
'jid': 'push-5@client.example', 'jid': 'push-5@client.example',
'node': 'yxs32uqsflafdk3iuqo' 'node': 'yxs32uqsflafdk3iuqo'
}] }]
}, function (done, _converse) { }, async function (done, _converse) {
const IQ_stanzas = _converse.connection.IQ_stanzas, const IQ_stanzas = _converse.connection.IQ_stanzas,
room_jid = 'coven@chat.shakespeare.lit'; room_jid = 'coven@chat.shakespeare.lit';
expect(_converse.session.get('push_enabled')).toBeFalsy(); expect(_converse.session.get('push_enabled')).toBeFalsy();
test_utils.openAndEnterChatRoom(_converse, 'coven', 'chat.shakespeare.lit', 'oldhag') test_utils.openAndEnterChatRoom(_converse, 'coven', 'chat.shakespeare.lit', 'oldhag');
.then(() => test_utils.waitUntilDiscoConfirmed( await test_utils.waitUntilDiscoConfirmed(
_converse, _converse.push_app_servers[0].jid, _converse, _converse.push_app_servers[0].jid,
[{'category': 'pubsub', 'type':'push'}], [{'category': 'pubsub', 'type':'push'}],
['urn:xmpp:push:0'], [], 'info')) ['urn:xmpp:push:0'], [], 'info');
.then(() => { await test_utils.waitUntilDiscoConfirmed(
return test_utils.waitUntilDiscoConfirmed( _converse, 'chat.shakespeare.lit',
_converse, 'chat.shakespeare.lit', [{'category': 'account', 'type':'registered'}],
[{'category': 'account', 'type':'registered'}], ['urn:xmpp:push:0'], [], 'info');
['urn:xmpp:push:0'], [], 'info') const stanza = await test_utils.waitUntil(
}).then(() => { () => _.filter(IQ_stanzas, (iq) => iq.nodeTree.querySelector('iq[type="set"] enable[xmlns="urn:xmpp:push:0"]')).pop()
return test_utils.waitUntil( );
() => _.filter(IQ_stanzas, (iq) => iq.nodeTree.querySelector('iq[type="set"] enable[xmlns="urn:xmpp:push:0"]')).pop()) expect(stanza.toLocaleString()).toEqual(
}).then(stanza => { `<iq id="${stanza.nodeTree.getAttribute('id')}" to="chat.shakespeare.lit" type="set" xmlns="jabber:client">`+
expect(stanza.toLocaleString()).toEqual( '<enable jid="push-5@client.example" node="yxs32uqsflafdk3iuqo" xmlns="urn:xmpp:push:0"/>'+
`<iq id="${stanza.nodeTree.getAttribute('id')}" to="chat.shakespeare.lit" type="set" xmlns="jabber:client">`+ '</iq>'
'<enable jid="push-5@client.example" node="yxs32uqsflafdk3iuqo" xmlns="urn:xmpp:push:0"/>'+ );
'</iq>' _converse.connection._dataRecv(test_utils.createRequest($iq({
) 'to': _converse.connection.jid,
_converse.connection._dataRecv(test_utils.createRequest($iq({ 'type': 'result',
'to': _converse.connection.jid, 'id': stanza.nodeTree.getAttribute('id')
'type': 'result', })));
'id': stanza.nodeTree.getAttribute('id') await test_utils.waitUntil(() => f.includes('chat.shakespeare.lit', _converse.session.get('push_enabled')));
}))); done();
return test_utils.waitUntil(() => f.includes('chat.shakespeare.lit', _converse.session.get('push_enabled')));
}).then(done).catch(_.partial(_converse.log, _, Strophe.LogLevel.FATAL));
})); }));
it("can be disabled", it("can be disabled",
@ -102,33 +96,32 @@
'node': 'yxs32uqsflafdk3iuqo', 'node': 'yxs32uqsflafdk3iuqo',
'disable': true 'disable': true
}] }]
}, function (done, _converse) { }, async function (done, _converse) {
const IQ_stanzas = _converse.connection.IQ_stanzas; const IQ_stanzas = _converse.connection.IQ_stanzas;
let stanza;
expect(_converse.session.get('push_enabled')).toBeFalsy(); expect(_converse.session.get('push_enabled')).toBeFalsy();
test_utils.waitUntilDiscoConfirmed( await test_utils.waitUntilDiscoConfirmed(
_converse, _converse,
_converse.bare_jid, _converse.bare_jid,
[{'category': 'account', 'type':'registered'}], [{'category': 'account', 'type':'registered'}],
['urn:xmpp:push:0'], [], 'info') ['urn:xmpp:push:0'], [], 'info');
.then(() => test_utils.waitUntil( const node = await test_utils.waitUntil(
() => _.filter(IQ_stanzas, iq => iq.nodeTree.querySelector('iq[type="set"] disable[xmlns="urn:xmpp:push:0"]')).pop() () => _.filter(IQ_stanzas, iq => iq.nodeTree.querySelector('iq[type="set"] disable[xmlns="urn:xmpp:push:0"]')).pop()
)).then(node => { );
const stanza = node.nodeTree; const stanza = node.nodeTree;
expect(node.toLocaleString()).toEqual( expect(node.toLocaleString()).toEqual(
`<iq id="${stanza.getAttribute('id')}" type="set" xmlns="jabber:client">`+ `<iq id="${stanza.getAttribute('id')}" type="set" xmlns="jabber:client">`+
'<disable jid="push-5@client.example" node="yxs32uqsflafdk3iuqo" xmlns="urn:xmpp:push:0"/>'+ '<disable jid="push-5@client.example" node="yxs32uqsflafdk3iuqo" xmlns="urn:xmpp:push:0"/>'+
'</iq>' '</iq>'
) )
_converse.connection._dataRecv(test_utils.createRequest($iq({ _converse.connection._dataRecv(test_utils.createRequest($iq({
'to': _converse.connection.jid, 'to': _converse.connection.jid,
'type': 'result', 'type': 'result',
'id': stanza.getAttribute('id') 'id': stanza.getAttribute('id')
}))); })));
return test_utils.waitUntil(() => _converse.session.get('push_enabled')) await test_utils.waitUntil(() => _converse.session.get('push_enabled'))
}).then(done).catch(_.partial(_converse.log, _, Strophe.LogLevel.FATAL)); done();
})); }));
@ -140,42 +133,42 @@
'node': 'yxs32uqsflafdk3iuqo', 'node': 'yxs32uqsflafdk3iuqo',
'secret': 'eruio234vzxc2kla-91' 'secret': 'eruio234vzxc2kla-91'
}] }]
}, function (done, _converse) { }, async function (done, _converse) {
const IQ_stanzas = _converse.connection.IQ_stanzas; const IQ_stanzas = _converse.connection.IQ_stanzas;
let stanza;
expect(_converse.session.get('push_enabled')).toBeFalsy(); expect(_converse.session.get('push_enabled')).toBeFalsy();
test_utils.waitUntilDiscoConfirmed( await test_utils.waitUntilDiscoConfirmed(
_converse, _converse.push_app_servers[0].jid, _converse, _converse.push_app_servers[0].jid,
[{'category': 'pubsub', 'type':'push'}], [{'category': 'pubsub', 'type':'push'}],
['urn:xmpp:push:0'], [], 'info') ['urn:xmpp:push:0'], [], 'info');
.then(() => test_utils.waitUntilDiscoConfirmed( await test_utils.waitUntilDiscoConfirmed(
_converse, _converse,
_converse.bare_jid, _converse.bare_jid,
[{'category': 'account', 'type':'registered'}], [{'category': 'account', 'type':'registered'}],
['urn:xmpp:push:0'], [], 'info')) ['urn:xmpp:push:0'], [], 'info');
.then(() => test_utils.waitUntil(
const node = await test_utils.waitUntil(
() => _.filter(IQ_stanzas, iq => iq.nodeTree.querySelector('iq[type="set"] enable[xmlns="urn:xmpp:push:0"]')).pop() () => _.filter(IQ_stanzas, iq => iq.nodeTree.querySelector('iq[type="set"] enable[xmlns="urn:xmpp:push:0"]')).pop()
)).then(node => { );
const stanza = node.nodeTree; const stanza = node.nodeTree;
expect(node.toLocaleString()).toEqual( expect(node.toLocaleString()).toEqual(
`<iq id="${stanza.getAttribute('id')}" type="set" xmlns="jabber:client">`+ `<iq id="${stanza.getAttribute('id')}" type="set" xmlns="jabber:client">`+
'<enable jid="push-5@client.example" node="yxs32uqsflafdk3iuqo" xmlns="urn:xmpp:push:0">'+ '<enable jid="push-5@client.example" node="yxs32uqsflafdk3iuqo" xmlns="urn:xmpp:push:0">'+
'<x type="submit" xmlns="jabber:x:data">'+ '<x type="submit" xmlns="jabber:x:data">'+
'<field var="FORM_TYPE"><value>http://jabber.org/protocol/pubsub#publish-options</value></field>'+ '<field var="FORM_TYPE"><value>http://jabber.org/protocol/pubsub#publish-options</value></field>'+
'<field var="secret"><value>eruio234vzxc2kla-91</value></field>'+ '<field var="secret"><value>eruio234vzxc2kla-91</value></field>'+
'</x>'+ '</x>'+
'</enable>'+ '</enable>'+
'</iq>' '</iq>'
) )
_converse.connection._dataRecv(test_utils.createRequest($iq({ _converse.connection._dataRecv(test_utils.createRequest($iq({
'to': _converse.connection.jid, 'to': _converse.connection.jid,
'type': 'result', 'type': 'result',
'id': stanza.getAttribute('id') 'id': stanza.getAttribute('id')
}))); })));
return test_utils.waitUntil(() => _converse.session.get('push_enabled')) await test_utils.waitUntil(() => _converse.session.get('push_enabled'))
}).then(done).catch(_.partial(_converse.log, _, Strophe.LogLevel.FATAL)); done();
})); }));
}); });
})); }));

View File

@ -1,9 +1,10 @@
(function (root, factory) { (function (root, factory) {
define(["jquery", "jasmine", "mock", "test-utils"], factory); define(["jasmine", "mock", "test-utils"], factory);
} (this, function ($, jasmine, mock, test_utils) { } (this, function (jasmine, mock, test_utils) {
var Strophe = converse.env.Strophe; const Strophe = converse.env.Strophe;
var $iq = converse.env.$iq; const $iq = converse.env.$iq;
var _ = converse.env._; const { _, sizzle} = converse.env;
const u = converse.env.utils;
describe("The Registration Panel", function () { describe("The Registration Panel", function () {
@ -12,15 +13,13 @@
null, ['connectionInitialized', 'chatBoxesInitialized'], null, ['connectionInitialized', 'chatBoxesInitialized'],
{ auto_login: false, { auto_login: false,
allow_registration: false }, allow_registration: false },
function (done, _converse) { async function (done, _converse) {
test_utils.waitUntil(() => _converse.chatboxviews.get('controlbox')) await test_utils.waitUntil(() => _converse.chatboxviews.get('controlbox'));
.then(function () { test_utils.openControlBox();
test_utils.openControlBox(); const cbview = _converse.chatboxviews.get('controlbox');
var cbview = _converse.chatboxviews.get('controlbox'); expect(cbview.el.querySelectorAll('a.register-account').length).toBe(0);
expect($(cbview.el.querySelector('a.register-account')).length).toBe(0); done();
done();
});
})); }));
it("can be opened by clicking on the registration tab", it("can be opened by clicking on the registration tab",
@ -28,26 +27,20 @@
null, ['connectionInitialized', 'chatBoxesInitialized'], null, ['connectionInitialized', 'chatBoxesInitialized'],
{ auto_login: false, { auto_login: false,
allow_registration: true }, allow_registration: true },
function (done, _converse) { async function (done, _converse) {
test_utils.waitUntil(() => _.get(_converse.chatboxviews.get('controlbox'), 'registerpanel'), 300) await test_utils.waitUntil(() => _.get(_converse.chatboxviews.get('controlbox'), 'registerpanel'), 300);
.then(function () { const cbview = _converse.chatboxviews.get('controlbox');
var cbview = _converse.chatboxviews.get('controlbox'); test_utils.openControlBox();
test_utils.openControlBox(); const panels = cbview.el.querySelector('.controlbox-panes');
var $panels = $(cbview.el.querySelector('.controlbox-panes')); const login = panels.firstElementChild;
var $login = $panels.children().first(); const registration = panels.childNodes[1];
var $registration = $panels.children().last(); const register_link = cbview.el.querySelector('a.register-account');
expect(register_link.textContent).toBe("Create an account");
var register_link = cbview.el.querySelector('a.register-account'); register_link.click();
expect(register_link.textContent).toBe("Create an account"); await test_utils.waitUntil(() => u.isVisible(registration));
register_link.click(); expect(u.isVisible(login)).toBe(false);
test_utils.waitUntil(function () { done();
return $registration.is(':visible');
}, 300).then(function () {
expect($login.is(':visible')).toBe(false);
done();
});
});
})); }));
it("allows the user to choose an XMPP provider's domain", it("allows the user to choose an XMPP provider's domain",
@ -55,16 +48,12 @@
null, ['connectionInitialized', 'chatBoxesInitialized'], null, ['connectionInitialized', 'chatBoxesInitialized'],
{ auto_login: false, { auto_login: false,
allow_registration: true }, allow_registration: true },
function (done, _converse) { async function (done, _converse) {
test_utils.waitUntil(function () {
return _.get(_converse.chatboxviews.get('controlbox'), 'registerpanel');
}, 300)
.then(function () {
await test_utils.waitUntil(() => _.get(_converse.chatboxviews.get('controlbox'), 'registerpanel'));
test_utils.openControlBox(); test_utils.openControlBox();
var cbview = _converse.chatboxviews.get('controlbox'); const cbview = _converse.chatboxviews.get('controlbox');
var registerview = cbview.registerpanel; const registerview = cbview.registerpanel;
spyOn(registerview, 'onProviderChosen').and.callThrough(); spyOn(registerview, 'onProviderChosen').and.callThrough();
registerview.delegateEvents(); // We need to rebind all events otherwise our spy won't be called registerview.delegateEvents(); // We need to rebind all events otherwise our spy won't be called
spyOn(_converse.connection, 'connect'); spyOn(_converse.connection, 'connect');
@ -73,21 +62,21 @@
cbview.el.querySelector('.toggle-register-login').click(); cbview.el.querySelector('.toggle-register-login').click();
// Check the form layout // Check the form layout
var $form = $(cbview.el.querySelector('#converse-register')); const form = cbview.el.querySelector('#converse-register');
expect($form.find('input').length).toEqual(2); expect(form.querySelectorAll('input').length).toEqual(2);
expect($form.find('input').first().attr('name')).toEqual('domain'); expect(form.querySelectorAll('input')[0].getAttribute('name')).toEqual('domain');
expect($form.find('input').last().attr('type')).toEqual('submit'); expect(sizzle('input:last', form).pop().getAttribute('type')).toEqual('submit');
// Check that the input[type=domain] input is required // Check that the input[type=domain] input is required
$form.find('input[type=submit]')[0].click(); const submit_button = form.querySelector('input[type=submit]');
submit_button.click();
expect(registerview.onProviderChosen).not.toHaveBeenCalled(); expect(registerview.onProviderChosen).not.toHaveBeenCalled();
// Check that the form is accepted if input[type=domain] has a value // Check that the form is accepted if input[type=domain] has a value
$form.find('input[name=domain]').val('conversejs.org'); form.querySelector('input[name=domain]').value = 'conversejs.org';
$form.find('input[type=submit]')[0].click(); submit_button.click();
expect(registerview.onProviderChosen).toHaveBeenCalled(); expect(registerview.onProviderChosen).toHaveBeenCalled();
expect(_converse.connection.connect).toHaveBeenCalled(); expect(_converse.connection.connect).toHaveBeenCalled();
done(); done();
});
})); }));
it("will render a registration form as received from the XMPP provider", it("will render a registration form as received from the XMPP provider",
@ -95,58 +84,55 @@
null, ['connectionInitialized', 'chatBoxesInitialized'], null, ['connectionInitialized', 'chatBoxesInitialized'],
{ auto_login: false, { auto_login: false,
allow_registration: true }, allow_registration: true },
function (done, _converse) { async function (done, _converse) {
test_utils.waitUntil(function () { await test_utils.waitUntil(() => _.get(_converse.chatboxviews.get('controlbox'), 'registerpanel'));
return _.get(_converse.chatboxviews.get('controlbox'), 'registerpanel'); test_utils.openControlBox();
}, 300).then(function () { const cbview = _converse.chatboxviews.get('controlbox');
test_utils.openControlBox(); cbview.el.querySelector('.toggle-register-login').click();
var cbview = _converse.chatboxviews.get('controlbox');
cbview.el.querySelector('.toggle-register-login').click();
var registerview = _converse.chatboxviews.get('controlbox').registerpanel; const registerview = _converse.chatboxviews.get('controlbox').registerpanel;
spyOn(registerview, 'onProviderChosen').and.callThrough(); spyOn(registerview, 'onProviderChosen').and.callThrough();
spyOn(registerview, 'getRegistrationFields').and.callThrough(); spyOn(registerview, 'getRegistrationFields').and.callThrough();
spyOn(registerview, 'onRegistrationFields').and.callThrough(); spyOn(registerview, 'onRegistrationFields').and.callThrough();
spyOn(registerview, 'renderRegistrationForm').and.callThrough(); spyOn(registerview, 'renderRegistrationForm').and.callThrough();
registerview.delegateEvents(); // We need to rebind all events otherwise our spy won't be called registerview.delegateEvents(); // We need to rebind all events otherwise our spy won't be called
spyOn(_converse.connection, 'connect').and.callThrough(); spyOn(_converse.connection, 'connect').and.callThrough();
expect(registerview._registering).toBeFalsy(); expect(registerview._registering).toBeFalsy();
expect(_converse.connection.connected).toBeFalsy(); expect(_converse.connection.connected).toBeFalsy();
registerview.el.querySelector('input[name=domain]').value = 'conversejs.org'; registerview.el.querySelector('input[name=domain]').value = 'conversejs.org';
registerview.el.querySelector('input[type=submit]').click(); registerview.el.querySelector('input[type=submit]').click();
expect(registerview.onProviderChosen).toHaveBeenCalled(); expect(registerview.onProviderChosen).toHaveBeenCalled();
expect(registerview._registering).toBeTruthy(); expect(registerview._registering).toBeTruthy();
expect(_converse.connection.connect).toHaveBeenCalled(); expect(_converse.connection.connect).toHaveBeenCalled();
var stanza = new Strophe.Builder("stream:features", { let stanza = new Strophe.Builder("stream:features", {
'xmlns:stream': "http://etherx.jabber.org/streams", 'xmlns:stream': "http://etherx.jabber.org/streams",
'xmlns': "jabber:client" 'xmlns': "jabber:client"
}) })
.c('register', {xmlns: "http://jabber.org/features/iq-register"}).up() .c('register', {xmlns: "http://jabber.org/features/iq-register"}).up()
.c('mechanisms', {xmlns: "urn:ietf:params:xml:ns:xmpp-sasl"}); .c('mechanisms', {xmlns: "urn:ietf:params:xml:ns:xmpp-sasl"});
_converse.connection._connect_cb(test_utils.createRequest(stanza)); _converse.connection._connect_cb(test_utils.createRequest(stanza));
expect(registerview.getRegistrationFields).toHaveBeenCalled(); expect(registerview.getRegistrationFields).toHaveBeenCalled();
stanza = $iq({ stanza = $iq({
'type': 'result', 'type': 'result',
'id': 'reg1' 'id': 'reg1'
}).c('query', {'xmlns': 'jabber:iq:register'}) }).c('query', {'xmlns': 'jabber:iq:register'})
.c('instructions') .c('instructions')
.t('Please choose a username, password and provide your email address').up() .t('Please choose a username, password and provide your email address').up()
.c('username').up() .c('username').up()
.c('password').up() .c('password').up()
.c('email'); .c('email');
_converse.connection._dataRecv(test_utils.createRequest(stanza)); _converse.connection._dataRecv(test_utils.createRequest(stanza));
expect(registerview.onRegistrationFields).toHaveBeenCalled(); expect(registerview.onRegistrationFields).toHaveBeenCalled();
expect(registerview.renderRegistrationForm).toHaveBeenCalled(); expect(registerview.renderRegistrationForm).toHaveBeenCalled();
expect(registerview.el.querySelectorAll('input').length).toBe(5); expect(registerview.el.querySelectorAll('input').length).toBe(5);
expect(registerview.el.querySelectorAll('input[type=submit]').length).toBe(1); expect(registerview.el.querySelectorAll('input[type=submit]').length).toBe(1);
expect(registerview.el.querySelectorAll('input[type=button]').length).toBe(1); expect(registerview.el.querySelectorAll('input[type=button]').length).toBe(1);
done(); done();
});
})); }));
it("will set form_type to legacy and submit it as legacy", it("will set form_type to legacy and submit it as legacy",
@ -154,60 +140,56 @@
null, ['connectionInitialized', 'chatBoxesInitialized'], null, ['connectionInitialized', 'chatBoxesInitialized'],
{ auto_login: false, { auto_login: false,
allow_registration: true }, allow_registration: true },
function (done, _converse) { async function (done, _converse) {
test_utils.waitUntil(function () { await test_utils.waitUntil(() => _.get(_converse.chatboxviews.get('controlbox'), 'registerpanel'));
return _.get(_converse.chatboxviews.get('controlbox'), 'registerpanel'); test_utils.openControlBox();
}, 300) const cbview = _converse.chatboxviews.get('controlbox');
.then(function () { cbview.el.querySelector('.toggle-register-login').click();
test_utils.openControlBox();
var cbview = _converse.chatboxviews.get('controlbox');
cbview.el.querySelector('.toggle-register-login').click();
var registerview = cbview.registerpanel; const registerview = cbview.registerpanel;
spyOn(registerview, 'onProviderChosen').and.callThrough(); spyOn(registerview, 'onProviderChosen').and.callThrough();
spyOn(registerview, 'getRegistrationFields').and.callThrough(); spyOn(registerview, 'getRegistrationFields').and.callThrough();
spyOn(registerview, 'onRegistrationFields').and.callThrough(); spyOn(registerview, 'onRegistrationFields').and.callThrough();
spyOn(registerview, 'renderRegistrationForm').and.callThrough(); spyOn(registerview, 'renderRegistrationForm').and.callThrough();
registerview.delegateEvents(); // We need to rebind all events otherwise our spy won't be called registerview.delegateEvents(); // We need to rebind all events otherwise our spy won't be called
spyOn(_converse.connection, 'connect').and.callThrough(); spyOn(_converse.connection, 'connect').and.callThrough();
registerview.el.querySelector('input[name=domain]').value = 'conversejs.org'; registerview.el.querySelector('input[name=domain]').value = 'conversejs.org';
registerview.el.querySelector('input[type=submit]').click(); registerview.el.querySelector('input[type=submit]').click();
var stanza = new Strophe.Builder("stream:features", { let stanza = new Strophe.Builder("stream:features", {
'xmlns:stream': "http://etherx.jabber.org/streams", 'xmlns:stream': "http://etherx.jabber.org/streams",
'xmlns': "jabber:client" 'xmlns': "jabber:client"
}) })
.c('register', {xmlns: "http://jabber.org/features/iq-register"}).up() .c('register', {xmlns: "http://jabber.org/features/iq-register"}).up()
.c('mechanisms', {xmlns: "urn:ietf:params:xml:ns:xmpp-sasl"}); .c('mechanisms', {xmlns: "urn:ietf:params:xml:ns:xmpp-sasl"});
_converse.connection._connect_cb(test_utils.createRequest(stanza)); _converse.connection._connect_cb(test_utils.createRequest(stanza));
stanza = $iq({ stanza = $iq({
'type': 'result', 'type': 'result',
'id': 'reg1' 'id': 'reg1'
}).c('query', {'xmlns': 'jabber:iq:register'}) }).c('query', {'xmlns': 'jabber:iq:register'})
.c('instructions') .c('instructions')
.t('Please choose a username, password and provide your email address').up() .t('Please choose a username, password and provide your email address').up()
.c('username').up() .c('username').up()
.c('password').up() .c('password').up()
.c('email'); .c('email');
_converse.connection._dataRecv(test_utils.createRequest(stanza)); _converse.connection._dataRecv(test_utils.createRequest(stanza));
expect(registerview.form_type).toBe('legacy'); expect(registerview.form_type).toBe('legacy');
$(registerview.el.querySelector('input[name=username]')).val('testusername'); registerview.el.querySelector('input[name=username]').value = 'testusername';
$(registerview.el.querySelector('input[name=password]')).val('testpassword'); registerview.el.querySelector('input[name=password]').value = 'testpassword';
$(registerview.el.querySelector('input[name=email]')).val('test@email.local'); registerview.el.querySelector('input[name=email]').value = 'test@email.local';
spyOn(_converse.connection, 'send'); spyOn(_converse.connection, 'send');
registerview.el.querySelector('input[type=submit]').click(); registerview.el.querySelector('input[type=submit]').click();
expect(_converse.connection.send).toHaveBeenCalled(); expect(_converse.connection.send).toHaveBeenCalled();
var $stanza = $(_converse.connection.send.calls.argsFor(0)[0].tree()); stanza = _converse.connection.send.calls.argsFor(0)[0].tree();
expect($stanza.children('query').children().length).toBe(3); expect(stanza.querySelector('query').childNodes.length).toBe(3);
expect($stanza.children('query').children()[0].tagName).toBe('username'); expect(stanza.querySelector('query').firstElementChild.tagName).toBe('username');
done(); done();
});
})); }));
it("will set form_type to xform and submit it as xform", it("will set form_type to xform and submit it as xform",
@ -215,75 +197,72 @@
null, ['connectionInitialized', 'chatBoxesInitialized'], null, ['connectionInitialized', 'chatBoxesInitialized'],
{ auto_login: false, { auto_login: false,
allow_registration: true }, allow_registration: true },
function (done, _converse) { async function (done, _converse) {
test_utils.waitUntil(function () { await test_utils.waitUntil(() => _.get(_converse.chatboxviews.get('controlbox'), 'registerpanel'));
return _.get(_converse.chatboxviews.get('controlbox'), 'registerpanel'); test_utils.openControlBox();
}, 300).then(function () { const cbview = _converse.chatboxviews.get('controlbox');
test_utils.openControlBox(); cbview.el.querySelector('.toggle-register-login').click();
var cbview = _converse.chatboxviews.get('controlbox'); const registerview = _converse.chatboxviews.get('controlbox').registerpanel;
cbview.el.querySelector('.toggle-register-login').click(); spyOn(registerview, 'onProviderChosen').and.callThrough();
var registerview = _converse.chatboxviews.get('controlbox').registerpanel; spyOn(registerview, 'getRegistrationFields').and.callThrough();
spyOn(registerview, 'onProviderChosen').and.callThrough(); spyOn(registerview, 'onRegistrationFields').and.callThrough();
spyOn(registerview, 'getRegistrationFields').and.callThrough(); spyOn(registerview, 'renderRegistrationForm').and.callThrough();
spyOn(registerview, 'onRegistrationFields').and.callThrough(); registerview.delegateEvents(); // We need to rebind all events otherwise our spy won't be called
spyOn(registerview, 'renderRegistrationForm').and.callThrough(); spyOn(_converse.connection, 'connect').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[name=domain]').value = 'conversejs.org';
registerview.el.querySelector('input[type=submit]').click(); registerview.el.querySelector('input[type=submit]').click();
var stanza = new Strophe.Builder("stream:features", { let stanza = new Strophe.Builder("stream:features", {
'xmlns:stream': "http://etherx.jabber.org/streams", 'xmlns:stream': "http://etherx.jabber.org/streams",
'xmlns': "jabber:client" 'xmlns': "jabber:client"
}) })
.c('register', {xmlns: "http://jabber.org/features/iq-register"}).up() .c('register', {xmlns: "http://jabber.org/features/iq-register"}).up()
.c('mechanisms', {xmlns: "urn:ietf:params:xml:ns:xmpp-sasl"}); .c('mechanisms', {xmlns: "urn:ietf:params:xml:ns:xmpp-sasl"});
_converse.connection._connect_cb(test_utils.createRequest(stanza)); _converse.connection._connect_cb(test_utils.createRequest(stanza));
stanza = $iq({ stanza = $iq({
'type': 'result', 'type': 'result',
'id': 'reg1' 'id': 'reg1'
}).c('query', {'xmlns': 'jabber:iq:register'}) }).c('query', {'xmlns': 'jabber:iq:register'})
.c('instructions') .c('instructions')
.t('Using xform data').up() .t('Using xform data').up()
.c('x', { 'xmlns': 'jabber:x:data', 'type': 'form' }) .c('x', { 'xmlns': 'jabber:x:data', 'type': 'form' })
.c('instructions').t('xform instructions').up() .c('instructions').t('xform instructions').up()
.c('field', {'type': 'text-single', 'var': 'username'}).c('required').up().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-private', 'var': 'password'}).c('required').up().up()
.c('field', {'type': 'text-single', 'var': 'email'}).c('required').up().up(); .c('field', {'type': 'text-single', 'var': 'email'}).c('required').up().up();
_converse.connection._dataRecv(test_utils.createRequest(stanza)); _converse.connection._dataRecv(test_utils.createRequest(stanza));
expect(registerview.form_type).toBe('xform'); expect(registerview.form_type).toBe('xform');
$(registerview.el.querySelector('input[name=username]')).val('testusername'); registerview.el.querySelector('input[name=username]').value = 'testusername';
$(registerview.el.querySelector('input[name=password]')).val('testpassword'); registerview.el.querySelector('input[name=password]').value = 'testpassword';
$(registerview.el.querySelector('input[name=email]')).val('test@email.local'); registerview.el.querySelector('input[name=email]').value = 'test@email.local';
spyOn(_converse.connection, 'send'); spyOn(_converse.connection, 'send');
registerview.el.querySelector('input[type=submit]').click(); registerview.el.querySelector('input[type=submit]').click();
expect(_converse.connection.send).toHaveBeenCalled(); expect(_converse.connection.send).toHaveBeenCalled();
stanza = _converse.connection.send.calls.argsFor(0)[0].tree(); stanza = _converse.connection.send.calls.argsFor(0)[0].tree();
expect(Strophe.serialize(stanza).toLocaleString().trim().replace(/(\n|\s{2,})/g, '')).toEqual( expect(Strophe.serialize(stanza).toLocaleString().trim().replace(/(\n|\s{2,})/g, '')).toEqual(
'<iq id="'+stanza.getAttribute('id')+'" type="set" xmlns="jabber:client">'+ '<iq id="'+stanza.getAttribute('id')+'" type="set" xmlns="jabber:client">'+
'<query xmlns="jabber:iq:register">'+ '<query xmlns="jabber:iq:register">'+
'<x type="submit" xmlns="jabber:x:data">'+ '<x type="submit" xmlns="jabber:x:data">'+
'<field var="username">'+ '<field var="username">'+
'<value>testusername</value>'+ '<value>testusername</value>'+
'</field>'+ '</field>'+
'<field var="password">'+ '<field var="password">'+
'<value>testpassword</value>'+ '<value>testpassword</value>'+
'</field>'+ '</field>'+
'<field var="email">'+ '<field var="email">'+
'<value>test@email.local</value>'+ '<value>test@email.local</value>'+
'</field>'+ '</field>'+
'</x>'+ '</x>'+
'</query>'+ '</query>'+
'</iq>' '</iq>'
); );
done(); done();
});
})); }));
}); });
})); }));