Commit e835a251 authored by JC Brand's avatar JC Brand

Add jshint checking and fix errors.

parent 218b4714
/*global __dirname, process */
module.exports = function(grunt) { module.exports = function(grunt) {
var path = require('path'); var path = require('path');
var cfg = require('./package.json');
grunt.initConfig({ grunt.initConfig({
jst: { jst: {
compile: { compile: {
...@@ -36,20 +36,6 @@ module.exports = function(grunt) { ...@@ -36,20 +36,6 @@ module.exports = function(grunt) {
} }
}, },
jshint: {
options: {
trailing: true
},
target: {
src : [
'converse.js',
'mock.js',
'main.js',
'tests_main.js',
'spec/*.js'
]
}
},
cssmin: { cssmin: {
options: { options: {
banner: "/*"+ banner: "/*"+
...@@ -70,7 +56,6 @@ module.exports = function(grunt) { ...@@ -70,7 +56,6 @@ module.exports = function(grunt) {
} }
}); });
grunt.loadNpmTasks('grunt-contrib-cssmin'); grunt.loadNpmTasks('grunt-contrib-cssmin');
grunt.loadNpmTasks('grunt-contrib-jshint');
grunt.loadNpmTasks('grunt-contrib-jst'); grunt.loadNpmTasks('grunt-contrib-jst');
grunt.loadNpmTasks('grunt-json'); grunt.loadNpmTasks('grunt-json');
grunt.loadNpmTasks('grunt-contrib-requirejs'); grunt.loadNpmTasks('grunt-contrib-requirejs');
...@@ -131,13 +116,9 @@ module.exports = function(grunt) { ...@@ -131,13 +116,9 @@ module.exports = function(grunt) {
rjs + ' -o src/build-no-locales-no-otr.js optimize=none out=builds/converse-no-locales-no-otr.js && ' + rjs + ' -o src/build-no-locales-no-otr.js optimize=none out=builds/converse-no-locales-no-otr.js && ' +
rjs + ' -o src/build-no-otr.js &&' + rjs + ' -o src/build-no-otr.js &&' +
rjs + ' -o src/build-no-otr.js optimize=none out=builds/converse-no-otr.js', callback); rjs + ' -o src/build-no-otr.js optimize=none out=builds/converse-no-otr.js', callback);
// XXX: It might be possible to not have separate build config files. For example: // XXX: It might be possible to not have separate build config files. For example:
// 'r.js -o src/build.js paths.converse-dependencies=src/deps-no-otr paths.locales=locale/nolocales out=builds/converse-no-locales-no-otr.min.js' // 'r.js -o src/build.js paths.converse-dependencies=src/deps-no-otr paths.locales=locale/nolocales out=builds/converse-no-locales-no-otr.min.js'
}); });
grunt.registerTask('minify', 'Create a new minified builds', ['cssmin', 'jsmin']); grunt.registerTask('minify', 'Create a new minified builds', ['cssmin', 'jsmin']);
grunt.registerTask('check', 'Perform all checks (e.g. before releasing)', function () {
grunt.task.run('jshint', 'test');
});
}; };
# You can set these variables from the command line. # You can set these variables from the command line.
BOWER ?= node_modules/.bin/bower BOWER ?= node_modules/.bin/bower
BUILDDIR = ./docs BUILDDIR = ./docs
BUNDLE ?= ./.bundle/bin/bundle
GRUNT ?= ./node_modules/.bin/grunt
HTTPSERVE ?= ./node_modules/.bin/http-server
JSHINT ?= ./node_modules/.bin/jshint
PAPER = PAPER =
PHANTOMJS ?= ./node_modules/.bin/phantomjs PHANTOMJS ?= ./node_modules/.bin/phantomjs
SPHINXBUILD ?= ./bin/sphinx-build
SPHINXOPTS =
PO2JSON ?= ./node_modules/.bin/po2json PO2JSON ?= ./node_modules/.bin/po2json
SASS ?= ./.bundle/bin/sass SASS ?= ./.bundle/bin/sass
BUNDLE ?= ./.bundle/bin/bundle SPHINXBUILD ?= ./bin/sphinx-build
GRUNT ?= ./node_modules/.bin/grunt SPHINXOPTS =
HTTPSERVE ?= ./node_modules/.bin/http-server
# Internal variables. # Internal variables.
ALLSPHINXOPTS = -d $(BUILDDIR)/doctrees $(PAPEROPT_$(PAPER)) $(SPHINXOPTS) ./docs/source ALLSPHINXOPTS = -d $(BUILDDIR)/doctrees $(PAPEROPT_$(PAPER)) $(SPHINXOPTS) ./docs/source
SOURCES = $(wildcard *.js) $(wildcard spec/*.js) $(wildcard src/*.js)
JSHINTEXCEPTIONS = $(GENERATED) \
src/otr.js \
src/crypto.js \
src/build-no-jquery.js \
src/build-no-locales-no-otr.js \
src/build-no-otr.js \
src/build.js \
src/bigint.js
CHECKSOURCES = $(filter-out $(JSHINTEXCEPTIONS),$(SOURCES))
.PHONY: help .PHONY: help
help: help:
...@@ -135,9 +146,12 @@ build:: stamp-npm ...@@ -135,9 +146,12 @@ build:: stamp-npm
######################################################################## ########################################################################
## Tests ## Tests
.PHONY: jshint
jshint: stamp-npm
$(JSHINT) --config jshintrc $(CHECKSOURCES)
.PHONY: watch .PHONY: watch
check: stamp-npm check: stamp-npm jshint
$(GRUNT) jshint
$(PHANTOMJS) node_modules/phantom-jasmine/lib/run_jasmine_test.coffee tests.html $(PHANTOMJS) node_modules/phantom-jasmine/lib/run_jasmine_test.coffee tests.html
######################################################################## ########################################################################
......
This diff is collapsed.
{
"browser": true,
"devel": true,
"eqeqeq": true,
"indent": 4,
"jquery": false,
"smarttabs": true,
"trailing": true,
"undef": true,
"unused": "vars",
"white": false,
"predef": [
"afterEach",
"beforeEach",
"converse_api",
"define",
"define",
"describe",
"expect",
"global",
"it",
"jasmine",
"module",
"require",
"runs",
"spyOn",
"xit",
"waits"
]
}
...@@ -4,7 +4,7 @@ if (typeof(require) === 'undefined') { ...@@ -4,7 +4,7 @@ if (typeof(require) === 'undefined') {
* We want to save the configuration in a variable so that we can reuse it in * We want to save the configuration in a variable so that we can reuse it in
* tests/main.js. * tests/main.js.
*/ */
require = { require = { // jshint ignore:line
config: function (c) { config: function (c) {
config = c; config = c;
} }
......
...@@ -24,7 +24,7 @@ ...@@ -24,7 +24,7 @@
"webchat" "webchat"
], ],
"author": "JC Brand", "author": "JC Brand",
"license": "MPL", "license": "MPL-2.0",
"bugs": { "bugs": {
"url": "https://github.com/jcbrand/converse.js/issues" "url": "https://github.com/jcbrand/converse.js/issues"
}, },
...@@ -36,7 +36,6 @@ ...@@ -36,7 +36,6 @@
"grunt": "~0.4.4", "grunt": "~0.4.4",
"grunt-cli": "~0.1.13", "grunt-cli": "~0.1.13",
"grunt-contrib-cssmin": "~0.9.0", "grunt-contrib-cssmin": "~0.9.0",
"grunt-contrib-jshint": "~0.10.0",
"grunt-contrib-jst": "~0.6.0", "grunt-contrib-jst": "~0.6.0",
"grunt-contrib-requirejs": "~0.4.3", "grunt-contrib-requirejs": "~0.4.3",
"grunt-json": "^0.1.3", "grunt-json": "^0.1.3",
...@@ -48,6 +47,7 @@ ...@@ -48,6 +47,7 @@
"po2json": "^0.3.0" "po2json": "^0.3.0"
}, },
"dependencies": { "dependencies": {
"jshint": "^2.8.0",
"requirejs": "~2.1.15" "requirejs": "~2.1.15"
} }
} }
/*global converse */
(function (root, factory) { (function (root, factory) {
define([ define([
"jquery", "jquery",
"underscore",
"mock", "mock",
"test_utils" "test_utils"
], function ($, mock, test_utils) { ], function ($, _, mock, test_utils) {
return factory($, mock, test_utils); return factory($, _, mock, test_utils);
} }
); );
} (this, function ($, mock, test_utils) { } (this, function ($, _, mock, test_utils) {
var $msg = converse_api.env.$msg; var $msg = converse_api.env.$msg;
var Strophe = converse_api.env.Strophe; var Strophe = converse_api.env.Strophe;
var moment = converse_api.env.moment; var moment = converse_api.env.moment;
...@@ -27,7 +29,7 @@ ...@@ -27,7 +29,7 @@
}); });
it("is created when you click on a roster item", function () { it("is created when you click on a roster item", function () {
var i, $el, click, jid, chatboxview; var i, $el, jid, chatboxview;
// openControlBox was called earlier, so the controlbox is // openControlBox was called earlier, so the controlbox is
// visible, but no other chat boxes have been created. // visible, but no other chat boxes have been created.
expect(this.chatboxes.length).toEqual(1); expect(this.chatboxes.length).toEqual(1);
...@@ -50,7 +52,7 @@ ...@@ -50,7 +52,7 @@
}.bind(converse)); }.bind(converse));
it("can be trimmed to conserve space", function () { it("can be trimmed to conserve space", function () {
var i, $el, click, jid, key, chatbox, chatboxview; var i, $el, jid, chatbox, chatboxview, trimmedview;
// openControlBox was called earlier, so the controlbox is // openControlBox was called earlier, so the controlbox is
// visible, but no other chat boxes have been created. // visible, but no other chat boxes have been created.
var trimmed_chatboxes = converse.minimized_chats; var trimmed_chatboxes = converse.minimized_chats;
...@@ -99,7 +101,7 @@ ...@@ -99,7 +101,7 @@
it("is focused if its already open and you click on its corresponding roster item", function () { it("is focused if its already open and you click on its corresponding roster item", function () {
var contact_jid = mock.cur_names[2].replace(/ /g,'.').toLowerCase() + '@localhost'; var contact_jid = mock.cur_names[2].replace(/ /g,'.').toLowerCase() + '@localhost';
var i, $el, click, jid, chatboxview, chatbox; var $el, jid, chatboxview, chatbox;
// openControlBox was called earlier, so the controlbox is // openControlBox was called earlier, so the controlbox is
// visible, but no other chat boxes have been created. // visible, but no other chat boxes have been created.
expect(this.chatboxes.length).toEqual(1); expect(this.chatboxes.length).toEqual(1);
...@@ -141,8 +143,9 @@ ...@@ -141,8 +143,9 @@
expect(newchatboxes.length).toEqual(7); expect(newchatboxes.length).toEqual(7);
// Check that the chatboxes items retrieved from browserStorage // Check that the chatboxes items retrieved from browserStorage
// have the same attributes values as the original ones. // have the same attributes values as the original ones.
attrs = ['id', 'box_id', 'visible']; var attrs = ['id', 'box_id', 'visible'];
for (i=0; i<attrs.length; i++) { var new_attrs, old_attrs;
for (var i=0; i<attrs.length; i++) {
new_attrs = _.pluck(_.pluck(newchatboxes.models, 'attributes'), attrs[i]); new_attrs = _.pluck(_.pluck(newchatboxes.models, 'attributes'), attrs[i]);
old_attrs = _.pluck(_.pluck(this.chatboxes.models, 'attributes'), attrs[i]); old_attrs = _.pluck(_.pluck(this.chatboxes.models, 'attributes'), attrs[i]);
expect(_.isEqual(new_attrs, old_attrs)).toEqual(true); expect(_.isEqual(new_attrs, old_attrs)).toEqual(true);
...@@ -565,7 +568,7 @@ ...@@ -565,7 +568,7 @@
expect(chatview.model.get('minimized')).toBeTruthy(); expect(chatview.model.get('minimized')).toBeTruthy();
var message = 'This message is sent to a minimized chatbox'; var message = 'This message is sent to a minimized chatbox';
var sender_jid = mock.cur_names[0].replace(/ /g,'.').toLowerCase() + '@localhost'; var sender_jid = mock.cur_names[0].replace(/ /g,'.').toLowerCase() + '@localhost';
msg = $msg({ var msg = $msg({
from: sender_jid, from: sender_jid,
to: this.connection.jid, to: this.connection.jid,
type: 'chat', type: 'chat',
...@@ -945,7 +948,7 @@ ...@@ -945,7 +948,7 @@
spyOn(converse, 'emit'); spyOn(converse, 'emit');
var sender_jid = mock.cur_names[1].replace(/ /g,'.').toLowerCase() + '@localhost'; var sender_jid = mock.cur_names[1].replace(/ /g,'.').toLowerCase() + '@localhost';
// <paused> state // <paused> state
msg = $msg({ var msg = $msg({
from: sender_jid, from: sender_jid,
to: this.connection.jid, to: this.connection.jid,
type: 'chat', type: 'chat',
...@@ -954,7 +957,7 @@ ...@@ -954,7 +957,7 @@
this.chatboxes.onMessage(msg); this.chatboxes.onMessage(msg);
expect(converse.emit).toHaveBeenCalledWith('message', msg); expect(converse.emit).toHaveBeenCalledWith('message', msg);
var chatboxview = this.chatboxviews.get(sender_jid); var chatboxview = this.chatboxviews.get(sender_jid);
$events = chatboxview.$el.find('.chat-event'); var $events = chatboxview.$el.find('.chat-event');
expect($events.length).toBe(1); expect($events.length).toBe(1);
expect($events.text()).toEqual(mock.cur_names[1].split(' ')[0] + ' has stopped typing'); expect($events.text()).toEqual(mock.cur_names[1].split(' ')[0] + ' has stopped typing');
}.bind(converse)); }.bind(converse));
...@@ -1030,7 +1033,7 @@ ...@@ -1030,7 +1033,7 @@
expect(view.$el.find('.chat-event').length).toBe(0); expect(view.$el.find('.chat-event').length).toBe(0);
view.showStatusNotification(sender_jid+' '+'is typing'); view.showStatusNotification(sender_jid+' '+'is typing');
expect(view.$el.find('.chat-event').length).toBe(1); expect(view.$el.find('.chat-event').length).toBe(1);
msg = $msg({ var msg = $msg({
from: sender_jid, from: sender_jid,
to: this.connection.jid, to: this.connection.jid,
type: 'chat', type: 'chat',
...@@ -1048,7 +1051,7 @@ ...@@ -1048,7 +1051,7 @@
spyOn(converse, 'emit'); spyOn(converse, 'emit');
var sender_jid = mock.cur_names[1].replace(/ /g,'.').toLowerCase() + '@localhost'; var sender_jid = mock.cur_names[1].replace(/ /g,'.').toLowerCase() + '@localhost';
// <paused> state // <paused> state
msg = $msg({ var msg = $msg({
from: sender_jid, from: sender_jid,
to: this.connection.jid, to: this.connection.jid,
type: 'chat', type: 'chat',
...@@ -1057,7 +1060,7 @@ ...@@ -1057,7 +1060,7 @@
this.chatboxes.onMessage(msg); this.chatboxes.onMessage(msg);
expect(converse.emit).toHaveBeenCalledWith('message', msg); expect(converse.emit).toHaveBeenCalledWith('message', msg);
var chatboxview = this.chatboxviews.get(sender_jid); var chatboxview = this.chatboxviews.get(sender_jid);
$events = chatboxview.$el.find('.chat-event'); var $events = chatboxview.$el.find('.chat-event');
expect($events.length).toBe(1); expect($events.length).toBe(1);
expect($events.text()).toEqual(mock.cur_names[1].split(' ')[0] + ' has gone away'); expect($events.text()).toEqual(mock.cur_names[1].split(' ')[0] + ' has gone away');
}.bind(converse)); }.bind(converse));
...@@ -1090,7 +1093,6 @@ ...@@ -1090,7 +1093,6 @@
expect(converse.emit).toHaveBeenCalledWith('messageSend', message); expect(converse.emit).toHaveBeenCalledWith('messageSend', message);
message = '/clear'; message = '/clear';
var old_length = view.model.messages.length;
spyOn(view, 'onMessageSubmitted').andCallThrough(); spyOn(view, 'onMessageSubmitted').andCallThrough();
spyOn(view, 'clearMessages').andCallThrough(); spyOn(view, 'clearMessages').andCallThrough();
spyOn(window, 'confirm').andCallFake(function () { spyOn(window, 'confirm').andCallFake(function () {
...@@ -1118,7 +1120,7 @@ ...@@ -1118,7 +1120,7 @@
spyOn(converse, 'incrementMsgCounter').andCallThrough(); spyOn(converse, 'incrementMsgCounter').andCallThrough();
$(window).trigger('blur'); $(window).trigger('blur');
var message = 'This message will increment the message counter'; var message = 'This message will increment the message counter';
var sender_jid = mock.cur_names[0].replace(/ /g,'.').toLowerCase() + '@localhost'; var sender_jid = mock.cur_names[0].replace(/ /g,'.').toLowerCase() + '@localhost',
msg = $msg({ msg = $msg({
from: sender_jid, from: sender_jid,
to: this.connection.jid, to: this.connection.jid,
...@@ -1149,7 +1151,7 @@ ...@@ -1149,7 +1151,7 @@
spyOn(converse, 'incrementMsgCounter').andCallThrough(); spyOn(converse, 'incrementMsgCounter').andCallThrough();
$(window).trigger('focus'); $(window).trigger('focus');
var message = 'This message will not increment the message counter'; var message = 'This message will not increment the message counter';
var sender_jid = mock.cur_names[0].replace(/ /g,'.').toLowerCase() + '@localhost'; var sender_jid = mock.cur_names[0].replace(/ /g,'.').toLowerCase() + '@localhost',
msg = $msg({ msg = $msg({
from: sender_jid, from: sender_jid,
to: this.connection.jid, to: this.connection.jid,
......
/*global converse */
(function (root, factory) { (function (root, factory) {
define([ define([
"jquery", "jquery",
"underscore",
"mock", "mock",
"test_utils", "test_utils",
"utils" "utils"
], function ($, mock, test_utils, utils) { ], function ($, _, mock, test_utils, utils) {
return factory($, mock, test_utils, utils); return factory($, _, mock, test_utils, utils);
} }
); );
} (this, function ($, mock, test_utils, utils) { } (this, function ($, _, mock, test_utils, utils) {
var $pres = converse_api.env.$pres; var $pres = converse_api.env.$pres;
var $msg = converse_api.env.$msg; var $msg = converse_api.env.$msg;
var Strophe = converse_api.env.Strophe; var Strophe = converse_api.env.Strophe;
...@@ -42,8 +44,8 @@ ...@@ -42,8 +44,8 @@
var view = this.chatboxviews.get('lounge@localhost'), var view = this.chatboxviews.get('lounge@localhost'),
$participants = view.$('.participant-list'); $participants = view.$('.participant-list');
spyOn(view, 'onChatRoomPresence').andCallThrough(); spyOn(view, 'onChatRoomPresence').andCallThrough();
var presence, room = {}, i, role; var presence, role;
for (i=0; i<mock.chatroom_names.length; i++) { for (var i=0; i<mock.chatroom_names.length; i++) {
name = mock.chatroom_names[i]; name = mock.chatroom_names[i];
role = mock.chatroom_roles[name].role; role = mock.chatroom_roles[name].role;
// See example 21 http://xmpp.org/extensions/xep-0045.html#enter-pres // See example 21 http://xmpp.org/extensions/xep-0045.html#enter-pres
...@@ -117,13 +119,13 @@ ...@@ -117,13 +119,13 @@
spyOn(window, 'prompt').andCallFake(function () { spyOn(window, 'prompt').andCallFake(function () {
return null; return null;
}); });
var roster = {}, $input; var $input;
var view = this.chatboxviews.get('lounge@localhost'); var view = this.chatboxviews.get('lounge@localhost');
view.$el.find('.chat-area').remove(); view.$el.find('.chat-area').remove();
view.renderChatArea(); // Will init the widget view.renderChatArea(); // Will init the widget
test_utils.createContacts('current'); // We need roster contacts, so that we have someone to invite test_utils.createContacts('current'); // We need roster contacts, so that we have someone to invite
$input = view.$el.find('input.invited-contact.tt-input'); $input = view.$el.find('input.invited-contact.tt-input');
$hint = view.$el.find('input.invited-contact.tt-hint'); var $hint = view.$el.find('input.invited-contact.tt-hint');
runs (function () { runs (function () {
expect($input.length).toBe(1); expect($input.length).toBe(1);
expect($input.attr('placeholder')).toBe('Invite...'); expect($input.attr('placeholder')).toBe('Invite...');
...@@ -198,7 +200,6 @@ ...@@ -198,7 +200,6 @@
spyOn(converse, 'playNotification'); spyOn(converse, 'playNotification');
var view = this.chatboxviews.get('lounge@localhost'); var view = this.chatboxviews.get('lounge@localhost');
if (!view.$el.find('.chat-area').length) { view.renderChatArea(); } if (!view.$el.find('.chat-area').length) { view.renderChatArea(); }
var nick = mock.chatroom_names[0];
var text = 'This message will play a sound because it mentions dummy'; var text = 'This message will play a sound because it mentions dummy';
var message = $msg({ var message = $msg({
from: 'lounge@localhost/otheruser', from: 'lounge@localhost/otheruser',
...@@ -237,7 +238,6 @@ ...@@ -237,7 +238,6 @@
spyOn(converse, 'emit'); spyOn(converse, 'emit');
var view = this.chatboxviews.get('lounge@localhost'); var view = this.chatboxviews.get('lounge@localhost');
if (!view.$el.find('.chat-area').length) { view.renderChatArea(); } if (!view.$el.find('.chat-area').length) { view.renderChatArea(); }
var nick = mock.chatroom_names[0];
var text = 'This is a sent message'; var text = 'This is a sent message';
view.$el.find('.chat-textarea').text(text); view.$el.find('.chat-textarea').text(text);
view.$el.find('textarea.chat-textarea').trigger($.Event('keypress', {keyCode: 13})); view.$el.find('textarea.chat-textarea').trigger($.Event('keypress', {keyCode: 13}));
...@@ -318,7 +318,7 @@ ...@@ -318,7 +318,7 @@
this.connection._dataRecv(test_utils.createRequest(presence)); this.connection._dataRecv(test_utils.createRequest(presence));
expect(view.onChatRoomPresence).toHaveBeenCalled(); expect(view.onChatRoomPresence).toHaveBeenCalled();
$participants = view.$('.participant-list'); var $participants = view.$('.participant-list');
expect($participants.children().length).toBe(1); expect($participants.children().length).toBe(1);
expect($participants.children().first(0).text()).toBe("oldnick"); expect($participants.children().first(0).text()).toBe("oldnick");
expect($chat_content.find('div.chat-info').length).toBe(1); expect($chat_content.find('div.chat-info').length).toBe(1);
...@@ -421,8 +421,9 @@ ...@@ -421,8 +421,9 @@
expect(newchatboxes.length).toEqual(2); expect(newchatboxes.length).toEqual(2);
// Check that the chatrooms retrieved from browserStorage // Check that the chatrooms retrieved from browserStorage
// have the same attributes values as the original ones. // have the same attributes values as the original ones.
attrs = ['id', 'box_id', 'visible']; var attrs = ['id', 'box_id', 'visible'];
for (i=0; i<attrs.length; i++) { var new_attrs, old_attrs;
for (var i=0; i<attrs.length; i++) {
new_attrs = _.pluck(_.pluck(newchatboxes.models, 'attributes'), attrs[i]); new_attrs = _.pluck(_.pluck(newchatboxes.models, 'attributes'), attrs[i]);
old_attrs = _.pluck(_.pluck(this.chatboxes.models, 'attributes'), attrs[i]); old_attrs = _.pluck(_.pluck(this.chatboxes.models, 'attributes'), attrs[i]);
// FIXME: should have have to sort here? Order must // FIXME: should have have to sort here? Order must
...@@ -453,7 +454,7 @@ ...@@ -453,7 +454,7 @@
expect(view.$el.is(':visible')).toBeFalsy(); expect(view.$el.is(':visible')).toBeFalsy();
expect(view.model.get('minimized')).toBeTruthy(); expect(view.model.get('minimized')).toBeTruthy();
expect(view.minimize).toHaveBeenCalled(); expect(view.minimize).toHaveBeenCalled();
trimmedview = trimmed_chatboxes.get(view.model.get('id')); var trimmedview = trimmed_chatboxes.get(view.model.get('id'));
trimmedview.$("a.restore-chat").click(); trimmedview.$("a.restore-chat").click();
}); });
waits(250); waits(250);
...@@ -469,7 +470,7 @@ ...@@ -469,7 +470,7 @@
it("can be closed again by clicking a DOM element with class 'close-chatbox-button'", function () { it("can be closed again by clicking a DOM element with class 'close-chatbox-button'", function () {
test_utils.openChatRoom('lounge', 'localhost', 'dummy'); test_utils.openChatRoom('lounge', 'localhost', 'dummy');
var view = this.chatboxviews.get('lounge@localhost'), chatroom = view.model, $el; var view = this.chatboxviews.get('lounge@localhost');
spyOn(view, 'close').andCallThrough(); spyOn(view, 'close').andCallThrough();
spyOn(converse, 'emit'); spyOn(converse, 'emit');
spyOn(view, 'leave'); spyOn(view, 'leave');
...@@ -497,10 +498,7 @@ ...@@ -497,10 +498,7 @@
it("to clear messages", function () { it("to clear messages", function () {
test_utils.openChatRoom('lounge', 'localhost', 'dummy'); test_utils.openChatRoom('lounge', 'localhost', 'dummy');
var view = converse.chatboxviews.get('lounge@localhost'), var view = converse.chatboxviews.get('lounge@localhost');
chatroom = view.model,
$chat_content = view.$el.find('.chat-content');
spyOn(view, 'onChatRoomMessageSubmitted').andCallThrough(); spyOn(view, 'onChatRoomMessageSubmitted').andCallThrough();
spyOn(view, 'clearChatRoomMessages'); spyOn(view, 'clearChatRoomMessages');
view.$el.find('.chat-textarea').text('/clear'); view.$el.find('.chat-textarea').text('/clear');
...@@ -512,10 +510,7 @@ ...@@ -512,10 +510,7 @@
it("to ban a user", function () { it("to ban a user", function () {
test_utils.openChatRoom('lounge', 'localhost', 'dummy'); test_utils.openChatRoom('lounge', 'localhost', 'dummy');
var view = converse.chatboxviews.get('lounge@localhost'), var view = converse.chatboxviews.get('lounge@localhost');
chatroom = view.model,
$chat_content = view.$el.find('.chat-content');
spyOn(view, 'onChatRoomMessageSubmitted').andCallThrough(); spyOn(view, 'onChatRoomMessageSubmitted').andCallThrough();
spyOn(view, 'setAffiliation').andCallThrough(); spyOn(view, 'setAffiliation').andCallThrough();
spyOn(view, 'showStatusNotification').andCallThrough(); spyOn(view, 'showStatusNotification').andCallThrough();
......
/*global converse */
(function (root, factory) { (function (root, factory) {
define([ define([
"jquery", "jquery",
"underscore",
"mock", "mock",
"test_utils" "test_utils"
], function ($, mock, test_utils) { ], function ($, _, mock, test_utils) {
return factory($, mock, test_utils); return factory($, _, mock, test_utils);
} }
); );
} (this, function ($, mock, test_utils) { } (this, function ($, _, mock, test_utils) {
var $pres = converse_api.env.$pres; var $pres = converse_api.env.$pres;
var $iq = converse_api.env.$iq; var $iq = converse_api.env.$iq;
...@@ -138,7 +140,7 @@ ...@@ -138,7 +140,7 @@
var names = mock.cur_names; var names = mock.cur_names;
expect($filter.length).toBe(1); expect($filter.length).toBe(1);
expect($filter.is(':visible')).toBeFalsy(); expect($filter.is(':visible')).toBeFalsy();
for (i=0; i<names.length; i++) { for (var i=0; i<names.length; i++) {
converse.roster.create({ converse.roster.create({
ask: null, ask: null,
fullname: names[i], fullname: names[i],
...@@ -255,7 +257,6 @@ ...@@ -255,7 +257,6 @@
_clearContacts(); _clearContacts();
utils.createGroupedContacts(); utils.createGroupedContacts();
var $filter = converse.rosterview.$('.roster-filter'); var $filter = converse.rosterview.$('.roster-filter');
var $roster = converse.rosterview.$roster;
runs (function () { runs (function () {
$filter.val("xxx"); $filter.val("xxx");
$filter.trigger('keydown'); $filter.trigger('keydown');
...@@ -316,7 +317,7 @@ ...@@ -316,7 +317,7 @@
var groups = ['colleagues', 'friends']; var groups = ['colleagues', 'friends'];
runs($.proxy(function () { runs($.proxy(function () {
_clearContacts(); _clearContacts();
var i=0, j=0; var i=0;
spyOn(converse, 'emit'); spyOn(converse, 'emit');
spyOn(this.rosterview, 'update').andCallThrough(); spyOn(this.rosterview, 'update').andCallThrough();
converse.rosterview.render(); converse.rosterview.render();
...@@ -484,7 +485,7 @@ ...@@ -484,7 +485,7 @@
}, this)); }, this));
waits(50); waits(50);
runs($.proxy(function () { runs($.proxy(function () {
contact = this.roster.create({ this.roster.create({
jid: name.replace(/ /g,'.').toLowerCase() + '@localhost', jid: name.replace(/ /g,'.').toLowerCase() + '@localhost',
subscription: 'none', subscription: 'none',
ask: 'subscribe', ask: 'subscribe',
...@@ -508,7 +509,7 @@ ...@@ -508,7 +509,7 @@
_addContacts(); _addContacts();
var name; var name;
spyOn(window, 'confirm').andReturn(true); spyOn(window, 'confirm').andReturn(true);
for (i=0; i<mock.pend_names.length; i++) { for (var i=0; i<mock.pend_names.length; i++) {
name = mock.pend_names[i]; name = mock.pend_names[i];
converse.rosterview.$el.find(".pending-contact-name:contains('"+name+"')") converse.rosterview.$el.find(".pending-contact-name:contains('"+name+"')")
.siblings('.remove-xmpp-contact').click(); .siblings('.remove-xmpp-contact').click();
...@@ -661,7 +662,7 @@ ...@@ -661,7 +662,7 @@
var jid, t; var jid, t;
spyOn(converse, 'emit'); spyOn(converse, 'emit');
spyOn(this.rosterview, 'update').andCallThrough(); spyOn(this.rosterview, 'update').andCallThrough();
for (i=0; i<mock.cur_names.length; i++) { for (var i=0; i<mock.cur_names.length; i++) {
jid = mock.cur_names[i].replace(/ /g,'.').toLowerCase() + '@localhost'; jid = mock.cur_names[i].replace(/ /g,'.').toLowerCase() + '@localhost';
this.roster.get(jid).set('chat_status', 'online'); this.roster.get(jid).set('chat_status', 'online');
expect(this.rosterview.update).toHaveBeenCalled(); expect(this.rosterview.update).toHaveBeenCalled();
...@@ -681,7 +682,7 @@ ...@@ -681,7 +682,7 @@
var jid, t; var jid, t;
spyOn(converse, 'emit'); spyOn(converse, 'emit');
spyOn(this.rosterview, 'update').andCallThrough(); spyOn(this.rosterview, 'update').andCallThrough();
for (i=0; i<mock.cur_names.length; i++) { for (var i=0; i<mock.cur_names.length; i++) {
jid = mock.cur_names[i].replace(/ /g,'.').toLowerCase() + '@localhost'; jid = mock.cur_names[i].replace(/ /g,'.').toLowerCase() + '@localhost';
this.roster.get(jid).set('chat_status', 'dnd'); this.roster.get(jid).set('chat_status', 'dnd');
expect(this.rosterview.update).toHaveBeenCalled(); expect(this.rosterview.update).toHaveBeenCalled();
...@@ -701,7 +702,7 @@ ...@@ -701,7 +702,7 @@
var jid, t; var jid, t;
spyOn(converse, 'emit'); spyOn(converse, 'emit');
spyOn(this.rosterview, 'update').andCallThrough(); spyOn(this.rosterview, 'update').andCallThrough();
for (i=0; i<mock.cur_names.length; i++) { for (var i=0; i<mock.cur_names.length; i++) {
jid = mock.cur_names[i].replace(/ /g,'.').toLowerCase() + '@localhost'; jid = mock.cur_names[i].replace(/ /g,'.').toLowerCase() + '@localhost';
this.roster.get(jid).set('chat_status', 'away'); this.roster.get(jid).set('chat_status', 'away');
expect(this.rosterview.update).toHaveBeenCalled(); expect(this.rosterview.update).toHaveBeenCalled();
...@@ -721,7 +722,7 @@ ...@@ -721,7 +722,7 @@
var jid, t; var jid, t;
spyOn(converse, 'emit'); spyOn(converse, 'emit');
spyOn(this.rosterview, 'update').andCallThrough(); spyOn(this.rosterview, 'update').andCallThrough();
for (i=0; i<mock.cur_names.length; i++) { for (var i=0; i<mock.cur_names.length; i++) {
jid = mock.cur_names[i].replace(/ /g,'.').toLowerCase() + '@localhost'; jid = mock.cur_names[i].replace(/ /g,'.').toLowerCase() + '@localhost';
this.roster.get(jid).set('chat_status', 'xa'); this.roster.get(jid).set('chat_status', 'xa');
expect(this.rosterview.update).toHaveBeenCalled(); expect(this.rosterview.update).toHaveBeenCalled();
...@@ -741,7 +742,7 @@ ...@@ -741,7 +742,7 @@
var jid, t; var jid, t;
spyOn(converse, 'emit'); spyOn(converse, 'emit');
spyOn(this.rosterview, 'update').andCallThrough(); spyOn(this.rosterview, 'update').andCallThrough();
for (i=0; i<mock.cur_names.length; i++) { for (var i=0; i<mock.cur_names.length; i++) {
jid = mock.cur_names[i].replace(/ /g,'.').toLowerCase() + '@localhost'; jid = mock.cur_names[i].replace(/ /g,'.').toLowerCase() + '@localhost';
this.roster.get(jid).set('chat_status', 'unavailable'); this.roster.get(jid).set('chat_status', 'unavailable');
expect(this.rosterview.update).toHaveBeenCalled(); expect(this.rosterview.update).toHaveBeenCalled();
...@@ -758,7 +759,7 @@ ...@@ -758,7 +759,7 @@
}); });
waits(50); waits(50);
runs($.proxy(function () { runs($.proxy(function () {
var i; var i, jid;
for (i=0; i<3; i++) { for (i=0; i<3; i++) {
jid = mock.cur_names[i].replace(/ /g,'.').toLowerCase() + '@localhost'; jid = mock.cur_names[i].replace(/ /g,'.').toLowerCase() + '@localhost';
this.roster.get(jid).set('chat_status', 'online'); this.roster.get(jid).set('chat_status', 'online');
...@@ -1010,7 +1011,7 @@ ...@@ -1010,7 +1011,7 @@
it("are saved to, and can be retrieved from, browserStorage", $.proxy(function () { it("are saved to, and can be retrieved from, browserStorage", $.proxy(function () {
var new_attrs, old_attrs, attrs; var new_attrs, old_attrs, attrs;
var num_contacts = this.roster.length; var num_contacts = this.roster.length;
new_roster = new this.RosterContacts(); var new_roster = new this.RosterContacts();
// Roster items are yet to be fetched from browserStorage // Roster items are yet to be fetched from browserStorage
expect(new_roster.length).toEqual(0); expect(new_roster.length).toEqual(0);
new_roster.browserStorage = this.roster.browserStorage; new_roster.browserStorage = this.roster.browserStorage;
...@@ -1019,7 +1020,7 @@ ...@@ -1019,7 +1020,7 @@
// Check that the roster items retrieved from browserStorage // Check that the roster items retrieved from browserStorage
// have the same attributes values as the original ones. // have the same attributes values as the original ones.
attrs = ['jid', 'fullname', 'subscription', 'ask']; attrs = ['jid', 'fullname', 'subscription', 'ask'];
for (i=0; i<attrs.length; i++) { for (var i=0; i<attrs.length; i++) {
new_attrs = _.pluck(_.pluck(new_roster.models, 'attributes'), attrs[i]); new_attrs = _.pluck(_.pluck(new_roster.models, 'attributes'), attrs[i]);
old_attrs = _.pluck(_.pluck(this.roster.models, 'attributes'), attrs[i]); old_attrs = _.pluck(_.pluck(this.roster.models, 'attributes'), attrs[i]);
// Roster items in storage are not necessarily sorted, // Roster items in storage are not necessarily sorted,
...@@ -1030,7 +1031,7 @@ ...@@ -1030,7 +1031,7 @@
}, converse)); }, converse));
it("will show fullname and jid properties on tooltip", $.proxy(function () { it("will show fullname and jid properties on tooltip", $.proxy(function () {
var jid, name, i, t; var jid, name, i;
for (i=0; i<mock.cur_names.length; i++) { for (i=0; i<mock.cur_names.length; i++) {
name = mock.cur_names[i]; name = mock.cur_names[i];
jid = name.replace(/ /g,'.').toLowerCase() + '@localhost'; jid = name.replace(/ /g,'.').toLowerCase() + '@localhost';
......
/*global converse */
(function (root, factory) { (function (root, factory) {
define([ define([
"jquery", "jquery",
"underscore",
"mock", "mock",
"test_utils" "test_utils"
], function ($, mock, test_utils) { ], function ($, _, mock, test_utils) {
return factory($, mock, test_utils); return factory($, _, mock, test_utils);
} }
); );
} (this, function ($, mock, test_utils) { } (this, function ($, _, mock, test_utils) {
var b64_sha1 = converse_api.env.b64_sha1; var b64_sha1 = converse_api.env.b64_sha1;
return describe("Converse", $.proxy(function(mock, test_utils) { return describe("Converse", $.proxy(function(mock, test_utils) {
......
/*global converse */
(function (root, factory) { (function (root, factory) {
define([ define([
"jquery", "jquery",
......
/*global converse */
(function (root, factory) { (function (root, factory) {
define([ define([
"jquery", "jquery",
......
/*global converse */
(function (root, factory) { (function (root, factory) {
define([ define([
"jquery", "jquery",
"underscore",
"mock", "mock",
"test_utils" "test_utils"
], function ($, mock, test_utils) { ], function ($, _, mock, test_utils) {
return factory($, mock, test_utils); return factory($, _, mock, test_utils);
} }
); );
} (this, function ($, mock, test_utils) { } (this, function ($, _, mock, test_utils) {
"use strict"; "use strict";
var Strophe = converse_api.env.Strophe; var Strophe = converse_api.env.Strophe;
var $iq = converse_api.env.$iq; var $iq = converse_api.env.$iq;
var $pres = converse_api.env.$pres;
var $msg = converse_api.env.$msg; var $msg = converse_api.env.$msg;
var moment = converse_api.env.moment; var moment = converse_api.env.moment;
// See: https://xmpp.org/rfcs/rfc3921.html // See: https://xmpp.org/rfcs/rfc3921.html
......
/*global converse */
(function (root, factory) { (function (root, factory) {
define([ define([
"jquery", "jquery",
"underscore",
"mock", "mock",
"test_utils" "test_utils"
], function ($, mock, test_utils) { ], function ($, _, mock, test_utils) {
return factory($, mock, test_utils); return factory($, _, mock, test_utils);
} }
); );
} (this, function ($, mock, test_utils) { } (this, function ($, _, mock, test_utils) {
var $msg = converse_api.env.$msg; var $msg = converse_api.env.$msg;
return describe("The Minimized Chats Widget", $.proxy(function(mock, test_utils) { return describe("The Minimized Chats Widget", $.proxy(function(mock, test_utils) {
...@@ -67,7 +69,6 @@ ...@@ -67,7 +69,6 @@
it("shows the number messages received to minimized chats", $.proxy(function () { it("shows the number messages received to minimized chats", $.proxy(function () {
var i, contact_jid, chatview, msg; var i, contact_jid, chatview, msg;
var sender_jid = mock.cur_names[4].replace(/ /g,'.').toLowerCase() + '@localhost';
this.minimized_chats.toggleview.model.set({'collapsed': true}); this.minimized_chats.toggleview.model.set({'collapsed': true});
expect(this.minimized_chats.toggleview.$('.unread-message-count').is(':visible')).toBeFalsy(); expect(this.minimized_chats.toggleview.$('.unread-message-count').is(':visible')).toBeFalsy();
for (i=0; i<3; i++) { for (i=0; i<3; i++) {
......
/*global converse */
(function (root, factory) { (function (root, factory) {
define([ define([
"jquery", "jquery",
......
/*global converse */
(function (root, factory) { (function (root, factory) {
define([ define([
"jquery", "jquery",
"underscore",
"mock", "mock",
"test_utils" "test_utils"
], function ($, mock, test_utils) { ], function ($, _, mock, test_utils) {
return factory($, mock, test_utils); return factory($, _, mock, test_utils);
} }
); );
} (this, function ($, mock, test_utils) { } (this, function ($, _, mock, test_utils) {
var Strophe = converse_api.env.Strophe; var Strophe = converse_api.env.Strophe;
var $iq = converse_api.env.$iq; var $iq = converse_api.env.$iq;
......
/*global converse */
(function (root, factory) { (function (root, factory) {
define([ define([
"jquery", "jquery",
...@@ -9,7 +10,6 @@ ...@@ -9,7 +10,6 @@
); );
} (this, function ($, mock, test_utils) { } (this, function ($, mock, test_utils) {
"use strict"; "use strict";
var Strophe = converse_api.env.Strophe;
var $iq = converse_api.env.$iq; var $iq = converse_api.env.$iq;
var $pres = converse_api.env.$pres; var $pres = converse_api.env.$pres;
// See: // See:
...@@ -355,7 +355,7 @@ ...@@ -355,7 +355,7 @@
/* The process by which a user subscribes to a contact, including /* The process by which a user subscribes to a contact, including
* the interaction between roster items and subscription states. * the interaction between roster items and subscription states.
*/ */
var contact, stanza, sent_stanza, sent_IQ, IQ_id; var contact, stanza, sent_stanza, sent_IQ;
runs($.proxy(function () { runs($.proxy(function () {
// Add a new roster contact via roster push // Add a new roster contact via roster push
stanza = $iq({'type': 'set'}).c('query', {'xmlns': 'jabber:iq:roster'}) stanza = $iq({'type': 'set'}).c('query', {'xmlns': 'jabber:iq:roster'})
...@@ -373,11 +373,9 @@ ...@@ -373,11 +373,9 @@
expect(this.roster.get('contact@example.org') instanceof this.RosterContact).toBeTruthy(); expect(this.roster.get('contact@example.org') instanceof this.RosterContact).toBeTruthy();
spyOn(contact, "ackUnsubscribe").andCallThrough(); spyOn(contact, "ackUnsubscribe").andCallThrough();
var send = this.connection.send;
spyOn(converse.connection, 'send').andCallFake(function (stanza) { spyOn(converse.connection, 'send').andCallFake(function (stanza) {
sent_stanza = stanza; sent_stanza = stanza;
}); });
var sendIQ = this.connection.sendIQ;
spyOn(this.connection, 'sendIQ').andCallFake(function (iq, callback, errback) { spyOn(this.connection, 'sendIQ').andCallFake(function (iq, callback, errback) {
sent_IQ = iq; sent_IQ = iq;
}); });
......
/*global converse */
(function (root, factory) { (function (root, factory) {
define([ define([
"jquery", "jquery",
...@@ -14,7 +15,7 @@ ...@@ -14,7 +15,7 @@
describe("The Registration Panel", $.proxy(function (mock, test_utils) { describe("The Registration Panel", $.proxy(function (mock, test_utils) {
beforeEach(function () { beforeEach(function () {
test_utils.closeControlBox(); test_utils.closeControlBox();
connection = mock.mock_connection; var connection = mock.mock_connection;
connection.connected = false; connection.connected = false;
converse._tearDown(); converse._tearDown();
converse.initialize({ converse.initialize({
......
/*global converse */
(function (root, factory) { (function (root, factory) {
define([ define([
"jquery", "jquery",
......
define("converse-dependencies", [ define("converse-dependencies", [
"jquery", "jquery",
"underscore",
"polyfill", "polyfill",
"utils", "utils",
"otr", "otr",
...@@ -13,7 +14,7 @@ define("converse-dependencies", [ ...@@ -13,7 +14,7 @@ define("converse-dependencies", [
"backbone.overview", "backbone.overview",
"jquery.browser", "jquery.browser",
"typeahead" "typeahead"
], function($, dummy, utils, otr, moment, Strophe) { ], function($, _, dummy, utils, otr, moment, Strophe) {
return _.extend({ return _.extend({
'underscore': _, 'underscore': _,
'jQuery': $, 'jQuery': $,
......
define("converse-dependencies", [ define("converse-dependencies", [
"jquery", "jquery",
"underscore",
"utils", "utils",
"polyfill", "polyfill",
"moment_with_locales", "moment_with_locales",
...@@ -12,7 +13,7 @@ define("converse-dependencies", [ ...@@ -12,7 +13,7 @@ define("converse-dependencies", [
"backbone.overview", "backbone.overview",
"jquery.browser", "jquery.browser",
"typeahead" "typeahead"
], function($, dummy, utils, moment, Strophe) { ], function($, _, dummy, utils, moment, Strophe) {
return _.extend({ return _.extend({
'underscore': _, 'underscore': _,
'jQuery': $, 'jQuery': $,
......
/*global jQuery */
define('jquery', [], function () { define('jquery', [], function () {
return jQuery; return jQuery;
}); });
/*global $ */
(function (root, factory) { (function (root, factory) {
if (typeof console === "undefined" || typeof console.log === "undefined") {
console = { log: function () {}, error: function () {} };
}
if (typeof define === 'function' && define.amd) { if (typeof define === 'function' && define.amd) {
define("converse", ["jquery"], function($) { define("converse", ["jquery"], function($) {
return factory($); return factory($);
......
/*global jQuery, templates, escape, Jed, _ */
(function (root, factory) { (function (root, factory) {
if (typeof define === 'function' && define.amd) { if (typeof define === 'function' && define.amd) {
define(["jquery", "converse-templates", "locales"], factory); define(["jquery", "underscore", "converse-templates", "locales"], factory);
} else { } else {
root.utils = factory(jQuery, templates); root.utils = factory(jQuery, _, templates);
} }
}(this, function ($, templates, locales) { }(this, function ($, _, templates, locales) {
"use strict"; "use strict";
var XFORM_TYPE_MAP = { var XFORM_TYPE_MAP = {
...@@ -156,7 +157,7 @@ ...@@ -156,7 +157,7 @@
// FIXME: take <required> into consideration // FIXME: take <required> into consideration
var options = [], j, $options, $values, value, values; var options = [], j, $options, $values, value, values;
if ($field.attr('type') == 'list-single' || $field.attr('type') == 'list-multi') { if ($field.attr('type') === 'list-single' || $field.attr('type') === 'list-multi') {
values = []; values = [];
$values = $field.children('value'); $values = $field.children('value');
for (j=0; j<$values.length; j++) { for (j=0; j<$values.length; j++) {
...@@ -176,19 +177,19 @@ ...@@ -176,19 +177,19 @@
name: $field.attr('var'), name: $field.attr('var'),
label: $field.attr('label'), label: $field.attr('label'),
options: options.join(''), options: options.join(''),
multiple: ($field.attr('type') == 'list-multi'), multiple: ($field.attr('type') === 'list-multi'),
required: $field.find('required').length required: $field.find('required').length
}); });
} else if ($field.attr('type') == 'fixed') { } else if ($field.attr('type') === 'fixed') {
return $('<p class="form-help">').text($field.find('value').text()); return $('<p class="form-help">').text($field.find('value').text());
} else if ($field.attr('type') == 'jid-multi') { } else if ($field.attr('type') === 'jid-multi') {
return templates.form_textarea({ return templates.form_textarea({
name: $field.attr('var'), name: $field.attr('var'),
label: $field.attr('label') || '', label: $field.attr('label') || '',
value: $field.find('value').text(), value: $field.find('value').text(),
required: $field.find('required').length required: $field.find('required').length
}); });
} else if ($field.attr('type') == 'boolean') { } else if ($field.attr('type') === 'boolean') {
return templates.form_checkbox({ return templates.form_checkbox({
name: $field.attr('var'), name: $field.attr('var'),
type: XFORM_TYPE_MAP[$field.attr('type')], type: XFORM_TYPE_MAP[$field.attr('type')],
......
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