2020-12-01 18:50:35 +01:00
|
|
|
/*global mock, converse */
|
2018-05-10 22:42:43 +02:00
|
|
|
|
2020-04-22 13:11:48 +02:00
|
|
|
const u = converse.env.utils;
|
2018-05-10 22:42:43 +02:00
|
|
|
|
2020-04-22 13:11:48 +02:00
|
|
|
describe("The User Details Modal", function () {
|
2018-05-10 22:42:43 +02:00
|
|
|
|
2020-04-22 13:11:48 +02:00
|
|
|
it("can be used to remove a contact",
|
2021-06-28 12:00:47 +02:00
|
|
|
mock.initConverse(['chatBoxesFetched'], {}, async function (_converse) {
|
2018-05-10 22:42:43 +02:00
|
|
|
|
2020-04-22 13:11:48 +02:00
|
|
|
await mock.waitForRoster(_converse, 'current', 1);
|
|
|
|
_converse.api.trigger('rosterContactsFetched');
|
2018-05-10 22:42:43 +02:00
|
|
|
|
2020-04-22 13:11:48 +02:00
|
|
|
const contact_jid = mock.cur_names[0].replace(/ /g,'.').toLowerCase() + '@montague.lit';
|
|
|
|
await mock.openChatBoxFor(_converse, contact_jid);
|
|
|
|
await u.waitUntil(() => _converse.chatboxes.length > 1);
|
2020-12-08 12:54:14 +01:00
|
|
|
|
2020-04-22 13:11:48 +02:00
|
|
|
const view = _converse.chatboxviews.get(contact_jid);
|
2020-12-08 12:54:14 +01:00
|
|
|
let show_modal_button = view.querySelector('.show-user-details-modal');
|
2020-04-22 13:11:48 +02:00
|
|
|
show_modal_button.click();
|
2020-12-02 18:37:32 +01:00
|
|
|
const modal = _converse.api.modal.get('user-details-modal');
|
2020-04-22 13:11:48 +02:00
|
|
|
await u.waitUntil(() => u.isVisible(modal.el), 1000);
|
|
|
|
spyOn(window, 'confirm').and.returnValue(true);
|
|
|
|
spyOn(view.model.contact, 'removeFromRoster').and.callFake(callback => callback());
|
|
|
|
let remove_contact_button = modal.el.querySelector('button.remove-contact');
|
|
|
|
expect(u.isVisible(remove_contact_button)).toBeTruthy();
|
|
|
|
remove_contact_button.click();
|
|
|
|
await u.waitUntil(() => modal.el.getAttribute('aria-hidden'), 1000);
|
|
|
|
await u.waitUntil(() => !u.isVisible(modal.el));
|
2020-12-08 12:54:14 +01:00
|
|
|
show_modal_button = view.querySelector('.show-user-details-modal');
|
2020-04-22 13:11:48 +02:00
|
|
|
show_modal_button.click();
|
|
|
|
remove_contact_button = modal.el.querySelector('button.remove-contact');
|
|
|
|
expect(remove_contact_button === null).toBeTruthy();
|
|
|
|
}));
|
2018-05-10 22:42:43 +02:00
|
|
|
|
2020-04-22 13:11:48 +02:00
|
|
|
it("shows an alert when an error happened while removing the contact",
|
2021-06-28 12:00:47 +02:00
|
|
|
mock.initConverse([], {}, async function (_converse) {
|
2018-05-10 22:42:43 +02:00
|
|
|
|
2020-04-22 13:11:48 +02:00
|
|
|
await mock.waitForRoster(_converse, 'current', 1);
|
|
|
|
_converse.api.trigger('rosterContactsFetched');
|
2019-10-24 14:29:15 +02:00
|
|
|
|
2020-04-22 13:11:48 +02:00
|
|
|
const contact_jid = mock.cur_names[0].replace(/ /g,'.').toLowerCase() + '@montague.lit';
|
|
|
|
await mock.openChatBoxFor(_converse, contact_jid)
|
|
|
|
const view = _converse.chatboxviews.get(contact_jid);
|
2020-12-08 12:54:14 +01:00
|
|
|
let show_modal_button = view.querySelector('.show-user-details-modal');
|
2020-04-22 13:11:48 +02:00
|
|
|
show_modal_button.click();
|
2020-12-02 18:37:32 +01:00
|
|
|
let modal = _converse.api.modal.get('user-details-modal');
|
2020-04-22 13:11:48 +02:00
|
|
|
await u.waitUntil(() => u.isVisible(modal.el), 2000);
|
|
|
|
spyOn(window, 'confirm').and.returnValue(true);
|
2018-12-12 17:39:54 +01:00
|
|
|
|
2020-04-22 13:11:48 +02:00
|
|
|
spyOn(view.model.contact, 'removeFromRoster').and.callFake((callback, errback) => errback());
|
|
|
|
let remove_contact_button = modal.el.querySelector('button.remove-contact');
|
|
|
|
expect(u.isVisible(remove_contact_button)).toBeTruthy();
|
|
|
|
remove_contact_button.click();
|
2020-12-02 18:37:32 +01:00
|
|
|
await u.waitUntil(() => !u.isVisible(modal.el))
|
2020-04-22 13:11:48 +02:00
|
|
|
await u.waitUntil(() => u.isVisible(document.querySelector('.alert-danger')), 2000);
|
2018-12-12 17:39:54 +01:00
|
|
|
|
2020-04-22 13:11:48 +02:00
|
|
|
const header = document.querySelector('.alert-danger .modal-title');
|
|
|
|
expect(header.textContent).toBe("Error");
|
|
|
|
expect(u.ancestor(header, '.modal-content').querySelector('.modal-body p').textContent.trim())
|
|
|
|
.toBe("Sorry, there was an error while trying to remove Mercutio as a contact.");
|
|
|
|
document.querySelector('.alert-danger button.close').click();
|
2020-12-08 12:54:14 +01:00
|
|
|
show_modal_button = view.querySelector('.show-user-details-modal');
|
2020-04-22 13:11:48 +02:00
|
|
|
show_modal_button.click();
|
2020-12-02 18:37:32 +01:00
|
|
|
modal = _converse.api.modal.get('user-details-modal');
|
2020-04-22 13:11:48 +02:00
|
|
|
await u.waitUntil(() => u.isVisible(modal.el), 2000)
|
2018-12-12 17:39:54 +01:00
|
|
|
|
2020-12-08 12:54:14 +01:00
|
|
|
show_modal_button = view.querySelector('.show-user-details-modal');
|
2020-04-22 13:11:48 +02:00
|
|
|
show_modal_button.click();
|
|
|
|
await u.waitUntil(() => u.isVisible(modal.el), 2000)
|
|
|
|
|
|
|
|
remove_contact_button = modal.el.querySelector('button.remove-contact');
|
|
|
|
expect(u.isVisible(remove_contact_button)).toBeTruthy();
|
|
|
|
}));
|
2020-04-22 12:10:39 +02:00
|
|
|
});
|