Commit bcd39a7f authored by JC Brand's avatar JC Brand

Use utility method in tests

parent 50b77e86
...@@ -13,6 +13,7 @@ ...@@ -13,6 +13,7 @@
_ = converse.env._, _ = converse.env._,
u = converse.env.utils; u = converse.env.utils;
describe("A chat room", function () { describe("A chat room", function () {
it("can be bookmarked", mock.initConverse( it("can be bookmarked", mock.initConverse(
...@@ -186,14 +187,8 @@ ...@@ -186,14 +187,8 @@
describe("when bookmarked", function () { describe("when bookmarked", function () {
it("will use the nickname from the bookmark", mock.initConverse( it("will use the nickname from the bookmark", mock.initConverse(
['rosterGroupsFetched'], {}, ['rosterGroupsFetched'], {}, async function (done, _converse) {
async function (done, _converse) { await test_utils.waitUntilBookmarksReturned(_converse);
await test_utils.waitUntilDiscoConfirmed(
_converse, _converse.bare_jid,
[{'category': 'pubsub', 'type': 'pep'}],
['http://jabber.org/protocol/pubsub#publish-options']
);
const room_jid = 'coven@chat.shakespeare.lit'; const room_jid = 'coven@chat.shakespeare.lit';
await u.waitUntil(() => _converse.bookmarks); await u.waitUntil(() => _converse.bookmarks);
_converse.bookmarks.create({ _converse.bookmarks.create({
...@@ -346,17 +341,9 @@ ...@@ -346,17 +341,9 @@
describe("Bookmarks", function () { describe("Bookmarks", function () {
it("can be pushed from the XMPP server", mock.initConverse( it("can be pushed from the XMPP server", mock.initConverse(
['rosterGroupsFetched', 'connected'], {}, ['rosterGroupsFetched', 'connected'], {}, async function (done, _converse) {
async function (done, _converse) {
await test_utils.waitUntilDiscoConfirmed( await test_utils.waitUntilBookmarksReturned(_converse);
_converse, _converse.bare_jid,
[{'category': 'pubsub', 'type': 'pep'}],
['http://jabber.org/protocol/pubsub#publish-options']
);
await u.waitUntil(() => _converse.bookmarks);
// Emit here instead of mocking fetching of bookmarks.
_converse.api.trigger('bookmarksInitialized');
/* The stored data is automatically pushed to all of the user's /* The stored data is automatically pushed to all of the user's
* connected resources. * connected resources.
...@@ -382,7 +369,7 @@ ...@@ -382,7 +369,7 @@
* </event> * </event>
* </message> * </message>
*/ */
var stanza = $msg({ const stanza = $msg({
'from': 'romeo@montague.lit', 'from': 'romeo@montague.lit',
'to': 'romeo@montague.lit/orchard', 'to': 'romeo@montague.lit/orchard',
'type': 'headline', 'type': 'headline',
...@@ -473,6 +460,7 @@ ...@@ -473,6 +460,7 @@
}); // Purposefully exclude the <nick> element to test #1043 }); // Purposefully exclude the <nick> element to test #1043
_converse.connection._dataRecv(test_utils.createRequest(stanza)); _converse.connection._dataRecv(test_utils.createRequest(stanza));
await u.waitUntil(() => _converse.bookmarks.onBookmarksReceived.calls.count()); await u.waitUntil(() => _converse.bookmarks.onBookmarksReceived.calls.count());
await _converse.api.waitUntil('bookmarksInitialized');
expect(_converse.bookmarks.models.length).toBe(2); expect(_converse.bookmarks.models.length).toBe(2);
expect(_converse.bookmarks.findWhere({'jid': 'theplay@conference.shakespeare.lit'}).get('autojoin')).toBe(true); expect(_converse.bookmarks.findWhere({'jid': 'theplay@conference.shakespeare.lit'}).get('autojoin')).toBe(true);
expect(_converse.bookmarks.findWhere({'jid': 'another@conference.shakespeare.lit'}).get('autojoin')).toBe(false); expect(_converse.bookmarks.findWhere({'jid': 'another@conference.shakespeare.lit'}).get('autojoin')).toBe(false);
...@@ -619,21 +607,10 @@ ...@@ -619,21 +607,10 @@
async function (done, _converse) { async function (done, _converse) {
test_utils.openControlBox(); test_utils.openControlBox();
const jid = 'room@conference.example.org'; await test_utils.waitUntilBookmarksReturned(_converse);
await test_utils.waitUntilDiscoConfirmed(
_converse, _converse.bare_jid,
[{'category': 'pubsub', 'type': 'pep'}],
['http://jabber.org/protocol/pubsub#publish-options']
);
await u.waitUntil(() => _converse.bookmarks);
// XXX Create bookmarks view here, otherwise we need to mock stanza
// traffic for it to get created.
_converse.bookmarksview = new _converse.BookmarksView(
{'model': _converse.bookmarks}
);
_converse.api.trigger('bookmarksInitialized');
// Check that it's there // Check that it's there
const jid = 'room@conference.example.org';
_converse.bookmarks.create({ _converse.bookmarks.create({
'jid': jid, 'jid': jid,
'autojoin': false, 'autojoin': false,
...@@ -655,7 +632,7 @@ ...@@ -655,7 +632,7 @@
// Check that it reappears once the room is closed // Check that it reappears once the room is closed
const view = _converse.chatboxviews.get(jid); const view = _converse.chatboxviews.get(jid);
view.close(); view.close();
expect(u.hasClass('hidden', _converse.bookmarksview.el.querySelector(".available-chatroom"))).toBeFalsy(); await u.waitUntil(() => !u.hasClass('hidden', _converse.bookmarksview.el.querySelector(".available-chatroom")));
done(); done();
})); }));
}); });
......
...@@ -238,7 +238,9 @@ ...@@ -238,7 +238,9 @@
done(); done();
})); }));
it("has a method 'add' with which contacts can be added", mock.initConverse((done, _converse) => { it("has a method 'add' with which contacts can be added",
mock.initConverse(['rosterInitialized'], {}, (done, _converse) => {
test_utils.createContacts(_converse, 'current'); test_utils.createContacts(_converse, 'current');
const error = new TypeError('contacts.add: invalid jid'); const error = new TypeError('contacts.add: invalid jid');
expect(_converse.api.contacts.add).toThrow(error); expect(_converse.api.contacts.add).toThrow(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