Commit 0d3e94c6 authored by JC Brand's avatar JC Brand

Minor testing changes

- Use async/await instead of promises.
- Use different room jids (to try and see whether this fixes heisenbugs on travis)
parent 1c7c70af
...@@ -3385,97 +3385,96 @@ ...@@ -3385,97 +3385,96 @@
it("will show an error message if the user is not allowed to have created the groupchat", it("will show an error message if the user is not allowed to have created the groupchat",
mock.initConverseWithPromises( mock.initConverseWithPromises(
null, ['rosterGroupsFetched'], {}, null, ['rosterGroupsFetched'], {},
function (done, _converse) { async function (done, _converse) {
test_utils.openChatRoomViaModal(_converse, 'problematic@muc.localhost', 'dummy') const groupchat_jid = 'impermissable@muc.localhost'
.then(function () { await test_utils.openChatRoomViaModal(_converse, groupchat_jid, 'dummy')
var presence = $pres().attrs({ var presence = $pres().attrs({
from:'problematic@muc.localhost/dummy', from: `${groupchat_jid}/dummy`,
id:'n13mt3l', id:'n13mt3l',
to:'dummy@localhost/pda', to:'dummy@localhost/pda',
type:'error'}) type:'error'
.c('x').attrs({xmlns:'http://jabber.org/protocol/muc'}).up() }).c('x').attrs({xmlns:'http://jabber.org/protocol/muc'}).up()
.c('error').attrs({by:'lounge@localhost', type:'cancel'}) .c('error').attrs({by:'lounge@localhost', type:'cancel'})
.c('not-allowed').attrs({xmlns:'urn:ietf:params:xml:ns:xmpp-stanzas'}).nodeTree; .c('not-allowed').attrs({xmlns:'urn:ietf:params:xml:ns:xmpp-stanzas'}).nodeTree;
var view = _converse.chatboxviews.get('problematic@muc.localhost'); const view = _converse.chatboxviews.get(groupchat_jid);
spyOn(view, 'showErrorMessage').and.callThrough(); spyOn(view, 'showErrorMessage').and.callThrough();
_converse.connection._dataRecv(test_utils.createRequest(presence)); _converse.connection._dataRecv(test_utils.createRequest(presence));
expect(view.el.querySelector('.chatroom-body .disconnect-container .disconnect-msg:last-child').textContent) expect(view.el.querySelector('.chatroom-body .disconnect-container .disconnect-msg:last-child').textContent)
.toBe('You are not allowed to create new groupchats.'); .toBe('You are not allowed to create new groupchats.');
done(); done();
}).catch(_.partial(console.error, _));
})); }));
it("will show an error message if the user's nickname doesn't conform to room policy", it("will show an error message if the user's nickname doesn't conform to groupchat policy",
mock.initConverseWithPromises( mock.initConverseWithPromises(
null, ['rosterGroupsFetched'], {}, null, ['rosterGroupsFetched'], {},
function (done, _converse) { async function (done, _converse) {
test_utils.openChatRoomViaModal(_converse, 'problematic@muc.localhost', 'dummy') const groupchat_jid = 'conformist@muc.localhost'
.then(function () { await test_utils.openChatRoomViaModal(_converse, groupchat_jid, 'dummy');
var presence = $pres().attrs({ var presence = $pres().attrs({
from:'problematic@muc.localhost/dummy', from: `${groupchat_jid}/dummy`,
id:'n13mt3l', id: u.getUniqueId(),
to:'dummy@localhost/pda', to:'dummy@localhost/pda',
type:'error'}) type:'error'
.c('x').attrs({xmlns:'http://jabber.org/protocol/muc'}).up() }).c('x').attrs({xmlns:'http://jabber.org/protocol/muc'}).up()
.c('error').attrs({by:'lounge@localhost', type:'cancel'}) .c('error').attrs({by:'lounge@localhost', type:'cancel'})
.c('not-acceptable').attrs({xmlns:'urn:ietf:params:xml:ns:xmpp-stanzas'}).nodeTree; .c('not-acceptable').attrs({xmlns:'urn:ietf:params:xml:ns:xmpp-stanzas'}).nodeTree;
var view = _converse.chatboxviews.get('problematic@muc.localhost');
var view = _converse.chatboxviews.get(groupchat_jid);
spyOn(view, 'showErrorMessage').and.callThrough(); spyOn(view, 'showErrorMessage').and.callThrough();
_converse.connection._dataRecv(test_utils.createRequest(presence)); _converse.connection._dataRecv(test_utils.createRequest(presence));
expect(view.el.querySelector('.chatroom-body .disconnect-container .disconnect-msg:last-child').textContent) expect(view.el.querySelector('.chatroom-body .disconnect-container .disconnect-msg:last-child').textContent)
.toBe("Your nickname doesn't conform to this groupchat's policies."); .toBe("Your nickname doesn't conform to this groupchat's policies.");
done(); done();
}).catch(_.partial(console.error, _));
})); }));
it("will show an error message if the groupchat doesn't yet exist", it("will show an error message if the groupchat doesn't yet exist",
mock.initConverseWithPromises( mock.initConverseWithPromises(
null, ['rosterGroupsFetched'], {}, null, ['rosterGroupsFetched'], {},
function (done, _converse) { async function (done, _converse) {
test_utils.openChatRoomViaModal(_converse, 'problematic@muc.localhost', 'dummy') const groupchat_jid = 'nonexistent@muc.localhost'
.then(function () { await test_utils.openChatRoomViaModal(_converse, groupchat_jid, 'dummy');
var presence = $pres().attrs({ const presence = $pres().attrs({
from:'problematic@muc.localhost/dummy', from: `${groupchat_jid}/dummy`,
id:'n13mt3l', id: u.getUniqueId(),
to:'dummy@localhost/pda', to: 'dummy@localhost/pda',
type:'error'}) type:'error'
.c('x').attrs({xmlns:'http://jabber.org/protocol/muc'}).up() }).c('x').attrs({xmlns:'http://jabber.org/protocol/muc'}).up()
.c('error').attrs({by:'lounge@localhost', type:'cancel'}) .c('error').attrs({by:'lounge@localhost', type:'cancel'})
.c('item-not-found').attrs({xmlns:'urn:ietf:params:xml:ns:xmpp-stanzas'}).nodeTree; .c('item-not-found').attrs({xmlns:'urn:ietf:params:xml:ns:xmpp-stanzas'}).nodeTree;
var view = _converse.chatboxviews.get('problematic@muc.localhost');
const view = _converse.chatboxviews.get(groupchat_jid);
spyOn(view, 'showErrorMessage').and.callThrough(); spyOn(view, 'showErrorMessage').and.callThrough();
_converse.connection._dataRecv(test_utils.createRequest(presence)); _converse.connection._dataRecv(test_utils.createRequest(presence));
expect(view.el.querySelector('.chatroom-body .disconnect-container .disconnect-msg:last-child').textContent) expect(view.el.querySelector('.chatroom-body .disconnect-container .disconnect-msg:last-child').textContent)
.toBe("This groupchat does not (yet) exist."); .toBe("This groupchat does not (yet) exist.");
done(); done();
}).catch(_.partial(console.error, _));
})); }));
it("will show an error message if the groupchat has reached its maximum number of participants", it("will show an error message if the groupchat has reached its maximum number of participants",
mock.initConverseWithPromises( mock.initConverseWithPromises(
null, ['rosterGroupsFetched'], {}, null, ['rosterGroupsFetched'], {},
function (done, _converse) { async function (done, _converse) {
test_utils.openChatRoomViaModal(_converse, 'problematic@muc.localhost', 'dummy') const groupchat_jid = 'maxed-out@muc.localhost'
.then(function () { await test_utils.openChatRoomViaModal(_converse, groupchat_jid, 'dummy')
var presence = $pres().attrs({ const presence = $pres().attrs({
from:'problematic@muc.localhost/dummy', from: `${groupchat_jid}/dummy`,
id:'n13mt3l', id: u.getUniqueId(),
to:'dummy@localhost/pda', to:'dummy@localhost/pda',
type:'error'}) type:'error'
.c('x').attrs({xmlns:'http://jabber.org/protocol/muc'}).up() }).c('x').attrs({xmlns:'http://jabber.org/protocol/muc'}).up()
.c('error').attrs({by:'lounge@localhost', type:'cancel'}) .c('error').attrs({by:'lounge@localhost', type:'cancel'})
.c('service-unavailable').attrs({xmlns:'urn:ietf:params:xml:ns:xmpp-stanzas'}).nodeTree; .c('service-unavailable').attrs({xmlns:'urn:ietf:params:xml:ns:xmpp-stanzas'}).nodeTree;
var view = _converse.chatboxviews.get('problematic@muc.localhost');
const view = _converse.chatboxviews.get(groupchat_jid);
spyOn(view, 'showErrorMessage').and.callThrough(); spyOn(view, 'showErrorMessage').and.callThrough();
_converse.connection._dataRecv(test_utils.createRequest(presence)); _converse.connection._dataRecv(test_utils.createRequest(presence));
expect(view.el.querySelector('.chatroom-body .disconnect-container .disconnect-msg:last-child').textContent) expect(view.el.querySelector('.chatroom-body .disconnect-container .disconnect-msg:last-child').textContent)
.toBe("This groupchat has reached its maximum number of participants."); .toBe("This groupchat has reached its maximum number of participants.");
done(); done();
}).catch(_.partial(console.error, _));
})); }));
}); });
......
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