Commit ff345dcf authored by JC Brand's avatar JC Brand

Move mock.js to tests dir. Add utils.js

Both changes from tests-refactor branch
parent f9c096c0
(function (root, factory) { (function (root, factory) {
define([ define([
"mock" "mock",
], function (mock_connection) { "utils"
return factory(mock_connection); ], function (mock, utils) {
return factory(mock, utils);
} }
); );
} (this, function (mock_connection) { } (this, function (mock, utils) {
return describe("ChatRooms", $.proxy(function() { var chatrooms_spec_callback = function(mock, utils) {
var chatroom_names = [
'Dyon van de Wege', 'Thomas Kalb', 'Dirk Theissen', 'Felix Hofmann', 'Ka Lek', 'Anne Ebersbacher'
];
closeChatRoom = function (name) {
converse.chatboxesview.views['lounge@muc.localhost'].closeChat();
};
describe("A Chat Room", $.proxy(function () { describe("A Chat Room", $.proxy(function () {
beforeEach($.proxy(function () { beforeEach($.proxy(function () {
if (!$("div#controlbox").is(':visible')) { if (!$("div#controlbox").is(':visible')) {
...@@ -35,12 +29,12 @@ ...@@ -35,12 +29,12 @@
$participant_list; $participant_list;
var roster = {}, room = {}, i; var roster = {}, room = {}, i;
for (i=0; i<chatroom_names.length-1; i++) { for (i=0; i<mock.chatroom_names.length-1; i++) {
roster[chatroom_names[i]] = {}; roster[mock.chatroom_names[i]] = {};
chatroomview.onChatRoomRoster(roster, room); chatroomview.onChatRoomRoster(roster, room);
$participant_list = chatroomview.$el.find('.participant-list'); $participant_list = chatroomview.$el.find('.participant-list');
expect($participant_list.find('li').length).toBe(1+i); expect($participant_list.find('li').length).toBe(1+i);
expect($($participant_list.find('li')[i]).text()).toBe(chatroom_names[i]); expect($($participant_list.find('li')[i]).text()).toBe(mock.chatroom_names[i]);
} }
roster[converse.bare_jid] = {}; roster[converse.bare_jid] = {};
chatroomview.onChatRoomRoster(roster, room); chatroomview.onChatRoomRoster(roster, room);
...@@ -48,13 +42,13 @@ ...@@ -48,13 +42,13 @@
it("indicates moderators by means of a special css class and tooltip", $.proxy(function () { it("indicates moderators by means of a special css class and tooltip", $.proxy(function () {
var chatroomview = this.chatboxesview.views['lounge@muc.localhost']; var chatroomview = this.chatboxesview.views['lounge@muc.localhost'];
var roster = {}, idx = chatroom_names.length-1; var roster = {}, idx = mock.chatroom_names.length-1;
roster[chatroom_names[idx]] = {}; roster[mock.chatroom_names[idx]] = {};
roster[chatroom_names[idx]].role = 'moderator'; roster[mock.chatroom_names[idx]].role = 'moderator';
chatroomview.onChatRoomRoster(roster, {}); chatroomview.onChatRoomRoster(roster, {});
var occupant = chatroomview.$el.find('.participant-list').find('li'); var occupant = chatroomview.$el.find('.participant-list').find('li');
expect(occupant.length).toBe(1); expect(occupant.length).toBe(1);
expect($(occupant).text()).toBe(chatroom_names[idx]); expect($(occupant).text()).toBe(mock.chatroom_names[idx]);
expect($(occupant).attr('class')).toBe('moderator'); expect($(occupant).attr('class')).toBe('moderator');
expect($(occupant).attr('title')).toBe('This user is a moderator'); expect($(occupant).attr('title')).toBe('This user is a moderator');
}, converse)); }, converse));
...@@ -62,7 +56,7 @@ ...@@ -62,7 +56,7 @@
it("shows received and sent groupchat messages", $.proxy(function () { it("shows received and sent groupchat messages", $.proxy(function () {
var view = this.chatboxesview.views['lounge@muc.localhost']; var view = this.chatboxesview.views['lounge@muc.localhost'];
if (!view.$el.find('.chat-area').length) { view.renderChatArea(); } if (!view.$el.find('.chat-area').length) { view.renderChatArea(); }
var nick = chatroom_names[0]; var nick = mock.chatroom_names[0];
var text = 'This is a received message'; var text = 'This is a received message';
var message = $msg({ var message = $msg({
from: 'lounge@muc.localhost/'+nick, from: 'lounge@muc.localhost/'+nick,
...@@ -268,5 +262,6 @@ ...@@ -268,5 +262,6 @@
expect(view.$el.find('.chat-body p').text()).toBe("This room has reached it's maximum number of occupants"); expect(view.$el.find('.chat-body p').text()).toBe("This room has reached it's maximum number of occupants");
}, converse)); }, converse));
}, converse)); }, converse));
}, converse)); };
return describe("ChatRooms", chatrooms_spec_callback.bind(converse, mock, utils));
})); }));
This diff is collapsed.
...@@ -5,7 +5,26 @@ ...@@ -5,7 +5,26 @@
return factory(); return factory();
}); });
}(this, function (converse) { }(this, function (converse) {
var mock_connection = { var mock = {};
// Names from http://www.fakenamegenerator.com/
mock.req_names = [
'Louw Spekman', 'Mohamad Stet', 'Dominik Beyer'
];
mock.pend_names = [
'Suleyman van Beusichem', 'Nanja van Yperen', 'Nicole Diederich'
];
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.chatroom_names = [
'Dyon van de Wege', 'Thomas Kalb', 'Dirk Theissen', 'Felix Hofmann', 'Ka Lek', 'Anne Ebersbacher'
];
mock.mock_connection = {
'muc': { 'muc': {
'listRooms': function () {}, 'listRooms': function () {},
'join': function () {}, 'join': function () {},
...@@ -48,5 +67,5 @@ ...@@ -48,5 +67,5 @@
'items': function () {} 'items': function () {}
} }
}; };
return mock_connection; return mock;
})); }));
(function (root, factory) {
define("utils", ['jquery'],
function($) {
return factory($);
});
}(this, function ($) {
var utils = {};
utils.closeAllChatBoxes = function () {
var i, chatbox, num_chatboxes = converse.chatboxes.models.length;
for (i=num_chatboxes-1; i>-1; i--) {
chatbox = converse.chatboxes.models[i];
converse.chatboxesview.views[chatbox.get('id')].closeChat();
}
return this;
};
utils.removeAllChatBoxes = function () {
var i, chatbox, num_chatboxes = converse.chatboxes.models.length;
for (i=num_chatboxes-1; i>-1; i--) {
chatbox = converse.chatboxes.models[i];
converse.chatboxesview.views[chatbox.get('id')].closeChat();
converse.chatboxesview.views[chatbox.get('id')].$el.remove();
}
converse.chatboxesview.views.controlbox.closeChat();
converse.chatboxesview.views.controlbox.$el.remove();
return this;
};
utils.initRoster = function () {
converse.roster.localStorage._clear();
converse.initRoster();
};
utils.openControlBox = function () {
if (!$("#controlbox").is(':visible')) {
$('.toggle-online-users').click();
}
return this;
};
utils.openContactsPanel = function () {
var cbview = converse.chatboxesview.views.controlbox;
var $tabs = cbview.$el.find('#controlbox-tabs');
$tabs.find('li').first().find('a').click();
};
utils.createContactsRoster = function () {
for (i=0; i<cur_names.length; i++) {
this.roster.create({
jid: cur_names[i].replace(' ','.').toLowerCase() + '@localhost',
subscription: 'both',
ask: null,
fullname: cur_names[i],
is_last: i===(cur_names.length-1)
});
}
return this;
};
return utils;
}));
...@@ -18,6 +18,8 @@ require.config({ ...@@ -18,6 +18,8 @@ require.config({
"salsa20": "components/otr/build/dep/salsa20", "salsa20": "components/otr/build/dep/salsa20",
"crypto.aes": "components/crypto-js/build/rollups/aes", "crypto.aes": "components/crypto-js/build/rollups/aes",
// Extra test dependencies // Extra test dependencies
"mock": "tests/mock",
"utils": "tests/utils",
"jasmine": "components/jasmine/lib/jasmine-core/jasmine", "jasmine": "components/jasmine/lib/jasmine-core/jasmine",
"jasmine-html": "components/jasmine/lib/jasmine-core/jasmine-html", "jasmine-html": "components/jasmine/lib/jasmine-core/jasmine-html",
"jasmine-console-reporter": "node_modules/jasmine-reporters/src/jasmine.console_reporter", "jasmine-console-reporter": "node_modules/jasmine-reporters/src/jasmine.console_reporter",
...@@ -85,7 +87,7 @@ require([ ...@@ -85,7 +87,7 @@ require([
"converse", "converse",
"mock", "mock",
"jasmine-html" "jasmine-html"
], function($, converse, mock_connection, jasmine) { ], function($, converse, mock, jasmine) {
// Set up converse.js // Set up converse.js
window.localStorage.clear(); window.localStorage.clear();
converse.initialize({ converse.initialize({
...@@ -93,7 +95,7 @@ require([ ...@@ -93,7 +95,7 @@ require([
xhr_user_search: false, xhr_user_search: false,
auto_subscribe: false, auto_subscribe: false,
animate: false, animate: false,
connection: mock_connection, connection: mock.mock_connection,
testing: true testing: true
}, function (converse) { }, function (converse) {
window.converse = converse; window.converse = converse;
...@@ -117,7 +119,7 @@ require([ ...@@ -117,7 +119,7 @@ require([
jasmineEnv.specFilter = function(spec) { jasmineEnv.specFilter = function(spec) {
return htmlReporter.specFilter(spec); return htmlReporter.specFilter(spec);
}; };
jasmineEnv.updateInterval = 200; jasmineEnv.updateInterval = 20;
} }
jasmineEnv.execute(); jasmineEnv.execute();
}); });
......
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