Commit c9b4c740 authored by JC Brand's avatar JC Brand

Exploring using karma

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