Commit a8ed46f6 authored by JC Brand's avatar JC Brand

Use async/await in spec

parent df3118fe
...@@ -42758,7 +42758,6 @@ Strophe.Websocket.prototype = { ...@@ -42758,7 +42758,6 @@ Strophe.Websocket.prototype = {
}); });
//# sourceMappingURL=strophe.js.map //# sourceMappingURL=strophe.js.map
/***/ }), /***/ }),
/***/ "./node_modules/strophejs-plugin-ping/strophe.ping.js": /***/ "./node_modules/strophejs-plugin-ping/strophe.ping.js":
...@@ -94190,7 +94189,7 @@ __p += '\n<a class="list-item-action fa '; ...@@ -94190,7 +94189,7 @@ __p += '\n<a class="list-item-action fa ';
if (o.bookmarked) { ; if (o.bookmarked) { ;
__p += ' fa-bookmark remove-bookmark button-on '; __p += ' fa-bookmark remove-bookmark button-on ';
} else { ; } else { ;
__p += ' add-bookmark fa-bookmark-o '; __p += ' add-bookmark fa-bookmark ';
} ; } ;
__p += '"\n data-room-jid="' + __p += '"\n data-room-jid="' +
__e(o.jid) + __e(o.jid) +
...@@ -17,85 +17,77 @@ ...@@ -17,85 +17,77 @@
it("can be used to remove a contact", it("can be used to remove a contact",
mock.initConverseWithPromises( mock.initConverseWithPromises(
null, ['rosterGroupsFetched', 'chatBoxesFetched'], {}, null, ['rosterGroupsFetched', 'chatBoxesFetched'], {},
function (done, _converse) { async function (done, _converse) {
test_utils.createContacts(_converse, 'current'); test_utils.createContacts(_converse, 'current');
_converse.emit('rosterContactsFetched'); _converse.emit('rosterContactsFetched');
let view, show_modal_button, modal;
const contact_jid = mock.cur_names[0].replace(/ /g,'.').toLowerCase() + '@localhost'; const contact_jid = mock.cur_names[0].replace(/ /g,'.').toLowerCase() + '@localhost';
test_utils.openChatBoxFor(_converse, contact_jid); test_utils.openChatBoxFor(_converse, contact_jid);
return test_utils.waitUntil(() => _converse.chatboxes.length).then(() => { await test_utils.waitUntil(() => _converse.chatboxes.length);
view = _converse.chatboxviews.get(contact_jid); const view = _converse.chatboxviews.get(contact_jid);
show_modal_button = view.el.querySelector('.show-user-details-modal'); let show_modal_button = view.el.querySelector('.show-user-details-modal');
expect(u.isVisible(show_modal_button)).toBeTruthy(); expect(u.isVisible(show_modal_button)).toBeTruthy();
show_modal_button.click(); show_modal_button.click();
modal = view.user_details_modal; const modal = view.user_details_modal;
return test_utils.waitUntil(() => u.isVisible(modal.el), 1000); await test_utils.waitUntil(() => u.isVisible(modal.el), 1000);
}).then(function () {
spyOn(window, 'confirm').and.returnValue(true); spyOn(window, 'confirm').and.returnValue(true);
spyOn(view.model.contact, 'removeFromRoster').and.callFake(function (callback) { spyOn(view.model.contact, 'removeFromRoster').and.callFake(function (callback) {
callback(); callback();
}); });
const remove_contact_button = modal.el.querySelector('button.remove-contact'); let remove_contact_button = modal.el.querySelector('button.remove-contact');
expect(u.isVisible(remove_contact_button)).toBeTruthy(); expect(u.isVisible(remove_contact_button)).toBeTruthy();
remove_contact_button.click(); remove_contact_button.click();
return test_utils.waitUntil(() => modal.el.getAttribute('aria-hidden'), 1000); await test_utils.waitUntil(() => modal.el.getAttribute('aria-hidden'), 1000);
}).then(function () {
const show_modal_button = view.el.querySelector('.show-user-details-modal'); show_modal_button = view.el.querySelector('.show-user-details-modal');
show_modal_button.click(); show_modal_button.click();
const remove_contact_button = modal.el.querySelector('button.remove-contact'); remove_contact_button = modal.el.querySelector('button.remove-contact');
expect(_.isNull(remove_contact_button)).toBeTruthy(); expect(_.isNull(remove_contact_button)).toBeTruthy();
done(); done();
}).catch(_.partial(_converse.log, _, Strophe.LogLevel.FATAL));
})); }));
it("shows an alert when an error happened while removing the contact", it("shows an alert when an error happened while removing the contact",
mock.initConverseWithPromises( mock.initConverseWithPromises(
null, ['rosterGroupsFetched'], {}, null, ['rosterGroupsFetched'], {},
function (done, _converse) { async function (done, _converse) {
test_utils.createContacts(_converse, 'current'); test_utils.createContacts(_converse, 'current');
_converse.emit('rosterContactsFetched'); _converse.emit('rosterContactsFetched');
let view, modal;
const contact_jid = mock.cur_names[0].replace(/ /g,'.').toLowerCase() + '@localhost'; const contact_jid = mock.cur_names[0].replace(/ /g,'.').toLowerCase() + '@localhost';
test_utils.openChatBoxFor(_converse, contact_jid) await test_utils.openChatBoxFor(_converse, contact_jid)
.then(() => { const view = _converse.chatboxviews.get(contact_jid);
view = _converse.chatboxviews.get(contact_jid); let show_modal_button = view.el.querySelector('.show-user-details-modal');
const show_modal_button = view.el.querySelector('.show-user-details-modal');
expect(u.isVisible(show_modal_button)).toBeTruthy(); expect(u.isVisible(show_modal_button)).toBeTruthy();
show_modal_button.click(); show_modal_button.click();
modal = view.user_details_modal; const modal = view.user_details_modal;
return test_utils.waitUntil(() => u.isVisible(modal.el), 2000); await test_utils.waitUntil(() => u.isVisible(modal.el), 2000);
}).then(function () {
spyOn(window, 'confirm').and.returnValue(true); spyOn(window, 'confirm').and.returnValue(true);
spyOn(view.model.contact, 'removeFromRoster').and.callFake(function (callback, errback) { spyOn(view.model.contact, 'removeFromRoster').and.callFake(function (callback, errback) {
errback(); errback();
}); });
const remove_contact_button = modal.el.querySelector('button.remove-contact'); let remove_contact_button = modal.el.querySelector('button.remove-contact');
expect(u.isVisible(remove_contact_button)).toBeTruthy(); expect(u.isVisible(remove_contact_button)).toBeTruthy();
remove_contact_button.click(); remove_contact_button.click();
return test_utils.waitUntil(() => u.isVisible(document.querySelector('.alert-danger')), 2000); await test_utils.waitUntil(() => u.isVisible(document.querySelector('.alert-danger')), 2000);
}).then(function () {
const header = document.querySelector('.alert-danger .modal-title'); const header = document.querySelector('.alert-danger .modal-title');
expect(header.textContent).toBe("Error"); expect(header.textContent).toBe("Error");
expect(u.ancestor(header, '.modal-content').querySelector('.modal-body p').textContent.trim()) expect(u.ancestor(header, '.modal-content').querySelector('.modal-body p').textContent.trim())
.toBe("Sorry, there was an error while trying to remove Max Frankfurter as a contact."); .toBe("Sorry, there was an error while trying to remove Max Frankfurter as a contact.");
document.querySelector('.alert-danger button.close').click(); document.querySelector('.alert-danger button.close').click();
const show_modal_button = view.el.querySelector('.show-user-details-modal'); show_modal_button = view.el.querySelector('.show-user-details-modal');
show_modal_button.click(); show_modal_button.click();
return test_utils.waitUntil(() => u.isVisible(modal.el), 2000) await test_utils.waitUntil(() => u.isVisible(modal.el), 2000)
}).then(function () {
const show_modal_button = view.el.querySelector('.show-user-details-modal'); show_modal_button = view.el.querySelector('.show-user-details-modal');
show_modal_button.click(); show_modal_button.click();
const modal = view.user_details_modal; await test_utils.waitUntil(() => u.isVisible(modal.el), 2000)
return test_utils.waitUntil(() => u.isVisible(modal.el), 2000)
}).then(function () { remove_contact_button = modal.el.querySelector('button.remove-contact');
const remove_contact_button = modal.el.querySelector('button.remove-contact');
expect(u.isVisible(remove_contact_button)).toBeTruthy(); expect(u.isVisible(remove_contact_button)).toBeTruthy();
done(); done();
}).catch(_.partial(_converse.log, _, Strophe.LogLevel.FATAL));
})); }));
}); });
})); }));
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