Commit 4b270359 authored by JC Brand's avatar JC Brand

Use Karma as test runner

parent 7e23adf2
dist: xenial
dist: bionic
language: node_js
cache:
directories:
......@@ -6,7 +6,11 @@ cache:
addons:
chrome: stable
node_js:
- "10"
- "14"
install: make node_modules
before_script: make serve_bg
script: make check
services:
- xvfb
before_script:
- make serve_bg
- export DISPLAY=:99.0
script: make check ARGS=--single-run
......@@ -2,6 +2,7 @@
BABEL ?= node_modules/.bin/babel
BOOTSTRAP = ./node_modules/
BUILDDIR = ./docs
KARMA ?= ./node_modules/.bin/karma
CHROMIUM ?= ./node_modules/.bin/run-headless-chromium
CLEANCSS ?= ./node_modules/clean-css-cli/bin/cleancss --skip-rebase
ESLINT ?= ./node_modules/.bin/eslint
......@@ -197,7 +198,11 @@ eslint: node_modules
.PHONY: check
check: eslint dev
LOG_CR_VERBOSITY=INFO $(CHROMIUM) --disable-gpu --no-sandbox http://localhost:$(HTTPSERVE_PORT)/tests/index.html
$(KARMA) start karma.conf.js $(ARGS)
.PHONY: test
test:
$(KARMA) start karma.conf.js $(ARGS)
########################################################################
## Documentation
......
/* global module */
const path = require('path');
module.exports = function(config) {
config.set({
// base path that will be used to resolve all patterns (eg. files, exclude)
basePath: '',
frameworks: ['jasmine'],
files: [
{ pattern: 'dist/*.js.map', included: false },
{ pattern: 'dist/*.css.map', included: false },
{ pattern: "dist/emojis.js", served: true },
"dist/converse.js",
"dist/converse.css",
{ pattern: "dist/webfonts/**/*.*", included: false },
{ pattern: "node_modules/sinon/pkg/sinon.js", type: 'module' },
{ pattern: "tests/console-reporter.js", type: 'module' },
{ pattern: "tests/mock.js", type: 'module' },
{ pattern: "spec/spoilers.js", type: 'module' },
{ pattern: "spec/roomslist.js", type: 'module' },
{ pattern: "spec/utils.js", type: 'module' },
{ pattern: "spec/converse.js", type: 'module' },
{ pattern: "spec/bookmarks.js", type: 'module' },
{ pattern: "spec/headline.js", type: 'module' },
{ pattern: "spec/disco.js", type: 'module' },
{ pattern: "spec/protocol.js", type: 'module' },
{ pattern: "spec/presence.js", type: 'module' },
{ pattern: "spec/eventemitter.js", type: 'module' },
{ pattern: "spec/smacks.js", type: 'module' },
{ pattern: "spec/ping.js", type: 'module' },
{ pattern: "spec/push.js", type: 'module' },
{ pattern: "spec/xmppstatus.js", type: 'module' },
{ pattern: "spec/mam.js", type: 'module' },
{ pattern: "spec/omemo.js", type: 'module' },
{ pattern: "spec/controlbox.js", type: 'module' },
{ pattern: "spec/roster.js", type: 'module' },
{ pattern: "spec/chatbox.js", type: 'module' },
{ pattern: "spec/user-details-modal.js", type: 'module' },
{ pattern: "spec/messages.js", type: 'module' },
{ pattern: "spec/muc_messages.js", type: 'module' },
{ pattern: "spec/retractions.js", type: 'module' },
{ pattern: "spec/muc.js", type: 'module' },
{ pattern: "spec/modtools.js", type: 'module' },
{ pattern: "spec/room_registration.js", type: 'module' },
{ pattern: "spec/autocomplete.js", type: 'module' },
{ pattern: "spec/minchats.js", type: 'module' },
{ pattern: "spec/notification.js", type: 'module' },
{ pattern: "spec/login.js", type: 'module' },
{ pattern: "spec/register.js", type: 'module' },
{ pattern: "spec/hats.js", type: 'module' },
{ pattern: "spec/http-file-upload.js", type: 'module' },
{ pattern: "spec/emojis.js", type: 'module' },
{ pattern: "spec/xss.js", type: 'module' },
],
exclude: ['**/*.sw?'],
// preprocess matching files before serving them to the browser
// available preprocessors: https://npmjs.org/browse/keyword/karma-preprocessor
preprocessors: {},
// test results reporter to use
// possible values: 'dots', 'progress'
// available reporters: https://npmjs.org/browse/keyword/karma-reporter
reporters: ['progress', 'kjhtml'],
webpack: {
mode: 'development',
devtool: 'inline-source-map',
module: {
rules: [{
test: /\.js$/,
exclude: /(node_modules|test)/
}]
},
output: {
path: path.resolve('test'),
filename: '[name].out.js',
chunkFilename: '[id].[chunkHash].js'
}
},
port: 9876,
colors: true,
// level of logging
// possible values: config.LOG_DISABLE || config.LOG_ERROR || config.LOG_WARN || config.LOG_INFO || config.LOG_DEBUG
logLevel: config.LOG_INFO,
// enable / disable watching file and executing tests whenever any file changes
autoWatch: true,
// start these browsers
// available browser launchers: https://npmjs.org/browse/keyword/karma-launcher
browsers: ['Chrome'],
// Continuous Integration mode
// if true, Karma captures browsers, runs the tests and exits
singleRun: false,
// Concurrency level
// how many browser should be started simultaneous
concurrency: Infinity
})
}
This diff is collapsed.
window.addEventListener('converse-loaded', () => {
const mock = window.mock;
const test_utils = window.test_utils;
const $pres = converse.env.$pres;
const $msg = converse.env.$msg;
const Strophe = converse.env.Strophe;
const u = converse.env.utils;
/*global mock */
describe("The nickname autocomplete feature", function () {
const $pres = converse.env.$pres;
const $msg = converse.env.$msg;
const Strophe = converse.env.Strophe;
const u = converse.env.utils;
describe("The nickname autocomplete feature", function () {
it("shows all autocompletion options when the user presses @",
mock.initConverse(
['rosterGroupsFetched', 'chatBoxesFetched'], {},
async function (done, _converse) {
await test_utils.openAndEnterChatRoom(_converse, 'lounge@montague.lit', 'tom');
await mock.openAndEnterChatRoom(_converse, 'lounge@montague.lit', 'tom');
const view = _converse.chatboxviews.get('lounge@montague.lit');
// Nicknames from presences
['dick', 'harry'].forEach((nick) => {
_converse.connection._dataRecv(test_utils.createRequest(
_converse.connection._dataRecv(mock.createRequest(
$pres({
'to': 'tom@montague.lit/resource',
'from': `lounge@montague.lit/${nick}`
......@@ -66,7 +65,7 @@ window.addEventListener('converse-loaded', () => {
['rosterGroupsFetched', 'chatBoxesFetched'], {},
async function (done, _converse) {
await test_utils.openAndEnterChatRoom(_converse, 'lounge@montague.lit', 'romeo');
await mock.openAndEnterChatRoom(_converse, 'lounge@montague.lit', 'romeo');
const view = _converse.chatboxviews.get('lounge@montague.lit');
expect(view.model.occupants.length).toBe(1);
let presence = $pres({
......@@ -79,7 +78,7 @@ window.addEventListener('converse-loaded', () => {
'jid': 'some1@montague.lit/resource',
'role': 'participant'
});
_converse.connection._dataRecv(test_utils.createRequest(presence));
_converse.connection._dataRecv(mock.createRequest(presence));
expect(view.model.occupants.length).toBe(2);
const textarea = view.el.querySelector('textarea.chat-textarea');
......@@ -122,7 +121,7 @@ window.addEventListener('converse-loaded', () => {
'jid': 'some2@montague.lit/resource',
'role': 'participant'
});
_converse.connection._dataRecv(test_utils.createRequest(presence));
_converse.connection._dataRecv(mock.createRequest(presence));
textarea.value = "hello s s";
view.onKeyDown(tab_event);
......@@ -161,7 +160,7 @@ window.addEventListener('converse-loaded', () => {
'jid': 'z3r0@montague.lit/resource',
'role': 'participant'
});
_converse.connection._dataRecv(test_utils.createRequest(presence));
_converse.connection._dataRecv(mock.createRequest(presence));
textarea.value = "hello z";
view.onKeyDown(tab_event);
view.onKeyUp(tab_event);
......@@ -178,7 +177,7 @@ window.addEventListener('converse-loaded', () => {
['rosterGroupsFetched'], {},
async function (done, _converse) {
await test_utils.openAndEnterChatRoom(_converse, 'lounge@montague.lit', 'romeo');
await mock.openAndEnterChatRoom(_converse, 'lounge@montague.lit', 'romeo');
const view = _converse.chatboxviews.get('lounge@montague.lit');
expect(view.model.occupants.length).toBe(1);
const presence = $pres({
......@@ -191,7 +190,7 @@ window.addEventListener('converse-loaded', () => {
'jid': 'some1@montague.lit/resource',
'role': 'participant'
});
_converse.connection._dataRecv(test_utils.createRequest(presence));
_converse.connection._dataRecv(mock.createRequest(presence));
expect(view.model.occupants.length).toBe(2);
const textarea = view.el.querySelector('textarea.chat-textarea');
......@@ -213,5 +212,4 @@ window.addEventListener('converse-loaded', () => {
expect(view.el.querySelector('.suggestion-box__results li').textContent).toBe('some1');
done();
}));
});
});
This diff is collapsed.
This diff is collapsed.
window.addEventListener('converse-loaded', () => {
const mock = window.mock;
const test_utils = window.test_utils;
const _ = converse.env._,
/*global mock */
const _ = converse.env._,
$msg = converse.env.$msg,
u = converse.env.utils,
Strophe = converse.env.Strophe,
sizzle = converse.env.sizzle;
describe("The Controlbox", function () {
describe("The Controlbox", function () {
it("can be opened by clicking a DOM element with class 'toggle-controlbox'",
mock.initConverse(
......@@ -43,7 +42,7 @@ window.addEventListener('converse-loaded', () => {
spyOn(_converse.api, "trigger").and.callThrough();
spyOn(_converse.rosterview, 'update').and.callThrough();
await test_utils.openControlBox(_converse);
await mock.openControlBox(_converse);
// Adding two contacts one with Capital initials and one with small initials of same JID (Case sensitive check)
_converse.roster.create({
jid: mock.pend_names[0].replace(/ /g,'.').toLowerCase() + '@montague.lit',
......@@ -69,11 +68,11 @@ window.addEventListener('converse-loaded', () => {
['rosterGroupsFetched', 'chatBoxesFetched'], {},
async function (done, _converse) {
await test_utils.waitForRoster(_converse, 'all');
await test_utils.openControlBox(_converse);
await mock.waitForRoster(_converse, 'all');
await mock.openControlBox(_converse);
const sender_jid = mock.cur_names[0].replace(/ /g,'.').toLowerCase() + '@montague.lit';
await test_utils.openChatBoxFor(_converse, sender_jid);
await mock.openChatBoxFor(_converse, sender_jid);
await u.waitUntil(() => _converse.chatboxes.length);
const chatview = _converse.chatboxviews.get(sender_jid);
chatview.model.set({'minimized': true});
......@@ -119,7 +118,7 @@ window.addEventListener('converse-loaded', () => {
['rosterGroupsFetched'], {},
function (done, _converse) {
test_utils.openControlBox(_converse);
mock.openControlBox(_converse);
var view = _converse.xmppstatusview;
expect(u.hasClass('online', view.el.querySelector('.xmpp-status span:first-child'))).toBe(true);
expect(view.el.querySelector('.xmpp-status span.online').textContent.trim()).toBe('I am online');
......@@ -131,7 +130,7 @@ window.addEventListener('converse-loaded', () => {
['rosterGroupsFetched'], {},
async function (done, _converse) {
await test_utils.openControlBox(_converse);
await mock.openControlBox(_converse);
var cbview = _converse.chatboxviews.get('controlbox');
cbview.el.querySelector('.change-status').click()
var modal = _converse.xmppstatusview.status_modal;
......@@ -160,7 +159,7 @@ window.addEventListener('converse-loaded', () => {
['rosterGroupsFetched'], {},
async function (done, _converse) {
await test_utils.openControlBox(_converse);
await mock.openControlBox(_converse);
const cbview = _converse.chatboxviews.get('controlbox');
cbview.el.querySelector('.change-status').click()
const modal = _converse.xmppstatusview.status_modal;
......@@ -185,17 +184,17 @@ window.addEventListener('converse-loaded', () => {
done();
}));
});
});
});
describe("The 'Add Contact' widget", function () {
describe("The 'Add Contact' widget", function () {
it("opens up an add modal when you click on it",
mock.initConverse(
['rosterGroupsFetched'], {},
async function (done, _converse) {
await test_utils.waitForRoster(_converse, 'all');
await test_utils.openControlBox(_converse);
await mock.waitForRoster(_converse, 'all');
await mock.openControlBox(_converse);
const cbview = _converse.chatboxviews.get('controlbox');
cbview.el.querySelector('.add-contact').click()
......@@ -228,8 +227,8 @@ window.addEventListener('converse-loaded', () => {
['rosterGroupsFetched'], {'autocomplete_add_contact': false},
async function (done, _converse) {
await test_utils.waitForRoster(_converse, 'all', 0);
test_utils.openControlBox(_converse);
await mock.waitForRoster(_converse, 'all', 0);
mock.openControlBox(_converse);
const cbview = _converse.chatboxviews.get('controlbox');
cbview.el.querySelector('.add-contact').click()
const modal = _converse.rosterview.add_contact_modal;
......@@ -261,7 +260,7 @@ window.addEventListener('converse-loaded', () => {
{ 'xhr_user_search_url': 'http://example.org/?' },
async function (done, _converse) {
await test_utils.waitForRoster(_converse, 'all', 0);
await mock.waitForRoster(_converse, 'all', 0);
const xhr = {
'open': function open () {},
......@@ -318,8 +317,8 @@ window.addEventListener('converse-loaded', () => {
'xhr_user_search_url': 'http://example.org/?' },
async function (done, _converse) {
await test_utils.waitForRoster(_converse, 'all');
await test_utils.openControlBox(_converse);
await mock.waitForRoster(_converse, 'all');
await mock.openControlBox(_converse);
var modal;
const xhr = {
'open': function open () {},
......@@ -385,5 +384,4 @@ window.addEventListener('converse-loaded', () => {
window.XMLHttpRequest = XMLHttpRequestBackup;
done();
}));
});
});
window.addEventListener('converse-loaded', () => {
const mock = window.mock;
const test_utils = window.test_utils;
const _ = converse.env._,
u = converse.env.utils;
/* global mock */
describe("Converse", function() {
describe("Converse", function() {
describe("Authentication", function () {
......@@ -146,7 +142,7 @@ window.addEventListener('converse-loaded', () => {
expect(_converse.xmppstatus.get('status')).toBe('xa');
_converse.api.user.status.set('chat');
expect(_converse.xmppstatus.get('status')).toBe('chat');
expect(_.partial(_converse.api.user.status.set, 'invalid')).toThrow(
expect(() => _converse.api.user.status.set('invalid')).toThrow(
new Error('Invalid availability value. See https://xmpp.org/rfcs/rfc3921.html#rfc.section.2.2.2.1')
);
done();
......@@ -179,7 +175,7 @@ window.addEventListener('converse-loaded', () => {
describe("The \"tokens\" API", function () {
it("has a method for retrieving the next RID", mock.initConverse((done, _converse) => {
test_utils.createContacts(_converse, 'current');
mock.createContacts(_converse, 'current');
const old_connection = _converse.connection;
_converse.connection._proto.rid = '1234';
expect(_converse.api.tokens.get('rid')).toBe('1234');
......@@ -191,7 +187,7 @@ window.addEventListener('converse-loaded', () => {
}));
it("has a method for retrieving the SID", mock.initConverse((done, _converse) => {
test_utils.createContacts(_converse, 'current');
mock.createContacts(_converse, 'current');
const old_connection = _converse.connection;
_converse.connection._proto.sid = '1234';
expect(_converse.api.tokens.get('sid')).toBe('1234');
......@@ -208,7 +204,7 @@ window.addEventListener('converse-loaded', () => {
it("has a method 'get' which returns wrapped contacts",
mock.initConverse([], {}, async function (done, _converse) {
await test_utils.waitForRoster(_converse, 'current');
await mock.waitForRoster(_converse, 'current');
let contact = await _converse.api.contacts.get('non-existing@jabber.org');
expect(contact).toBeFalsy();
// Check when a single jid is given
......@@ -231,7 +227,7 @@ window.addEventListener('converse-loaded', () => {
it("has a method 'add' with which contacts can be added",
mock.initConverse(['rosterInitialized'], {}, async (done, _converse) => {
await test_utils.waitForRoster(_converse, 'current', 0);
await mock.waitForRoster(_converse, 'current', 0);
try {
await _converse.api.contacts.add();
throw new Error('Call should have failed');
......@@ -258,8 +254,10 @@ window.addEventListener('converse-loaded', () => {
['rosterInitialized', 'chatBoxesInitialized'], {},
async (done, _converse) => {
await test_utils.openControlBox(_converse);
await test_utils.waitForRoster(_converse, 'current', 2);
const u = converse.env.utils;
await mock.openControlBox(_converse);
await mock.waitForRoster(_converse, 'current', 2);
// Test on chat that doesn't exist.
let chat = await _converse.api.chats.get('non-existing@jabber.org');
......@@ -280,7 +278,7 @@ window.addEventListener('converse-loaded', () => {
const view = _converse.chatboxviews.get(jid);
await u.waitUntil(() => u.isVisible(view.el));
// Test for multiple JIDs
test_utils.openChatBoxFor(_converse, jid2);
mock.openChatBoxFor(_converse, jid2);
await u.waitUntil(() => _converse.chatboxes.length == 3);
const list = await _converse.api.chats.get([jid, jid2]);
expect(Array.isArray(list)).toBeTruthy();
......@@ -293,8 +291,9 @@ window.addEventListener('converse-loaded', () => {
['rosterGroupsFetched', 'chatBoxesInitialized'], {},
async (done, _converse) => {
await test_utils.openControlBox(_converse);
await test_utils.waitForRoster(_converse, 'current', 2);
const u = converse.env.utils;
await mock.openControlBox(_converse);
await mock.waitForRoster(_converse, 'current', 2);
const jid = mock.cur_names[0].replace(/ /g,'.').toLowerCase() + '@montague.lit';
const jid2 = mock.cur_names[1].replace(/ /g,'.').toLowerCase() + '@montague.lit';
......@@ -324,7 +323,7 @@ window.addEventListener('converse-loaded', () => {
it("has methods 'get' and 'set' to set configuration settings",
mock.initConverse(null, {'play_sounds': true}, (done, _converse) => {
expect(_.keys(_converse.api.settings)).toEqual(["update", "get", "set"]);
expect(Object.keys(_converse.api.settings)).toEqual(["update", "get", "set"]);
expect(_converse.api.settings.get("play_sounds")).toBe(true);
_converse.api.settings.set("play_sounds", false);
expect(_converse.api.settings.get("play_sounds")).toBe(false);
......@@ -340,14 +339,14 @@ window.addEventListener('converse-loaded', () => {
describe("The \"plugins\" API", function() {
it("only has a method 'add' for registering plugins", mock.initConverse((done, _converse) => {
expect(_.keys(converse.plugins)).toEqual(["add"]);
expect(Object.keys(converse.plugins)).toEqual(["add"]);
// Cheating a little bit. We clear the plugins to test more easily.
const _old_plugins = _converse.pluggable.plugins;
_converse.pluggable.plugins = [];
converse.plugins.add('plugin1', {});
expect(_.keys(_converse.pluggable.plugins)).toEqual(['plugin1']);
expect(Object.keys(_converse.pluggable.plugins)).toEqual(['plugin1']);
converse.plugins.add('plugin2', {});
expect(_.keys(_converse.pluggable.plugins)).toEqual(['plugin1', 'plugin2']);
expect(Object.keys(_converse.pluggable.plugins)).toEqual(['plugin1', 'plugin2']);
_converse.pluggable.plugins = _old_plugins;
done();
}));
......@@ -358,10 +357,9 @@ window.addEventListener('converse-loaded', () => {
converse.plugins.add('myplugin', {});
const error = new TypeError('Error: plugin with name "myplugin" has already been registered!');
expect(_.partial(converse.plugins.add, 'myplugin', {})).toThrow(error);
expect(() => converse.plugins.add('myplugin', {})).toThrow(error);
done();
}));
});
});
});
});
window.addEventListener('converse-loaded', () => {
const mock = window.mock;
const test_utils = window.test_utils;
const Strophe = converse.env.Strophe;
const $iq = converse.env.$iq;
const _ = converse.env._;
const u = converse.env.utils;
/*global mock */
describe("Service Discovery", function () {
describe("Service Discovery", function () {
describe("Whenever converse.js queries a server for its features", function () {
......@@ -15,10 +9,11 @@ window.addEventListener('converse-loaded', () => {
['discoInitialized'], {},
async function (done, _converse) {
const { u, $iq } = converse.env;
const IQ_stanzas = _converse.connection.IQ_stanzas;
const IQ_ids = _converse.connection.IQ_ids;
await u.waitUntil(function () {
return _.filter(IQ_stanzas, function (iq) {
return IQ_stanzas.filter(function (iq) {
return iq.querySelector('iq[to="montague.lit"] query[xmlns="http://jabber.org/protocol/disco#info"]');
}).length > 0;
});
......@@ -48,7 +43,7 @@ window.addEventListener('converse-loaded', () => {
* </query>
* </iq>
*/
let stanza = _.find(IQ_stanzas, function (iq) {
let stanza = IQ_stanzas.find(function (iq) {
return iq.querySelector('iq[to="montague.lit"] query[xmlns="http://jabber.org/protocol/disco#info"]');
});
const info_IQ_id = IQ_ids[IQ_stanzas.indexOf(stanza)];
......@@ -79,7 +74,7 @@ window.addEventListener('converse-loaded', () => {
'var': 'jabber:iq:time'}).up()
.c('feature', {
'var': 'jabber:iq:version'});
_converse.connection._dataRecv(test_utils.createRequest(stanza));
_converse.connection._dataRecv(mock.createRequest(stanza));
let entities = await _converse.api.disco.entities.get()
expect(entities.length).toBe(2); // We have an extra entity, which is the user's JID
......@@ -96,9 +91,7 @@ window.addEventListener('converse-loaded', () => {
await u.waitUntil(function () {
// Converse.js sees that the entity has a disco#items feature,
// so it will make a query for it.
return _.filter(IQ_stanzas, function (iq) {
return iq.querySelector('query[xmlns="http://jabber.org/protocol/disco#items"]');
}).length > 0;
return IQ_stanzas.filter(iq => iq.querySelector('query[xmlns="http://jabber.org/protocol/disco#items"]')).length > 0;
});
/* <iq type='result'
* from='catalog.shakespeare.lit'
......@@ -126,10 +119,10 @@ window.addEventListener('converse-loaded', () => {
* </query>
* </iq>
*/
stanza = _.find(IQ_stanzas, function (iq) {
stanza = IQ_stanzas.find(function (iq) {
return iq.querySelector('iq[to="montague.lit"] query[xmlns="http://jabber.org/protocol/disco#items"]');
});
var items_IQ_id = IQ_ids[IQ_stanzas.indexOf(stanza)];
const items_IQ_id = IQ_ids[IQ_stanzas.indexOf(stanza)];
stanza = $iq({
'type': 'result',
'from': 'montague.lit',
......@@ -158,14 +151,14 @@ window.addEventListener('converse-loaded', () => {
'node': 'music',
'name': 'Music from the time of Shakespeare'
});
_converse.connection._dataRecv(test_utils.createRequest(stanza));
_converse.connection._dataRecv(mock.createRequest(stanza));
await u.waitUntil(() => _converse.disco_entities);
entities = _converse.disco_entities;
expect(entities.length).toBe(2); // We have an extra entity, which is the user's JID
expect(entities.get(_converse.domain).items.length).toBe(3);
expect(_.includes(entities.get(_converse.domain).items.pluck('jid'), 'people.shakespeare.lit')).toBeTruthy();
expect(_.includes(entities.get(_converse.domain).items.pluck('jid'), 'plays.shakespeare.lit')).toBeTruthy();
expect(_.includes(entities.get(_converse.domain).items.pluck('jid'), 'words.shakespeare.lit')).toBeTruthy();
expect(entities.get(_converse.domain).items.pluck('jid').includes('people.shakespeare.lit')).toBeTruthy();
expect(entities.get(_converse.domain).items.pluck('jid').includes('plays.shakespeare.lit')).toBeTruthy();
expect(entities.get(_converse.domain).items.pluck('jid').includes('words.shakespeare.lit')).toBeTruthy();
expect(entities.get(_converse.domain).identities.where({'category': 'conference'}).length).toBe(1);
expect(entities.get(_converse.domain).identities.where({'category': 'directory'}).length).toBe(1);
done();
......@@ -178,6 +171,7 @@ window.addEventListener('converse-loaded', () => {
['discoInitialized'], {},
function (done, _converse) {
const { Strophe } = converse.env;
sinon.spy(_converse.api, "trigger");
_converse.disco_entities.get(_converse.domain).features.create({'var': Strophe.NS.MAM});
expect(_converse.api.trigger.called).toBe(true);
......@@ -186,5 +180,4 @@ window.addEventListener('converse-loaded', () => {
done();
}));
});
});
});
window.addEventListener('converse-loaded', () => {
const mock = window.mock;
const test_utils = window.test_utils;
const { Promise, $msg, $pres, sizzle } = converse.env;
const u = converse.env.utils;
/*global mock */
describe("Emojis", function () {
const { Promise, $msg, $pres, sizzle } = converse.env;
const u = converse.env.utils;
describe("Emojis", function () {
describe("The emoji picker", function () {
it("can be opened by clicking a button in the chat toolbar",
......@@ -13,9 +12,9 @@ window.addEventListener('converse-loaded', () => {
async function (done, _converse) {
const contact_jid = mock.cur_names[2].replace(/ /g,'.').toLowerCase() + '@montague.lit';
await test_utils.waitForRoster(_converse, 'current');
await test_utils.openControlBox(_converse);
await test_utils.openChatBoxFor(_converse, contact_jid);
await mock.waitForRoster(_converse, 'current');
await mock.openControlBox(_converse);
await mock.openChatBoxFor(_converse, contact_jid);
const view = _converse.chatboxviews.get(contact_jid);
const toolbar = await u.waitUntil(() => view.el.querySelector('ul.chat-toolbar'));
expect(toolbar.querySelectorAll('li.toggle-smiley__container').length).toBe(1);
......@@ -35,7 +34,7 @@ window.addEventListener('converse-loaded', () => {
async function (done, _converse) {
const muc_jid = 'lounge@montague.lit';
await test_utils.openAndEnterChatRoom(_converse, muc_jid, 'romeo');
await mock.openAndEnterChatRoom(_converse, muc_jid, 'romeo');
const view = _converse.chatboxviews.get(muc_jid);
const textarea = view.el.querySelector('textarea.chat-textarea');
......@@ -85,7 +84,7 @@ window.addEventListener('converse-loaded', () => {
'affiliation': 'member',
'role': 'participant'
});
_converse.connection._dataRecv(test_utils.createRequest(presence));
_converse.connection._dataRecv(mock.createRequest(presence));
textarea.value = ':use';
view.onKeyDown(tab_event);
......@@ -104,7 +103,7 @@ window.addEventListener('converse-loaded', () => {
async function (done, _converse) {
const muc_jid = 'lounge@montague.lit';
await test_utils.openAndEnterChatRoom(_converse, muc_jid, 'romeo');
await mock.openAndEnterChatRoom(_converse, muc_jid, 'romeo');
const view = _converse.chatboxviews.get(muc_jid);
const toolbar = view.el.querySelector('ul.chat-toolbar');
......@@ -156,7 +155,7 @@ window.addEventListener('converse-loaded', () => {
['rosterGroupsFetched', 'chatBoxesFetched'], {'use_system_emojis': true},
async function (done, _converse) {
await test_utils.waitForRoster(_converse, 'current');
await mock.waitForRoster(_converse, 'current');
const sender_jid = mock.cur_names[1].replace(/ /g,'.').toLowerCase() + '@montague.lit';
_converse.handleMessageStanza($msg({
'from': sender_jid,
......@@ -234,5 +233,4 @@ window.addEventListener('converse-loaded', () => {
done()
}));
});
});
});
window.addEventListener('converse-loaded', () => {
const mock = window.mock;
/*global mock */
return describe("The _converse Event Emitter", function() {
describe("The _converse Event Emitter", function() {
it("allows you to subscribe to emitted events", mock.initConverse((done, _converse) => {
this.callback = function () {};
......@@ -59,5 +58,4 @@ window.addEventListener('converse-loaded', () => {
expect(this.neverCalled).not.toHaveBeenCalled();
done();
}));
});
});
window.addEventListener('converse-loaded', () => {
const mock = window.mock;
const test_utils = window.test_utils;
const u = converse.env.utils;
/*global mock */
describe("A XEP-0317 MUC Hat", function () {
const u = converse.env.utils;
describe("A XEP-0317 MUC Hat", function () {
it("can be included in a presence stanza",
mock.initConverse(
......@@ -11,11 +10,11 @@ window.addEventListener('converse-loaded', () => {
async function (done, _converse) {
const muc_jid = 'lounge@montague.lit';
await test_utils.openAndEnterChatRoom(_converse, muc_jid, 'romeo');
await mock.openAndEnterChatRoom(_converse, muc_jid, 'romeo');
const view = _converse.chatboxviews.get(muc_jid);
const hat1_id = u.getUniqueId();
const hat2_id = u.getUniqueId();
_converse.connection._dataRecv(test_utils.createRequest(u.toStanza(`
_converse.connection._dataRecv(mock.createRequest(u.toStanza(`
<presence from="${muc_jid}/Terry" id="${u.getUniqueId()}" to="${_converse.jid}">
<x xmlns="http://jabber.org/protocol/muc#user">
<item affiliation="member" role="participant"/>
......@@ -33,7 +32,7 @@ window.addEventListener('converse-loaded', () => {
expect(hats.length).toBe(2);
expect(hats.map(h => h.title).join(' ')).toBe("Teacher's Assistant Dark Mage");
_converse.connection._dataRecv(test_utils.createRequest(u.toStanza(`
_converse.connection._dataRecv(mock.createRequest(u.toStanza(`
<message type="groupchat" from="${muc_jid}/Terry" id="${u.getUniqueId()}" to="${_converse.jid}">
<body>Hello world</body>
</message>
......@@ -45,7 +44,7 @@ window.addEventListener('converse-loaded', () => {
expect(badges.map(b => b.textContent.trim()).join(' ' )).toBe("Teacher's Assistant Dark Mage");
const hat3_id = u.getUniqueId();
_converse.connection._dataRecv(test_utils.createRequest(u.toStanza(`
_converse.connection._dataRecv(mock.createRequest(u.toStanza(`
<presence from="${muc_jid}/Terry" id="${u.getUniqueId()}" to="${_converse.jid}">
<x xmlns="http://jabber.org/protocol/muc#user">
<item affiliation="member" role="participant"/>
......@@ -65,7 +64,7 @@ window.addEventListener('converse-loaded', () => {
badges = Array.from(view.el.querySelectorAll('.chat-msg .badge'));
expect(badges.map(b => b.textContent.trim()).join(' ' )).toBe("Teacher's Assistant Dark Mage Mad hatter");
_converse.connection._dataRecv(test_utils.createRequest(u.toStanza(`
_converse.connection._dataRecv(mock.createRequest(u.toStanza(`
<presence from="${muc_jid}/Terry" id="${u.getUniqueId()}" to="${_converse.jid}">
<x xmlns="http://jabber.org/protocol/muc#user">
<item affiliation="member" role="participant"/>
......@@ -76,5 +75,4 @@ window.addEventListener('converse-loaded', () => {
await u.waitUntil(() => view.el.querySelectorAll('.chat-msg .badge').length === 0);
done();
}));
})
});
})
window.addEventListener('converse-loaded', () => {
const mock = window.mock;
const test_utils = window.test_utils;
const $msg = converse.env.$msg,
_ = converse.env._,
u = converse.env.utils;
/*global mock */
describe("A headlines box", function () {
describe("A headlines box", function () {
it("will not open nor display non-headline messages",
mock.initConverse(
['rosterGroupsFetched', 'chatBoxesFetched'], {}, function (done, _converse) {
const { u, $msg} = converse.env;
/* XMPP spam message:
*
* <message xmlns="jabber:client"
......@@ -30,7 +26,7 @@ window.addEventListener('converse-loaded', () => {
})
.c('nick', {'xmlns': "http://jabber.org/protocol/nick"}).t("-wwdmz").up()
.c('body').t('SORRY FOR THIS ADVERT');
_converse.connection._dataRecv(test_utils.createRequest(stanza));
_converse.connection._dataRecv(mock.createRequest(stanza));
expect(u.isHeadlineMessage.called).toBeTruthy();
expect(u.isHeadlineMessage.returned(false)).toBeTruthy();
expect(_converse.api.headlines.get().length === 0);
......@@ -41,6 +37,7 @@ window.addEventListener('converse-loaded', () => {
it("will open and display headline messages", mock.initConverse(
['rosterGroupsFetched'], {}, async function (done, _converse) {
const { u, $msg} = converse.env;
/* <message from='notify.example.com'
* to='romeo@im.example.com'
* type='headline'
......@@ -66,7 +63,7 @@ window.addEventListener('converse-loaded', () => {
.c('x', {'xmlns': 'jabber:x:oob'})
.c('url').t('imap://romeo@example.com/INBOX;UIDVALIDITY=385759043/;UID=18');
_converse.connection._dataRecv(test_utils.createRequest(stanza));
_converse.connection._dataRecv(mock.createRequest(stanza));
await u.waitUntil(() => _converse.chatboxviews.keys().includes('notify.example.com'));
expect(u.isHeadlineMessage.called).toBeTruthy();
expect(u.isHeadlineMessage.returned(true)).toBeTruthy();
......@@ -80,6 +77,7 @@ window.addEventListener('converse-loaded', () => {
it("will show headline messages in the controlbox", mock.initConverse(
['rosterGroupsFetched'], {}, async function (done, _converse) {
const { u, $msg} = converse.env;
/* <message from='notify.example.com'
* to='romeo@im.example.com'
* type='headline'
......@@ -104,7 +102,7 @@ window.addEventListener('converse-loaded', () => {
.c('x', {'xmlns': 'jabber:x:oob'})
.c('url').t('imap://romeo@example.com/INBOX;UIDVALIDITY=385759043/;UID=18');
_converse.connection._dataRecv(test_utils.createRequest(stanza));
_converse.connection._dataRecv(mock.createRequest(stanza));
const view = _converse.chatboxviews.get('controlbox');
await u.waitUntil(() => view.el.querySelectorAll(".open-headline").length);
expect(view.el.querySelectorAll('.open-headline').length).toBe(1);
......@@ -115,7 +113,8 @@ window.addEventListener('converse-loaded', () => {
it("will remove headline messages from the controlbox if closed", mock.initConverse(
['rosterGroupsFetched'], {}, async function (done, _converse) {
await test_utils.openControlBox(_converse);
const { u, $msg} = converse.env;
await mock.openControlBox(_converse);
/* <message from='notify.example.com'
* to='romeo@im.example.com'
* type='headline'
......@@ -140,7 +139,7 @@ window.addEventListener('converse-loaded', () => {
.c('x', {'xmlns': 'jabber:x:oob'})
.c('url').t('imap://romeo@example.com/INBOX;UIDVALIDITY=385759043/;UID=18');
_converse.connection._dataRecv(test_utils.createRequest(stanza));
_converse.connection._dataRecv(mock.createRequest(stanza));
const cbview = _converse.chatboxviews.get('controlbox');
await u.waitUntil(() => cbview.el.querySelectorAll(".open-headline").length);
const hlview = _converse.chatboxviews.get('notify.example.com');
......@@ -156,6 +155,7 @@ window.addEventListener('converse-loaded', () => {
mock.initConverse(
['rosterGroupsFetched', 'chatBoxesFetched'], {}, function (done, _converse) {
const { u, $msg, _ } = converse.env;
_converse.allow_non_roster_messaging = false;
sinon.spy(u, 'isHeadlineMessage');
const stanza = $msg({
......@@ -166,12 +166,11 @@ window.addEventListener('converse-loaded', () => {
})
.c('nick').t('gpocy').up()
.c('body').t('Здравствуйте друзья');
_converse.connection._dataRecv(test_utils.createRequest(stanza));
_converse.connection._dataRecv(mock.createRequest(stanza));
expect(_.without('controlbox', _converse.chatboxviews.keys()).length).toBe(0);
expect(u.isHeadlineMessage.called).toBeTruthy();
expect(u.isHeadlineMessage.returned(true)).toBeTruthy();
u.isHeadlineMessage.restore(); // unwraps
done();
}));
});
});
This diff is collapsed.
window.addEventListener('converse-loaded', () => {
const mock = window.mock;
const test_utils = window.test_utils;
const u = converse.env.utils;
/*global mock */
describe("The Login Form", function () {
const u = converse.env.utils;
describe("The Login Form", function () {
it("contains a checkbox to indicate whether the computer is trusted or not",
mock.initConverse(
......@@ -12,7 +11,7 @@ window.addEventListener('converse-loaded', () => {
allow_registration: false },
async function (done, _converse) {
test_utils.openControlBox(_converse);
mock.openControlBox(_converse);
const cbview = await u.waitUntil(() => _converse.chatboxviews.get('controlbox'));
const checkboxes = cbview.el.querySelectorAll('input[type="checkbox"]');
expect(checkboxes.length).toBe(1);
......@@ -50,7 +49,7 @@ window.addEventListener('converse-loaded', () => {
u.waitUntil(() => _converse.chatboxviews.get('controlbox'))
.then(() => {
var cbview = _converse.chatboxviews.get('controlbox');
test_utils.openControlBox(_converse);
mock.openControlBox(_converse);
const checkboxes = cbview.el.querySelectorAll('input[type="checkbox"]');
expect(checkboxes.length).toBe(1);
......@@ -75,5 +74,4 @@ window.addEventListener('converse-loaded', () => {
done();
});
}));
});
});
This diff is collapsed.
This diff is collapsed.
window.addEventListener('converse-loaded', () => {
const mock = window.mock;
const test_utils = window.test_utils;
const _ = converse.env._;
const $msg = converse.env.$msg;
const u = converse.env.utils;
/*global mock */
describe("The Minimized Chats Widget", function () {
const _ = converse.env._;
const $msg = converse.env.$msg;
const u = converse.env.utils;
describe("The Minimized Chats Widget", function () {
it("shows chats that have been minimized",
mock.initConverse(
['rosterGroupsFetched'], {},
async function (done, _converse) {
await test_utils.waitForRoster(_converse, 'current');
await test_utils.openControlBox(_converse);
await mock.waitForRoster(_converse, 'current');
await mock.openControlBox(_converse);
_converse.minimized_chats.initToggle();
let contact_jid = mock.cur_names[0].replace(/ /g,'.').toLowerCase() + '@montague.lit';
await test_utils.openChatBoxFor(_converse, contact_jid)
await mock.openChatBoxFor(_converse, contact_jid)
let chatview = _converse.chatboxviews.get(contact_jid);
expect(chatview.model.get('minimized')).toBeFalsy();
expect(u.isVisible(_converse.minimized_chats.el)).toBe(false);
......@@ -28,7 +27,7 @@ window.addEventListener('converse-loaded', () => {
expect(_converse.minimized_chats.keys()[0]).toBe(contact_jid);
contact_jid = mock.cur_names[1].replace(/ /g,'.').toLowerCase() + '@montague.lit';
await test_utils.openChatBoxFor(_converse, contact_jid);
await mock.openChatBoxFor(_converse, contact_jid);
chatview = _converse.chatboxviews.get(contact_jid);
expect(chatview.model.get('minimized')).toBeFalsy();
chatview.el.querySelector('.toggle-chatbox-button').click();
......@@ -44,12 +43,12 @@ window.addEventListener('converse-loaded', () => {
['rosterGroupsFetched'], {},
async function (done, _converse) {
await test_utils.waitForRoster(_converse, 'current');
await test_utils.openControlBox(_converse);
await mock.waitForRoster(_converse, 'current');
await mock.openControlBox(_converse);
_converse.minimized_chats.initToggle();
const contact_jid = mock.cur_names[0].replace(/ /g,'.').toLowerCase() + '@montague.lit';
await test_utils.openChatBoxFor(_converse, contact_jid);
await mock.openChatBoxFor(_converse, contact_jid);
const chatview = _converse.chatboxviews.get(contact_jid);
expect(u.isVisible(_converse.minimized_chats.el)).toBeFalsy();
chatview.model.set({'minimized': true});
......@@ -69,8 +68,8 @@ window.addEventListener('converse-loaded', () => {
['rosterGroupsFetched', 'chatBoxesFetched'], {},
async function (done, _converse) {
await test_utils.waitForRoster(_converse, 'current', 4);
await test_utils.openControlBox(_converse);
await mock.waitForRoster(_converse, 'current', 4);
await mock.openControlBox(_converse);
_converse.minimized_chats.initToggle();
var i, contact_jid, chatview, msg;
......@@ -81,7 +80,7 @@ window.addEventListener('converse-loaded', () => {
for (i=0; i<3; i++) {
contact_jid = mock.cur_names[i].replace(/ /g,'.').toLowerCase() + '@montague.lit';
test_utils.openChatBoxFor(_converse, contact_jid);
mock.openChatBoxFor(_converse, contact_jid);
}
await u.waitUntil(() => _converse.chatboxes.length == 4);
......@@ -146,7 +145,7 @@ window.addEventListener('converse-loaded', () => {
async function (done, _converse) {
const muc_jid = 'kitchen@conference.shakespeare.lit';
await test_utils.openAndEnterChatRoom(_converse, 'kitchen@conference.shakespeare.lit', 'fires');
await mock.openAndEnterChatRoom(_converse, 'kitchen@conference.shakespeare.lit', 'fires');
const view = _converse.chatboxviews.get(muc_jid);
view.model.set({'minimized': true});
const message = 'fires: Your attention is required';
......@@ -163,5 +162,4 @@ window.addEventListener('converse-loaded', () => {
expect(_converse.minimized_chats.toggleview.el.querySelector('.unread-message-count').textContent).toBe('1');
done();
}));
});
});
window.addEventListener('converse-loaded', () => {
const mock = window.mock;
const test_utils = window.test_utils;
const _ = converse.env._;
const $iq = converse.env.$iq;
const $pres = converse.env.$pres;
const sizzle = converse.env.sizzle;
const Strophe = converse.env.Strophe;
const u = converse.env.utils;
describe("The groupchat moderator tool", function () {
/*global mock */
const _ = converse.env._;
const $iq = converse.env.$iq;
const $pres = converse.env.$pres;
const sizzle = converse.env.sizzle;
const Strophe = converse.env.Strophe;
const u = converse.env.utils;
describe("The groupchat moderator tool", function () {
it("allows you to set affiliations and roles",
mock.initConverse(
......@@ -25,7 +24,7 @@ window.addEventListener('converse-loaded', () => {
{'jid': 'crone1@shakespeare.lit', 'nick': 'thirdwitch', 'affiliation': 'owner'},
{'jid': 'romeo@montague.lit', 'nick': 'romeo', 'affiliation': 'owner'},
];
await test_utils.openAndEnterChatRoom(_converse, muc_jid, 'romeo', [], members);
await mock.openAndEnterChatRoom(_converse, muc_jid, 'romeo', [], members);
const view = _converse.chatboxviews.get(muc_jid);
await u.waitUntil(() => (view.model.occupants.length === 5), 1000);
......@@ -98,7 +97,7 @@ window.addEventListener('converse-loaded', () => {
'from': view.model.get('jid'),
'to': _converse.connection.jid
});
_converse.connection._dataRecv(test_utils.createRequest(stanza));
_converse.connection._dataRecv(mock.createRequest(stanza));
await u.waitUntil(() => view.model.occupants.fetchMembers.calls.count());
members = [
......@@ -108,7 +107,7 @@ window.addEventListener('converse-loaded', () => {
{'jid': 'crone1@shakespeare.lit', 'nick': 'thirdwitch', 'affiliation': 'admin'},
{'jid': 'romeo@montague.lit', 'nick': 'romeo', 'affiliation': 'owner'},
];
await test_utils.returnMemberLists(_converse, muc_jid, members);
await mock.returnMemberLists(_converse, muc_jid, members);
await u.waitUntil(() => view.model.occupants.pluck('affiliation').filter(o => o === 'owner').length === 1);
const alert = modal.el.querySelector('.alert-primary');
expect(alert.textContent.trim()).toBe('Affiliation changed');
......@@ -153,7 +152,7 @@ window.addEventListener('converse-loaded', () => {
{'jid': 'romeo@montague.lit', 'nick': 'romeo', 'affiliation': 'member'},
{'jid': 'juliet@capulet.lit', 'nick': 'juliet', 'affiliation': 'member'},
];
await test_utils.openAndEnterChatRoom(_converse, muc_jid, 'romeo', [], members);
await mock.openAndEnterChatRoom(_converse, muc_jid, 'romeo', [], members);
const view = _converse.chatboxviews.get(muc_jid);
await u.waitUntil(() => (view.model.occupants.length === 6), 1000);
......@@ -203,10 +202,10 @@ window.addEventListener('converse-loaded', () => {
spyOn(_converse.ChatRoomView.prototype, 'showModeratorToolsModal').and.callThrough();
const muc_jid = 'lounge@montague.lit';
await test_utils.openAndEnterChatRoom(_converse, muc_jid, 'romeo', []);
await mock.openAndEnterChatRoom(_converse, muc_jid, 'romeo', []);
const view = _converse.chatboxviews.get(muc_jid);
_converse.connection._dataRecv(test_utils.createRequest(
_converse.connection._dataRecv(mock.createRequest(
$pres({to: _converse.jid, from: `${muc_jid}/nomorenicks`})
.c('x', {xmlns: Strophe.NS.MUC_USER})
.c('item', {
......@@ -215,7 +214,7 @@ window.addEventListener('converse-loaded', () => {
'role': 'participant'
})
));
_converse.connection._dataRecv(test_utils.createRequest(
_converse.connection._dataRecv(mock.createRequest(
$pres({to: _converse.jid, from: `${muc_jid}/newb`})
.c('x', {xmlns: Strophe.NS.MUC_USER})
.c('item', {
......@@ -224,7 +223,7 @@ window.addEventListener('converse-loaded', () => {
'role': 'participant'
})
));
_converse.connection._dataRecv(test_utils.createRequest(
_converse.connection._dataRecv(mock.createRequest(
$pres({to: _converse.jid, from: `${muc_jid}/some1`})
.c('x', {xmlns: Strophe.NS.MUC_USER})
.c('item', {
......@@ -233,7 +232,7 @@ window.addEventListener('converse-loaded', () => {
'role': 'participant'
})
));
_converse.connection._dataRecv(test_utils.createRequest(
_converse.connection._dataRecv(mock.createRequest(
$pres({to: _converse.jid, from: `${muc_jid}/oldhag`})
.c('x', {xmlns: Strophe.NS.MUC_USER})
.c('item', {
......@@ -242,7 +241,7 @@ window.addEventListener('converse-loaded', () => {
'role': 'participant'
})
));
_converse.connection._dataRecv(test_utils.createRequest(
_converse.connection._dataRecv(mock.createRequest(
$pres({to: _converse.jid, from: `${muc_jid}/crone`})
.c('x', {xmlns: Strophe.NS.MUC_USER})
.c('item', {
......@@ -251,7 +250,7 @@ window.addEventListener('converse-loaded', () => {
'role': 'participant'
})
));
_converse.connection._dataRecv(test_utils.createRequest(
_converse.connection._dataRecv(mock.createRequest(
$pres({to: _converse.jid, from: `${muc_jid}/tux`})
.c('x', {xmlns: Strophe.NS.MUC_USER})
.c('item', {
......@@ -321,7 +320,7 @@ window.addEventListener('converse-loaded', () => {
{'jid': 'crone1@shakespeare.lit', 'nick': 'thirdwitch', 'affiliation': 'owner'},
{'jid': 'romeo@montague.lit', 'nick': 'romeo', 'affiliation': 'owner'},
];
await test_utils.openAndEnterChatRoom(_converse, muc_jid, 'romeo', [], members);
await mock.openAndEnterChatRoom(_converse, muc_jid, 'romeo', [], members);
const view = _converse.chatboxviews.get(muc_jid);
await u.waitUntil(() => (view.model.occupants.length === 5));
......@@ -358,7 +357,7 @@ window.addEventListener('converse-loaded', () => {
<forbidden xmlns="${Strophe.NS.STANZAS}"/>
</error>
</iq>`);
_converse.connection._dataRecv(test_utils.createRequest(error));
_converse.connection._dataRecv(mock.createRequest(error));
await u.waitUntil(() => !modal.loading_users_with_affiliation);
const user_els = modal.el.querySelectorAll('.list-group--users > li');
......@@ -366,5 +365,4 @@ window.addEventListener('converse-loaded', () => {
expect(user_els[0].textContent.trim()).toBe('Error: not allowed to fetch outcast list for MUC lounge@montague.lit');
done();
}));
});
});
This diff is collapsed.
This diff is collapsed.
window.addEventListener('converse-loaded', () => {
const mock = window.mock;
const test_utils = window.test_utils;
const _ = converse.env._;
const $msg = converse.env.$msg;
const u = converse.env.utils;
describe("Notifications", function () {
/*global mock */
const _ = converse.env._;
const $msg = converse.env.$msg;
const u = converse.env.utils;
describe("Notifications", function () {
// Implement the protocol defined in https://xmpp.org/extensions/xep-0313.html#config
describe("When show_desktop_notifications is set to true", function () {
......@@ -15,7 +14,7 @@ window.addEventListener('converse-loaded', () => {
it("is shown when a new private message is received",
mock.initConverse(['rosterGroupsFetched'], {}, async (done, _converse) => {
await test_utils.waitForRoster(_converse, 'current');
await mock.waitForRoster(_converse, 'current');
spyOn(_converse, 'showMessageNotification').and.callThrough();
spyOn(_converse, 'areDesktopNotificationsEnabled').and.returnValue(true);
spyOn(_converse, 'isMessageToHiddenChat').and.returnValue(true);
......@@ -39,8 +38,8 @@ window.addEventListener('converse-loaded', () => {
it("is shown when you are mentioned in a groupchat",
mock.initConverse(['rosterGroupsFetched'], {}, async (done, _converse) => {
await test_utils.waitForRoster(_converse, 'current');
await test_utils.openAndEnterChatRoom(_converse, 'lounge@montague.lit', 'romeo');
await mock.waitForRoster(_converse, 'current');
await mock.openAndEnterChatRoom(_converse, 'lounge@montague.lit', 'romeo');
const view = _converse.api.chatviews.get('lounge@montague.lit');
if (!view.el.querySelectorAll('.chat-area').length) {
view.renderChatArea();
......@@ -65,7 +64,7 @@ window.addEventListener('converse-loaded', () => {
to: 'romeo@montague.lit',
type: 'groupchat'
}).c('body').t(message).tree();
_converse.connection._dataRecv(test_utils.createRequest(msg));
_converse.connection._dataRecv(mock.createRequest(msg));
await new Promise(resolve => view.once('messageInserted', resolve));
await u.waitUntil(() => _converse.areDesktopNotificationsEnabled.calls.count() === 1);
......@@ -92,7 +91,7 @@ window.addEventListener('converse-loaded', () => {
.c('body').t('&lt;juliet@example.com&gt; You got mail.').up()
.c('x', {'xmlns': 'jabber:x:oob'})
.c('url').t('imap://romeo@example.com/INBOX;UIDVALIDITY=385759043/;UID=18');
_converse.connection._dataRecv(test_utils.createRequest(stanza));
_converse.connection._dataRecv(mock.createRequest(stanza));
await u.waitUntil(() => _converse.chatboxviews.keys().length);
const view = _converse.chatboxviews.get('notify.example.com');
await new Promise(resolve => view.once('messageInserted', resolve));
......@@ -118,7 +117,7 @@ window.addEventListener('converse-loaded', () => {
.c('body').t('&lt;juliet@example.com&gt; You got mail.').up()
.c('x', {'xmlns': 'jabber:x:oob'})
.c('url').t('imap://romeo@example.com/INBOX;UIDVALIDITY=385759043/;UID=18');
_converse.connection._dataRecv(test_utils.createRequest(stanza));
_converse.connection._dataRecv(mock.createRequest(stanza));
expect(
_.includes(_converse.chatboxviews.keys(),
'someone@notify.example.com')
......@@ -131,7 +130,7 @@ window.addEventListener('converse-loaded', () => {
mock.initConverse(['rosterGroupsFetched'], {show_chat_state_notifications: true},
async (done, _converse) => {
await test_utils.waitForRoster(_converse, 'current', 3);
await mock.waitForRoster(_converse, 'current', 3);
spyOn(_converse, 'areDesktopNotificationsEnabled').and.returnValue(true);
spyOn(_converse, 'showChatStateNotification');
const jid = mock.cur_names[2].replace(/ /g,'.').toLowerCase() + '@montague.lit';
......@@ -161,8 +160,8 @@ window.addEventListener('converse-loaded', () => {
it("is played when the current user is mentioned in a groupchat",
mock.initConverse(['rosterGroupsFetched'], {}, async (done, _converse) => {
test_utils.createContacts(_converse, 'current');
await test_utils.openAndEnterChatRoom(_converse, 'lounge@montague.lit', 'romeo');
mock.createContacts(_converse, 'current');
await mock.openAndEnterChatRoom(_converse, 'lounge@montague.lit', 'romeo');
_converse.play_sounds = true;
spyOn(_converse, 'playSoundNotification');
const view = _converse.chatboxviews.get('lounge@montague.lit');
......@@ -205,5 +204,4 @@ window.addEventListener('converse-loaded', () => {
}));
});
});
});
});
This diff is collapsed.
window.addEventListener('converse-loaded', () => {
const mock = window.mock;
const test_utils = window.test_utils;
const Strophe = converse.env.Strophe;
const u = converse.env.utils;
/*global mock */
const Strophe = converse.env.Strophe;
const u = converse.env.utils;
describe("XMPP Ping", function () {
describe("XMPP Ping", function () {
describe("An IQ stanza", function () {
......@@ -15,7 +14,7 @@ window.addEventListener('converse-loaded', () => {
to="${_converse.jid}" id="s2c1" type="get">
<ping xmlns="urn:xmpp:ping"/>
</iq>`);
_converse.connection._dataRecv(test_utils.createRequest(ping));
_converse.connection._dataRecv(mock.createRequest(ping));
const sent_stanza = _converse.connection.IQ_stanzas.pop();
expect(Strophe.serialize(sent_stanza)).toBe(
`<iq id="s2c1" to="${_converse.domain}" type="result" xmlns="jabber:client"/>`);
......@@ -32,5 +31,4 @@ window.addEventListener('converse-loaded', () => {
done();
}));
});
});
});
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
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