Fix tests
This commit is contained in:
parent
8467dc7016
commit
946bb7730b
21
converse.js
21
converse.js
@ -1251,6 +1251,11 @@
|
|||||||
this.$el.find('.chatroom-form').on('submit', $.proxy(this.submitPassword, this));
|
this.$el.find('.chatroom-form').on('submit', $.proxy(this.submitPassword, this));
|
||||||
},
|
},
|
||||||
|
|
||||||
|
renderErrorMessage: function (msg) {
|
||||||
|
this.$el.find('img.centered.spinner').remove();
|
||||||
|
this.$el.find('.chat-body').append($('<p>'+msg+'</p>'));
|
||||||
|
},
|
||||||
|
|
||||||
submitPassword: function (ev) {
|
submitPassword: function (ev) {
|
||||||
ev.preventDefault();
|
ev.preventDefault();
|
||||||
var password = this.$el.find('.chatroom-form').find('input[type=password]').val();
|
var password = this.$el.find('.chatroom-form').find('input[type=password]').val();
|
||||||
@ -1300,25 +1305,25 @@
|
|||||||
if ($error.find('not-authorized').length) {
|
if ($error.find('not-authorized').length) {
|
||||||
this.renderPasswordForm();
|
this.renderPasswordForm();
|
||||||
} else if ($error.find('registration-required').length) {
|
} else if ($error.find('registration-required').length) {
|
||||||
$chat_content.append('You are not on the member list of this room');
|
this.renderErrorMessage('You are not on the member list of this room');
|
||||||
} else if ($error.find('forbidden').length) {
|
} else if ($error.find('forbidden').length) {
|
||||||
$chat_content.append('You have been banned from this room');
|
this.renderErrorMessage('You have been banned from this room');
|
||||||
}
|
}
|
||||||
} else if ($error.attr('type') == 'modify') {
|
} else if ($error.attr('type') == 'modify') {
|
||||||
if ($error.find('jid-malformed').length) {
|
if ($error.find('jid-malformed').length) {
|
||||||
$chat_content.append('No nickname was specified');
|
this.renderErrorMessage('No nickname was specified');
|
||||||
}
|
}
|
||||||
} else if ($error.attr('type') == 'cancel') {
|
} else if ($error.attr('type') == 'cancel') {
|
||||||
if ($error.find('not-allowed').length) {
|
if ($error.find('not-allowed').length) {
|
||||||
$chat_content.append('You are not allowed to create new rooms');
|
this.renderErrorMessage('You are not allowed to create new rooms');
|
||||||
} else if ($error.find('not-acceptable').length) {
|
} else if ($error.find('not-acceptable').length) {
|
||||||
$chat_content.append("Your nickname doesn't conform to the room's policies");
|
this.renderErrorMessage("Your nickname doesn't conform to the room's policies");
|
||||||
} else if ($error.find('conflict').length) {
|
} else if ($error.find('conflict').length) {
|
||||||
$chat_content.append("Your nickname is already taken");
|
this.renderErrorMessage("Your nickname is already taken");
|
||||||
} else if ($error.find('item-not-found').length) {
|
} else if ($error.find('item-not-found').length) {
|
||||||
$chat_content.append("This room does not (yet) exist");
|
this.renderErrorMessage("This room does not (yet) exist");
|
||||||
} else if ($error.find('service-unavailable').length) {
|
} else if ($error.find('service-unavailable').length) {
|
||||||
$chat_content.append("This room has reached it's maximum number of occupants");
|
this.renderErrorMessage("This room has reached it's maximum number of occupants");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
3
mock.js
3
mock.js
@ -9,7 +9,8 @@
|
|||||||
'muc': {
|
'muc': {
|
||||||
'listRooms': function () {},
|
'listRooms': function () {},
|
||||||
'join': function () {},
|
'join': function () {},
|
||||||
'leave': function () {}
|
'leave': function () {},
|
||||||
|
'removeRoom': function () {}
|
||||||
},
|
},
|
||||||
'jid': 'dummy@localhost',
|
'jid': 'dummy@localhost',
|
||||||
'addHandler': function (handler, ns, name, type, id, from, options) {
|
'addHandler': function (handler, ns, name, type, id, from, options) {
|
||||||
|
@ -27,6 +27,7 @@
|
|||||||
|
|
||||||
it("shows users currently present in the room", $.proxy(function () {
|
it("shows users currently present in the room", $.proxy(function () {
|
||||||
var chatroomview = this.chatboxesview.views['lounge@muc.localhost'];
|
var chatroomview = this.chatboxesview.views['lounge@muc.localhost'];
|
||||||
|
chatroomview.renderChatArea();
|
||||||
var $participant_list = chatroomview.$el.find('.participant-list');
|
var $participant_list = chatroomview.$el.find('.participant-list');
|
||||||
var roster = {}, room = {}, i;
|
var roster = {}, room = {}, i;
|
||||||
|
|
||||||
@ -109,10 +110,21 @@
|
|||||||
.c('x').attrs({xmlns:'http://jabber.org/protocol/muc'}).up()
|
.c('x').attrs({xmlns:'http://jabber.org/protocol/muc'}).up()
|
||||||
.c('error').attrs({by:'coven@chat.shakespeare.lit', type:'auth'})
|
.c('error').attrs({by:'coven@chat.shakespeare.lit', type:'auth'})
|
||||||
.c('not-authorized').attrs({xmlns:'urn:ietf:params:xml:ns:xmpp-stanzas'}).nodeTree;
|
.c('not-authorized').attrs({xmlns:'urn:ietf:params:xml:ns:xmpp-stanzas'}).nodeTree;
|
||||||
|
|
||||||
var view = this.chatboxesview.views['problematic@muc.localhost'];
|
var view = this.chatboxesview.views['problematic@muc.localhost'];
|
||||||
view.onChatRoomPresence(presence, {'nick': 'dummy'});
|
spyOn(converse.connection.muc, 'removeRoom');
|
||||||
var $chat_content = view.$el.find('.chat-content');
|
spyOn(view, 'renderPasswordForm').andCallThrough();
|
||||||
expect($chat_content.text()).toBe('This chatroom requires a password');
|
runs(function () {
|
||||||
|
view.onChatRoomPresence(presence, {'nick': 'dummy'});
|
||||||
|
});
|
||||||
|
waits(250);
|
||||||
|
runs(function () {
|
||||||
|
var $chat_body = view.$el.find('.chat-body');
|
||||||
|
expect(converse.connection.muc.removeRoom).toHaveBeenCalled();
|
||||||
|
expect(view.renderPasswordForm).toHaveBeenCalled();
|
||||||
|
expect($chat_body.find('form.chatroom-form').length).toBe(1);
|
||||||
|
expect($chat_body.find('legend').text()).toBe('This chat room requires a password');
|
||||||
|
});
|
||||||
}, converse));
|
}, converse));
|
||||||
|
|
||||||
it("will show an error message if the room is members-only and the user not included", $.proxy(function () {
|
it("will show an error message if the room is members-only and the user not included", $.proxy(function () {
|
||||||
@ -125,9 +137,11 @@
|
|||||||
.c('error').attrs({by:'coven@chat.shakespeare.lit', type:'auth'})
|
.c('error').attrs({by:'coven@chat.shakespeare.lit', type:'auth'})
|
||||||
.c('registration-required').attrs({xmlns:'urn:ietf:params:xml:ns:xmpp-stanzas'}).nodeTree;
|
.c('registration-required').attrs({xmlns:'urn:ietf:params:xml:ns:xmpp-stanzas'}).nodeTree;
|
||||||
var view = this.chatboxesview.views['problematic@muc.localhost'];
|
var view = this.chatboxesview.views['problematic@muc.localhost'];
|
||||||
|
spyOn(converse.connection.muc, 'removeRoom');
|
||||||
|
spyOn(view, 'renderErrorMessage').andCallThrough();
|
||||||
view.onChatRoomPresence(presence, {'nick': 'dummy'});
|
view.onChatRoomPresence(presence, {'nick': 'dummy'});
|
||||||
var $chat_content = view.$el.find('.chat-content');
|
expect(converse.connection.muc.removeRoom).toHaveBeenCalled();
|
||||||
expect($chat_content.text()).toBe('You are not on the member list of this room');
|
expect(view.$el.find('.chat-body p').text()).toBe('You are not on the member list of this room');
|
||||||
}, converse));
|
}, converse));
|
||||||
|
|
||||||
it("will show an error message if the user has been banned", $.proxy(function () {
|
it("will show an error message if the user has been banned", $.proxy(function () {
|
||||||
@ -140,9 +154,11 @@
|
|||||||
.c('error').attrs({by:'coven@chat.shakespeare.lit', type:'auth'})
|
.c('error').attrs({by:'coven@chat.shakespeare.lit', type:'auth'})
|
||||||
.c('forbidden').attrs({xmlns:'urn:ietf:params:xml:ns:xmpp-stanzas'}).nodeTree;
|
.c('forbidden').attrs({xmlns:'urn:ietf:params:xml:ns:xmpp-stanzas'}).nodeTree;
|
||||||
var view = this.chatboxesview.views['problematic@muc.localhost'];
|
var view = this.chatboxesview.views['problematic@muc.localhost'];
|
||||||
|
spyOn(converse.connection.muc, 'removeRoom');
|
||||||
|
spyOn(view, 'renderErrorMessage').andCallThrough();
|
||||||
view.onChatRoomPresence(presence, {'nick': 'dummy'});
|
view.onChatRoomPresence(presence, {'nick': 'dummy'});
|
||||||
var $chat_content = view.$el.find('.chat-content');
|
expect(converse.connection.muc.removeRoom).toHaveBeenCalled();
|
||||||
expect($chat_content.text()).toBe('You have been banned from this room');
|
expect(view.$el.find('.chat-body p').text()).toBe('You have been banned from this room');
|
||||||
}, converse));
|
}, converse));
|
||||||
|
|
||||||
it("will show an error message if no nickname was specified for the user", $.proxy(function () {
|
it("will show an error message if no nickname was specified for the user", $.proxy(function () {
|
||||||
@ -155,9 +171,11 @@
|
|||||||
.c('error').attrs({by:'coven@chat.shakespeare.lit', type:'modify'})
|
.c('error').attrs({by:'coven@chat.shakespeare.lit', type:'modify'})
|
||||||
.c('jid-malformed').attrs({xmlns:'urn:ietf:params:xml:ns:xmpp-stanzas'}).nodeTree;
|
.c('jid-malformed').attrs({xmlns:'urn:ietf:params:xml:ns:xmpp-stanzas'}).nodeTree;
|
||||||
var view = this.chatboxesview.views['problematic@muc.localhost'];
|
var view = this.chatboxesview.views['problematic@muc.localhost'];
|
||||||
|
spyOn(converse.connection.muc, 'removeRoom');
|
||||||
|
spyOn(view, 'renderErrorMessage').andCallThrough();
|
||||||
view.onChatRoomPresence(presence, {'nick': 'dummy'});
|
view.onChatRoomPresence(presence, {'nick': 'dummy'});
|
||||||
var $chat_content = view.$el.find('.chat-content');
|
expect(converse.connection.muc.removeRoom).toHaveBeenCalled();
|
||||||
expect($chat_content.text()).toBe('No nickname was specified');
|
expect(view.$el.find('.chat-body p').text()).toBe('No nickname was specified');
|
||||||
}, converse));
|
}, converse));
|
||||||
|
|
||||||
it("will show an error message if the user is not allowed to have created the room", $.proxy(function () {
|
it("will show an error message if the user is not allowed to have created the room", $.proxy(function () {
|
||||||
@ -170,9 +188,11 @@
|
|||||||
.c('error').attrs({by:'coven@chat.shakespeare.lit', type:'cancel'})
|
.c('error').attrs({by:'coven@chat.shakespeare.lit', type:'cancel'})
|
||||||
.c('not-allowed').attrs({xmlns:'urn:ietf:params:xml:ns:xmpp-stanzas'}).nodeTree;
|
.c('not-allowed').attrs({xmlns:'urn:ietf:params:xml:ns:xmpp-stanzas'}).nodeTree;
|
||||||
var view = this.chatboxesview.views['problematic@muc.localhost'];
|
var view = this.chatboxesview.views['problematic@muc.localhost'];
|
||||||
|
spyOn(converse.connection.muc, 'removeRoom');
|
||||||
|
spyOn(view, 'renderErrorMessage').andCallThrough();
|
||||||
view.onChatRoomPresence(presence, {'nick': 'dummy'});
|
view.onChatRoomPresence(presence, {'nick': 'dummy'});
|
||||||
var $chat_content = view.$el.find('.chat-content');
|
expect(converse.connection.muc.removeRoom).toHaveBeenCalled();
|
||||||
expect($chat_content.text()).toBe('You are not allowed to create new rooms');
|
expect(view.$el.find('.chat-body p').text()).toBe('You are not allowed to create new rooms');
|
||||||
}, converse));
|
}, converse));
|
||||||
|
|
||||||
it("will show an error message if the user's nickname doesn't conform to room policy", $.proxy(function () {
|
it("will show an error message if the user's nickname doesn't conform to room policy", $.proxy(function () {
|
||||||
@ -185,9 +205,11 @@
|
|||||||
.c('error').attrs({by:'coven@chat.shakespeare.lit', type:'cancel'})
|
.c('error').attrs({by:'coven@chat.shakespeare.lit', type:'cancel'})
|
||||||
.c('not-acceptable').attrs({xmlns:'urn:ietf:params:xml:ns:xmpp-stanzas'}).nodeTree;
|
.c('not-acceptable').attrs({xmlns:'urn:ietf:params:xml:ns:xmpp-stanzas'}).nodeTree;
|
||||||
var view = this.chatboxesview.views['problematic@muc.localhost'];
|
var view = this.chatboxesview.views['problematic@muc.localhost'];
|
||||||
|
spyOn(converse.connection.muc, 'removeRoom');
|
||||||
|
spyOn(view, 'renderErrorMessage').andCallThrough();
|
||||||
view.onChatRoomPresence(presence, {'nick': 'dummy'});
|
view.onChatRoomPresence(presence, {'nick': 'dummy'});
|
||||||
var $chat_content = view.$el.find('.chat-content');
|
expect(converse.connection.muc.removeRoom).toHaveBeenCalled();
|
||||||
expect($chat_content.text()).toBe("Your nickname doesn't conform to the room's policies");
|
expect(view.$el.find('.chat-body p').text()).toBe("Your nickname doesn't conform to the room's policies");
|
||||||
}, converse));
|
}, converse));
|
||||||
|
|
||||||
it("will show an error message if the user's nickname is already taken", $.proxy(function () {
|
it("will show an error message if the user's nickname is already taken", $.proxy(function () {
|
||||||
@ -200,9 +222,11 @@
|
|||||||
.c('error').attrs({by:'coven@chat.shakespeare.lit', type:'cancel'})
|
.c('error').attrs({by:'coven@chat.shakespeare.lit', type:'cancel'})
|
||||||
.c('conflict').attrs({xmlns:'urn:ietf:params:xml:ns:xmpp-stanzas'}).nodeTree;
|
.c('conflict').attrs({xmlns:'urn:ietf:params:xml:ns:xmpp-stanzas'}).nodeTree;
|
||||||
var view = this.chatboxesview.views['problematic@muc.localhost'];
|
var view = this.chatboxesview.views['problematic@muc.localhost'];
|
||||||
|
spyOn(converse.connection.muc, 'removeRoom');
|
||||||
|
spyOn(view, 'renderErrorMessage').andCallThrough();
|
||||||
view.onChatRoomPresence(presence, {'nick': 'dummy'});
|
view.onChatRoomPresence(presence, {'nick': 'dummy'});
|
||||||
var $chat_content = view.$el.find('.chat-content');
|
expect(converse.connection.muc.removeRoom).toHaveBeenCalled();
|
||||||
expect($chat_content.text()).toBe("Your nickname is already taken");
|
expect(view.$el.find('.chat-body p').text()).toBe("Your nickname is already taken");
|
||||||
}, converse));
|
}, converse));
|
||||||
|
|
||||||
it("will show an error message if the room doesn't yet exist", $.proxy(function () {
|
it("will show an error message if the room doesn't yet exist", $.proxy(function () {
|
||||||
@ -215,9 +239,11 @@
|
|||||||
.c('error').attrs({by:'coven@chat.shakespeare.lit', type:'cancel'})
|
.c('error').attrs({by:'coven@chat.shakespeare.lit', type:'cancel'})
|
||||||
.c('item-not-found').attrs({xmlns:'urn:ietf:params:xml:ns:xmpp-stanzas'}).nodeTree;
|
.c('item-not-found').attrs({xmlns:'urn:ietf:params:xml:ns:xmpp-stanzas'}).nodeTree;
|
||||||
var view = this.chatboxesview.views['problematic@muc.localhost'];
|
var view = this.chatboxesview.views['problematic@muc.localhost'];
|
||||||
|
spyOn(converse.connection.muc, 'removeRoom');
|
||||||
|
spyOn(view, 'renderErrorMessage').andCallThrough();
|
||||||
view.onChatRoomPresence(presence, {'nick': 'dummy'});
|
view.onChatRoomPresence(presence, {'nick': 'dummy'});
|
||||||
var $chat_content = view.$el.find('.chat-content');
|
expect(converse.connection.muc.removeRoom).toHaveBeenCalled();
|
||||||
expect($chat_content.text()).toBe("This room does not (yet) exist");
|
expect(view.$el.find('.chat-body p').text()).toBe("This room does not (yet) exist");
|
||||||
}, converse));
|
}, converse));
|
||||||
|
|
||||||
it("will show an error message if the room has reached it's maximum number of occupants", $.proxy(function () {
|
it("will show an error message if the room has reached it's maximum number of occupants", $.proxy(function () {
|
||||||
@ -230,9 +256,11 @@
|
|||||||
.c('error').attrs({by:'coven@chat.shakespeare.lit', type:'cancel'})
|
.c('error').attrs({by:'coven@chat.shakespeare.lit', type:'cancel'})
|
||||||
.c('service-unavailable').attrs({xmlns:'urn:ietf:params:xml:ns:xmpp-stanzas'}).nodeTree;
|
.c('service-unavailable').attrs({xmlns:'urn:ietf:params:xml:ns:xmpp-stanzas'}).nodeTree;
|
||||||
var view = this.chatboxesview.views['problematic@muc.localhost'];
|
var view = this.chatboxesview.views['problematic@muc.localhost'];
|
||||||
|
spyOn(converse.connection.muc, 'removeRoom');
|
||||||
|
spyOn(view, 'renderErrorMessage').andCallThrough();
|
||||||
view.onChatRoomPresence(presence, {'nick': 'dummy'});
|
view.onChatRoomPresence(presence, {'nick': 'dummy'});
|
||||||
var $chat_content = view.$el.find('.chat-content');
|
expect(converse.connection.muc.removeRoom).toHaveBeenCalled();
|
||||||
expect($chat_content.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));
|
}, converse));
|
||||||
|
Loading…
Reference in New Issue
Block a user