2018-05-10 22:42:43 +02:00
|
|
|
(function (root, factory) {
|
|
|
|
define([
|
|
|
|
"jasmine",
|
|
|
|
"mock",
|
|
|
|
"test-utils"
|
|
|
|
], factory);
|
2018-06-03 16:40:20 +02:00
|
|
|
} (this, function (jasmine, mock, test_utils) {
|
2018-05-10 22:42:43 +02:00
|
|
|
"use strict";
|
2019-02-12 14:21:45 +01:00
|
|
|
const u = converse.env.utils;
|
2018-05-10 22:42:43 +02:00
|
|
|
|
|
|
|
return describe("The User Details Modal", function () {
|
|
|
|
|
|
|
|
it("can be used to remove a contact",
|
2020-01-21 12:45:34 +01:00
|
|
|
mock.initConverse(
|
|
|
|
['rosterGroupsFetched', 'chatBoxesFetched'], {},
|
|
|
|
async function (done, _converse) {
|
2018-05-10 22:42:43 +02:00
|
|
|
|
2019-10-24 14:29:15 +02:00
|
|
|
await test_utils.waitForRoster(_converse, 'current', 1);
|
2019-03-29 21:10:45 +01:00
|
|
|
_converse.api.trigger('rosterContactsFetched');
|
2018-05-10 22:42:43 +02:00
|
|
|
|
2019-06-03 07:58:51 +02:00
|
|
|
const contact_jid = mock.cur_names[0].replace(/ /g,'.').toLowerCase() + '@montague.lit';
|
2019-10-24 14:29:15 +02:00
|
|
|
await test_utils.openChatBoxFor(_converse, contact_jid);
|
2019-07-11 22:50:30 +02:00
|
|
|
await u.waitUntil(() => _converse.chatboxes.length > 1);
|
2018-12-12 17:39:54 +01:00
|
|
|
const view = _converse.chatboxviews.get(contact_jid);
|
|
|
|
let show_modal_button = view.el.querySelector('.show-user-details-modal');
|
|
|
|
show_modal_button.click();
|
|
|
|
const modal = view.user_details_modal;
|
2019-07-11 22:50:30 +02:00
|
|
|
await u.waitUntil(() => u.isVisible(modal.el), 1000);
|
2018-12-12 17:39:54 +01:00
|
|
|
spyOn(window, 'confirm').and.returnValue(true);
|
2020-01-23 10:18:41 +01:00
|
|
|
spyOn(view.model.contact, 'removeFromRoster').and.callFake(callback => callback());
|
2018-12-12 17:39:54 +01:00
|
|
|
let remove_contact_button = modal.el.querySelector('button.remove-contact');
|
|
|
|
expect(u.isVisible(remove_contact_button)).toBeTruthy();
|
|
|
|
remove_contact_button.click();
|
2019-07-11 22:50:30 +02:00
|
|
|
await u.waitUntil(() => modal.el.getAttribute('aria-hidden'), 1000);
|
2020-02-10 11:23:55 +01:00
|
|
|
await u.waitUntil(() => !u.isVisible(modal.el));
|
2018-12-12 17:39:54 +01:00
|
|
|
show_modal_button = view.el.querySelector('.show-user-details-modal');
|
|
|
|
show_modal_button.click();
|
|
|
|
remove_contact_button = modal.el.querySelector('button.remove-contact');
|
2019-08-05 01:39:57 +02:00
|
|
|
expect(remove_contact_button === null).toBeTruthy();
|
2018-12-12 17:39:54 +01:00
|
|
|
done();
|
2018-05-10 22:42:43 +02:00
|
|
|
}));
|
|
|
|
|
|
|
|
it("shows an alert when an error happened while removing the contact",
|
2020-01-21 12:45:34 +01:00
|
|
|
mock.initConverse(['rosterGroupsFetched'], {}, async function (done, _converse) {
|
2018-05-10 22:42:43 +02:00
|
|
|
|
2019-10-24 14:29:15 +02:00
|
|
|
await test_utils.waitForRoster(_converse, 'current', 1);
|
2019-03-29 21:10:45 +01:00
|
|
|
_converse.api.trigger('rosterContactsFetched');
|
2018-05-10 22:42:43 +02:00
|
|
|
|
2019-06-03 07:58:51 +02:00
|
|
|
const contact_jid = mock.cur_names[0].replace(/ /g,'.').toLowerCase() + '@montague.lit';
|
2018-12-12 17:39:54 +01:00
|
|
|
await test_utils.openChatBoxFor(_converse, contact_jid)
|
|
|
|
const view = _converse.chatboxviews.get(contact_jid);
|
|
|
|
let show_modal_button = view.el.querySelector('.show-user-details-modal');
|
|
|
|
show_modal_button.click();
|
|
|
|
const modal = view.user_details_modal;
|
2019-07-11 22:50:30 +02:00
|
|
|
await u.waitUntil(() => u.isVisible(modal.el), 2000);
|
2018-12-12 17:39:54 +01:00
|
|
|
spyOn(window, 'confirm').and.returnValue(true);
|
2019-10-24 14:29:15 +02:00
|
|
|
|
|
|
|
spyOn(view.model.contact, 'removeFromRoster').and.callFake((callback, errback) => errback());
|
2018-12-12 17:39:54 +01:00
|
|
|
let remove_contact_button = modal.el.querySelector('button.remove-contact');
|
|
|
|
expect(u.isVisible(remove_contact_button)).toBeTruthy();
|
|
|
|
remove_contact_button.click();
|
2019-07-11 22:50:30 +02:00
|
|
|
await u.waitUntil(() => u.isVisible(document.querySelector('.alert-danger')), 2000);
|
2018-12-12 17:39:54 +01: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())
|
2019-06-03 07:58:51 +02:00
|
|
|
.toBe("Sorry, there was an error while trying to remove Mercutio as a contact.");
|
2018-12-12 17:39:54 +01:00
|
|
|
document.querySelector('.alert-danger button.close').click();
|
|
|
|
show_modal_button = view.el.querySelector('.show-user-details-modal');
|
|
|
|
show_modal_button.click();
|
2019-07-11 22:50:30 +02:00
|
|
|
await u.waitUntil(() => u.isVisible(modal.el), 2000)
|
2018-12-12 17:39:54 +01:00
|
|
|
|
|
|
|
show_modal_button = view.el.querySelector('.show-user-details-modal');
|
|
|
|
show_modal_button.click();
|
2019-07-11 22:50:30 +02:00
|
|
|
await u.waitUntil(() => u.isVisible(modal.el), 2000)
|
2018-12-12 17:39:54 +01:00
|
|
|
|
|
|
|
remove_contact_button = modal.el.querySelector('button.remove-contact');
|
|
|
|
expect(u.isVisible(remove_contact_button)).toBeTruthy();
|
|
|
|
done();
|
2018-05-10 22:42:43 +02:00
|
|
|
}));
|
|
|
|
});
|
|
|
|
}));
|