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);
const xhr = {
'open': function open () {},
'send': function () {
xhr.responseText = JSON.stringify([
class MockXHR extends XMLHttpRequest {
open () {} // eslint-disable-line
responseText = ''
send () {
this.responseText = JSON.stringify([
{"jid": "marty@mcfly.net", "fullname": "Marty McFly"},
{"jid": "doc@brown.com", "fullname": "Doc Brown"}
]);
xhr.onload();
this.onload();
}
}
};
const XMLHttpRequestBackup = window.XMLHttpRequest;
window.XMLHttpRequest = jasmine.createSpy('XMLHttpRequest');
XMLHttpRequest.and.callFake(() => xhr);
window.XMLHttpRequest = MockXHR;
const cbview = _converse.chatboxviews.get('controlbox');
cbview.querySelector('.add-contact').click()
@ -315,36 +316,37 @@ describe("The 'Add Contact' widget", function () {
await mock.waitForRoster(_converse, 'all');
await mock.openControlBox(_converse);
var modal;
const xhr = {
'open': function open () {},
'send': function () {
class MockXHR extends XMLHttpRequest {
open () {} // eslint-disable-line
responseText = ''
send () {
const value = modal.el.querySelector('input[name="name"]').value;
if (value === 'existing') {
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') {
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') {
xhr.responseText = JSON.stringify([
this.responseText = JSON.stringify([
{"jid": "marty@mcfly.net", "fullname": "Marty McFly"},
{"jid": "doc@brown.com", "fullname": "Doc Brown"}
]);
} else if (value === 'insufficient') {
xhr.responseText = JSON.stringify([]);
this.responseText = JSON.stringify([]);
} 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;
window.XMLHttpRequest = jasmine.createSpy('XMLHttpRequest');
XMLHttpRequest.and.callFake(() => xhr);
window.XMLHttpRequest = MockXHR;
const cbview = _converse.chatboxviews.get('controlbox');
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);
expect(modal.jid_auto_complete).toBe(undefined);

View File

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