Commit c9b4c740 authored by JC Brand's avatar JC Brand

Exploring using karma

parent 74eed32e
......@@ -9,6 +9,7 @@
"plugins": ["lodash"],
"extends": ["eslint:recommended", "plugin:lodash/canonical"],
"globals": {
"module": true,
"window": true,
"sinon": true,
"define": true,
......
......@@ -11,11 +11,7 @@
<link rel="shortcut icon" type="image/ico" href="css/images/favicon.ico"/>
<link type="text/css" rel="stylesheet" media="screen" href="css/fullpage.css" />
<link type="text/css" rel="stylesheet" media="screen" href="css/converse.css" />
<![if gte IE 11]>
<link type="text/css" rel="stylesheet" media="screen" href="css/converse.css" />
<script src="dist/converse.js"></script>
<![endif]>
</head>
<body class="reset">
......
// Karma configuration
// Generated on Sat Jun 02 2018 22:33:35 GMT+0200 (CEST)
module.exports = function(config) {
config.set({
// base path that will be used to resolve all patterns (eg. files, exclude)
basePath: '',
// frameworks to use
// available frameworks: https://npmjs.org/browse/keyword/karma-adapter
frameworks: ['jasmine'],
// list of files / patterns to load in the browser
files: [
'dist/converse.js',
'tests/utils.js',
'tests/mock.js',
'spec/messages.js'
],
// list of files / patterns to exclude
exclude: ['*.min.js'],
// 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'],
// web server port
port: 9876,
// enable / disable colors in the output (reporters and logs)
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_DEBUG,
// 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: [],
// 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.
(function (root, factory) {
define([
"jquery",
"jasmine",
"utils",
"converse-core",
"mock",
"test-utils"
], factory);
} (this, function ($, jasmine, utils, converse, mock, test_utils) {
"use strict";
var _ = converse.env._;
var $iq = converse.env.$iq;
var $msg = converse.env.$msg;
var Strophe = converse.env.Strophe;
var Promise = converse.env.Promise;
var moment = converse.env.moment;
var u = converse.env.utils;
describe("A Chat Message", function () {
"use strict";
var _ = converse.env._;
var $iq = converse.env.$iq;
var $msg = converse.env.$msg;
var Strophe = converse.env.Strophe;
var Promise = converse.env.Promise;
var moment = converse.env.moment;
var u = converse.env.utils;
debugger;
describe("A Chat Message", function () {
describe("when received from someone else", function () {
......@@ -1483,5 +1473,4 @@
});
}));
});
});
}));
});
......@@ -12,7 +12,7 @@ if (typeof(require) === 'undefined') {
};
}
require.config({
window.config = {
baseUrl: '.',
paths: {
"IPv6": "node_modules/urijs/src/IPv6",
......
......@@ -11,9 +11,8 @@
<link rel="stylesheet" type="text/css" media="screen" href="../css/jasmine.css">
<link type="text/css" rel="stylesheet" media="screen" href="../css/website.css" />
<link type="text/css" rel="stylesheet" media="screen" href="../css/converse.css" />
<script src="../src/config.js"></script>
<script data-main="runner" src="../node_modules/requirejs/require.js"></script>
<script src="dist/converse.js"></script>
<script src="runner.js"></script>
<style>
.tests-brand-heading {
......
(function (root, factory) {
define("mock", ['converse'], factory);
}(this, function (converse) {
var _ = converse.env._;
var Promise = converse.env.Promise;
var Strophe = converse.env.Strophe;
var $iq = converse.env.$iq;
var mock = {};
var _ = converse.env._;
var Promise = converse.env.Promise;
var Strophe = converse.env.Strophe;
var $iq = converse.env.$iq;
window.mock = {};
mock.view_mode = 'overlayed';
mock.view_mode = 'overlayed';
// Names from http://www.fakenamegenerator.com/
mock.req_names = [
// Names from http://www.fakenamegenerator.com/
mock.req_names = [
'Louw Spekman', 'Mohamad Stet', 'Dominik Beyer'
];
mock.pend_names = [
];
mock.pend_names = [
'Suleyman van Beusichem', 'Nanja van Yperen', 'Nicole Diederich'
];
mock.cur_names = [
];
mock.cur_names = [
'Max Frankfurter', 'Candice van der Knijff', 'Irini Vlastuin', 'Rinse Sommer', 'Annegreet Gomez',
'Robin Schook', 'Marcel Eberhardt', 'Simone Brauer', 'Asmaa Haakman', 'Felix Amsel',
'Lena Grunewald', 'Laura Grunewald', 'Mandy Seiler', 'Sven Bosch', 'Nuriye Cuypers'
];
mock.num_contacts = mock.req_names.length + mock.pend_names.length + mock.cur_names.length;
];
mock.num_contacts = mock.req_names.length + mock.pend_names.length + mock.cur_names.length;
mock.groups = {
mock.groups = {
'colleagues': 3,
'friends & acquaintences': 3,
'Family': 4,
'ænemies': 3,
'Ungrouped': 2
};
};
mock.chatroom_names = [
mock.chatroom_names = [
'Dyon van de Wege', 'Thomas Kalb', 'Dirk Theissen', 'Felix Hofmann', 'Ka Lek', 'Anne Ebersbacher'
];
// TODO: need to also test other roles and affiliations
mock.chatroom_roles = {
];
// TODO: need to also test other roles and affiliations
mock.chatroom_roles = {
'Anne Ebersbacher': { affiliation: "owner", role: "moderator" },
'Dirk Theissen': { affiliation: "admin", role: "moderator" },
'Dyon van de Wege': { affiliation: "member", role: "occupant" },
'Felix Hofmann': { affiliation: "member", role: "occupant" },
'Ka Lek': { affiliation: "member", role: "occupant" },
'Thomas Kalb': { affiliation: "member", role: "occupant" }
};
};
mock.event = {
mock.event = {
'preventDefault': function () {}
};
};
mock.mock_connection = function () { // eslint-disable-line wrap-iife
mock.mock_connection = function () { // eslint-disable-line wrap-iife
return function () {
Strophe.Bosh.prototype._processRequest = function () {}; // Don't attempt to send out stanzas
var c = new Strophe.Connection('jasmine tests');
......@@ -72,9 +69,9 @@
};
return c;
};
}();
}();
function initConverse (settings, spies, promises) {
function initConverse (settings, spies, promises) {
window.localStorage.clear();
window.sessionStorage.clear();
......@@ -137,9 +134,9 @@
}
window.converse_disable_effects = true;
return _converse;
}
}
mock.initConverseWithPromises = function (spies, promise_names, settings, func) {
mock.initConverseWithPromises = function (spies, promise_names, settings, func) {
return function (done) {
var _converse = initConverse(settings, spies);
var promises = _.map(promise_names, _converse.api.waitUntil);
......@@ -147,15 +144,15 @@
.then(_.partial(func, done, _converse))
.catch(_.partial(_converse.log, _, Strophe.LogLevel.FATAL));
}
};
};
mock.initConverseWithConnectionSpies = function (spies, settings, func) {
mock.initConverseWithConnectionSpies = function (spies, settings, func) {
return function (done) {
return func(done, initConverse(settings, spies));
};
};
};
mock.initConverseWithAsync = function (settings, func) {
mock.initConverseWithAsync = function (settings, func) {
if (_.isFunction(settings)) {
var _func = settings;
settings = func;
......@@ -164,8 +161,8 @@
return function (done) {
return func(done, initConverse(settings));
};
};
mock.initConverse = function (settings, func) {
};
mock.initConverse = function (settings, func) {
if (_.isFunction(settings)) {
var _func = settings;
settings = func;
......@@ -174,6 +171,4 @@
return function () {
return func(initConverse(settings));
};
};
return mock;
}));
};
This diff is collapsed.
(function (root, factory) {
define(['converse', 'es6-promise', 'mock', 'wait-until-promise'], factory);
}(this, function (converse_api, Promise, mock, waitUntilPromise) {
var _ = converse_api.env._;
var $msg = converse_api.env.$msg;
var $pres = converse_api.env.$pres;
var $iq = converse_api.env.$iq;
var Strophe = converse_api.env.Strophe;
var u = converse_api.env.utils;
var utils = {};
var _ = converse.env._;
var $msg = converse.env.$msg;
var $pres = converse.env.$pres;
var $iq = converse.env.$iq;
var Strophe = converse.env.Strophe;
var u = converse.env.utils;
var utils = {};
if (typeof window.Promise === 'undefined') {
if (typeof window.Promise === 'undefined') {
waitUntilPromise.setPromiseImplementation(Promise);
}
utils.waitUntil = waitUntilPromise.default;
}
utils.waitUntil = waitUntilPromise.default;
utils.waitUntilDiscoConfirmed = function (_converse, entity_jid, identities, features, items, type) {
utils.waitUntilDiscoConfirmed = function (_converse, entity_jid, identities, features, items, type) {
if (_.isNil(type)) {
type = 'info';
}
......@@ -45,9 +42,9 @@
});
_converse.connection._dataRecv(utils.createRequest(stanza));
}).catch(_.partial(console.error, _));
}
}
utils.createRequest = function (iq) {
utils.createRequest = function (iq) {
iq = typeof iq.tree == "function" ? iq.tree() : iq;
var req = new Strophe.Request(iq, function() {});
req.getResponse = function () {
......@@ -56,18 +53,18 @@
return env;
};
return req;
};
};
utils.closeAllChatBoxes = function (converse) {
utils.closeAllChatBoxes = function (converse) {
var i, chatbox;
for (i=converse.chatboxes.models.length-1; i>-1; i--) {
chatbox = converse.chatboxes.models[i];
converse.chatboxviews.get(chatbox.get('id')).close();
}
return this;
};
};
utils.openControlBox = function () {
utils.openControlBox = function () {
var toggle = document.querySelector(".toggle-controlbox");
if (!u.isVisible(document.querySelector("#controlbox"))) {
if (!u.isVisible(toggle)) {
......@@ -76,9 +73,9 @@
toggle.click();
}
return this;
};
};
utils.closeControlBox = function () {
utils.closeControlBox = function () {
var controlbox = document.querySelector("#controlbox");
if (u.isVisible(controlbox)) {
var button = controlbox.querySelector(".close-chatbox-button");
......@@ -87,22 +84,22 @@
}
}
return this;
};
};
utils.openChatBoxes = function (converse, amount) {
utils.openChatBoxes = function (converse, amount) {
var i = 0, jid, views = [];
for (i; i<amount; i++) {
jid = mock.cur_names[i].replace(/ /g,'.').toLowerCase() + '@localhost';
views[i] = converse.roster.get(jid).trigger("open");
}
return views;
};
};
utils.openChatBoxFor = function (converse, jid) {
utils.openChatBoxFor = function (converse, jid) {
return converse.roster.get(jid).trigger("open");
};
};
utils.openChatRoomViaModal = function (_converse, jid, nick) {
utils.openChatRoomViaModal = function (_converse, jid, nick) {
// Opens a new chatroom
return new Promise(function (resolve, reject) {
utils.openControlBox(_converse);
......@@ -118,13 +115,13 @@
resolve();
}).catch(_.partial(console.error, _));
}).catch(_.partial(console.error, _));
};
};
utils.openChatRoom = function (_converse, room, server, nick) {
utils.openChatRoom = function (_converse, room, server, nick) {
_converse.api.rooms.open(`${room}@${server}`);
};
};
utils.openAndEnterChatRoom = function (_converse, room, server, nick) {
utils.openAndEnterChatRoom = function (_converse, room, server, nick) {
let last_stanza;
return new Promise(function (resolve, reject) {
......@@ -181,22 +178,22 @@
}).catch(_.partial(console.error, _));
}).catch(_.partial(console.error, _));
};
};
utils.clearBrowserStorage = function () {
utils.clearBrowserStorage = function () {
window.localStorage.clear();
window.sessionStorage.clear();
return this;
};
};
utils.clearChatBoxMessages = function (converse, jid) {
utils.clearChatBoxMessages = function (converse, jid) {
var view = converse.chatboxviews.get(jid);
view.el.querySelector('.chat-content').innerHTML = '';
view.model.messages.reset();
view.model.messages.browserStorage._clear();
};
};
utils.createContacts = function (converse, type, length) {
utils.createContacts = function (converse, type, length) {
/* Create current (as opposed to requesting or pending) contacts
* for the user's roster.
*
......@@ -243,9 +240,9 @@
}
}
return this;
};
};
utils.createGroupedContacts = function (converse) {
utils.createGroupedContacts = function (converse) {
/* Create grouped contacts
*/
var i=0, j=0;
......@@ -261,9 +258,9 @@
});
}
});
};
};
utils.createChatMessage = function (_converse, sender_jid, message) {
utils.createChatMessage = function (_converse, sender_jid, message) {
return $msg({
from: sender_jid,
to: _converse.connection.jid,
......@@ -272,15 +269,13 @@
})
.c('body').t(message).up()
.c('active', {'xmlns': Strophe.NS.CHATSTATES}).tree();
}
}
utils.sendMessage = function (chatboxview, message) {
utils.sendMessage = function (chatboxview, message) {
chatboxview.el.querySelector('.chat-textarea').value = message;
chatboxview.keyPressed({
target: chatboxview.el.querySelector('textarea.chat-textarea'),
preventDefault: _.noop,
keyCode: 13
});
};
return utils;
}));
};
......@@ -75,6 +75,18 @@ const config = {
path.resolve(__dirname, "src"),
],
alias: {
"jquery": path.resolve(__dirname, "node_modules/jquery/dist/jquery"),
"mock": path.resolve(__dirname, "tests/mock"),
"wait-until-promise": path.resolve(__dirname, "node_modules/wait-until-promise/index"),
"test-utils": path.resolve(__dirname, "tests/utils"),
"sinon": path.resolve(__dirname, "node_modules/sinon/pkg/sinon"),
"transcripts": path.resolve(__dirname, "converse-logs/converse-logs"),
"jasmine-core": path.resolve(__dirname, "node_modules/jasmine-core/lib/jasmine-core/jasmine"),
"jasmine": path.resolve(__dirname, "node_modules/jasmine-core/lib/jasmine-core/boot"),
"jasmine-console": path.resolve(__dirname, "node_modules/jasmine-core/lib/console/console"),
"console-reporter": path.resolve(__dirname, "tests/console-reporter"),
"jasmine-html": path.resolve(__dirname, "node_modules/jasmine-core/lib/jasmine-core/jasmine-html"),
"IPv6": path.resolve(__dirname, "node_modules/urijs/src/IPv6"),
"SecondLevelDomains": path.resolve(__dirname, "node_modules/urijs/src/SecondLevelDomains"),
"awesomplete": path.resolve(__dirname, "node_modules/awesomplete-avoid-xss/awesomplete"),
......
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