Two small changes

- Fix controlbox spec to work with newer Jasmine
- Don't import Strophe in the non-headless code
This commit is contained in:
JC Brand 2021-02-24 09:11:24 +01:00
parent c11b3d03f4
commit 4d0012f672
2 changed files with 26 additions and 23 deletions

View File

@ -259,19 +259,20 @@ describe("The 'Add Contact' widget", function () {
await mock.waitForRoster(_converse, 'all', 0); await mock.waitForRoster(_converse, 'all', 0);
const xhr = {
'open': function open () {}, class MockXHR extends XMLHttpRequest {
'send': function () { open () {} // eslint-disable-line
xhr.responseText = JSON.stringify([ responseText = ''
send () {
this.responseText = JSON.stringify([
{"jid": "marty@mcfly.net", "fullname": "Marty McFly"}, {"jid": "marty@mcfly.net", "fullname": "Marty McFly"},
{"jid": "doc@brown.com", "fullname": "Doc Brown"} {"jid": "doc@brown.com", "fullname": "Doc Brown"}
]); ]);
xhr.onload(); this.onload();
} }
}; }
const XMLHttpRequestBackup = window.XMLHttpRequest; const XMLHttpRequestBackup = window.XMLHttpRequest;
window.XMLHttpRequest = jasmine.createSpy('XMLHttpRequest'); window.XMLHttpRequest = MockXHR;
XMLHttpRequest.and.callFake(() => xhr);
const cbview = _converse.chatboxviews.get('controlbox'); const cbview = _converse.chatboxviews.get('controlbox');
cbview.querySelector('.add-contact').click() cbview.querySelector('.add-contact').click()
@ -315,36 +316,37 @@ describe("The 'Add Contact' widget", function () {
await mock.waitForRoster(_converse, 'all'); await mock.waitForRoster(_converse, 'all');
await mock.openControlBox(_converse); await mock.openControlBox(_converse);
var modal;
const xhr = { class MockXHR extends XMLHttpRequest {
'open': function open () {}, open () {} // eslint-disable-line
'send': function () { responseText = ''
send () {
const value = modal.el.querySelector('input[name="name"]').value; const value = modal.el.querySelector('input[name="name"]').value;
if (value === 'existing') { if (value === 'existing') {
const contact_jid = mock.cur_names[0].replace(/ /g,'.').toLowerCase() + '@montague.lit'; const contact_jid = mock.cur_names[0].replace(/ /g,'.').toLowerCase() + '@montague.lit';
xhr.responseText = JSON.stringify([{"jid": contact_jid, "fullname": mock.cur_names[0]}]); this.responseText = JSON.stringify([{"jid": contact_jid, "fullname": mock.cur_names[0]}]);
} else if (value === 'romeo') { } else if (value === 'romeo') {
xhr.responseText = JSON.stringify([{"jid": "romeo@montague.lit", "fullname": "Romeo Montague"}]); this.responseText = JSON.stringify([{"jid": "romeo@montague.lit", "fullname": "Romeo Montague"}]);
} else if (value === 'ambiguous') { } else if (value === 'ambiguous') {
xhr.responseText = JSON.stringify([ this.responseText = JSON.stringify([
{"jid": "marty@mcfly.net", "fullname": "Marty McFly"}, {"jid": "marty@mcfly.net", "fullname": "Marty McFly"},
{"jid": "doc@brown.com", "fullname": "Doc Brown"} {"jid": "doc@brown.com", "fullname": "Doc Brown"}
]); ]);
} else if (value === 'insufficient') { } else if (value === 'insufficient') {
xhr.responseText = JSON.stringify([]); this.responseText = JSON.stringify([]);
} else { } else {
xhr.responseText = JSON.stringify([{"jid": "marty@mcfly.net", "fullname": "Marty McFly"}]); this.responseText = JSON.stringify([{"jid": "marty@mcfly.net", "fullname": "Marty McFly"}]);
} }
xhr.onload(); this.onload();
} }
}; }
const XMLHttpRequestBackup = window.XMLHttpRequest; const XMLHttpRequestBackup = window.XMLHttpRequest;
window.XMLHttpRequest = jasmine.createSpy('XMLHttpRequest'); window.XMLHttpRequest = MockXHR;
XMLHttpRequest.and.callFake(() => xhr);
const cbview = _converse.chatboxviews.get('controlbox'); const cbview = _converse.chatboxviews.get('controlbox');
cbview.querySelector('.add-contact').click() cbview.querySelector('.add-contact').click()
modal = _converse.api.modal.get('add-contact-modal'); const modal = _converse.api.modal.get('add-contact-modal');
await u.waitUntil(() => u.isVisible(modal.el), 1000); await u.waitUntil(() => u.isVisible(modal.el), 1000);
expect(modal.jid_auto_complete).toBe(undefined); expect(modal.jid_auto_complete).toBe(undefined);

View File

@ -1,12 +1,13 @@
import BottomPanel from 'plugins/chatview/bottom_panel.js'; import BottomPanel from 'plugins/chatview/bottom_panel.js';
import debounce from 'lodash/debounce'; import debounce from 'lodash/debounce';
import tpl_muc_bottom_panel from './templates/muc_bottom_panel.js'; import tpl_muc_bottom_panel from './templates/muc_bottom_panel.js';
import { $pres, Strophe } from 'strophe.js/src/strophe';
import { __ } from 'i18n'; import { __ } from 'i18n';
import { _converse, api, converse } from "@converse/headless/core"; import { _converse, api, converse } from "@converse/headless/core";
import { getAutoCompleteListItem } from './utils.js'; import { getAutoCompleteListItem } from './utils.js';
import { render } from 'lit-html'; import { render } from 'lit-html';
const { Strophe, $pres } = converse.env;
const COMMAND_TO_AFFILIATION = { const COMMAND_TO_AFFILIATION = {
'admin': 'admin', 'admin': 'admin',