Commit c25f33b1 authored by JC Brand's avatar JC Brand

Add proper separation between controlbox tests

parent 5034ae33
...@@ -15,7 +15,7 @@ ...@@ -15,7 +15,7 @@
utils.removeControlBox(); utils.removeControlBox();
converse.roster.browserStorage._clear(); converse.roster.browserStorage._clear();
utils.initConverse(); utils.initConverse();
utils.createCurrentContacts(); utils.createContacts();
utils.openControlBox(); utils.openControlBox();
utils.openContactsPanel(); utils.openContactsPanel();
}); });
...@@ -694,7 +694,7 @@ ...@@ -694,7 +694,7 @@
utils.removeControlBox(); utils.removeControlBox();
converse.roster.browserStorage._clear(); converse.roster.browserStorage._clear();
utils.initConverse(); utils.initConverse();
utils.createCurrentContacts(); utils.createContacts();
utils.openControlBox(); utils.openControlBox();
utils.openContactsPanel(); utils.openContactsPanel();
}); });
......
...@@ -106,27 +106,30 @@ ...@@ -106,27 +106,30 @@
}, converse, mock, utils)); }, converse, mock, utils));
describe("The Contacts Roster", $.proxy(function (mock, utils) { describe("The Contacts Roster", $.proxy(function (mock, utils) {
// FIXME: These tests are dependent on being run in order and cannot be
// run independently
describe("Pending Contacts", $.proxy(function () { describe("Pending Contacts", $.proxy(function () {
beforeEach(function () { beforeEach($.proxy(function () {
runs(function () { runs(function () {
utils.openControlBox(); converse.rosterview.model.reset();
utils.createContacts('pending').openControlBox();
}); });
waits(50); waits(50);
runs(function () { runs(function () {
utils.openContactsPanel(); utils.openContactsPanel();
}); });
waits(50); }, converse));
runs(function () {});
});
it("do not have a heading if there aren't any", $.proxy(function () { it("do not have a heading if there aren't any", $.proxy(function () {
converse.rosterview.model.reset();
expect(this.rosterview.$el.find('dt#pending-xmpp-contacts').css('display')).toEqual('none'); expect(this.rosterview.$el.find('dt#pending-xmpp-contacts').css('display')).toEqual('none');
}, converse)); }, converse));
it("will have their own heading once they have been added", $.proxy(function () {
expect(this.rosterview.$el.find('dt#pending-xmpp-contacts').css('display')).toEqual('block');
}, converse));
it("can be added to the roster", $.proxy(function () { it("can be added to the roster", $.proxy(function () {
converse.rosterview.model.reset(); // We want to manually create users so that we can spy
spyOn(converse, 'emit'); spyOn(converse, 'emit');
spyOn(this.rosterview, 'render').andCallThrough(); spyOn(this.rosterview, 'render').andCallThrough();
runs($.proxy(function () { runs($.proxy(function () {
...@@ -155,26 +158,28 @@ ...@@ -155,26 +158,28 @@
spyOn(this.connection.roster, 'unauthorize'); spyOn(this.connection.roster, 'unauthorize');
spyOn(this.rosterview.model, 'remove').andCallThrough(); spyOn(this.rosterview.model, 'remove').andCallThrough();
runs($.proxy(function () { view.$el.find('.remove-xmpp-contact').click();
view.$el.find('.remove-xmpp-contact').click(); expect(window.confirm).toHaveBeenCalled();
}, converse)); expect(this.connection.roster.remove).toHaveBeenCalled();
waits(250); expect(this.connection.roster.unauthorize).toHaveBeenCalled();
runs($.proxy(function () { expect(this.rosterview.model.remove).toHaveBeenCalled();
expect(window.confirm).toHaveBeenCalled(); // The element must now be detached from the DOM.
expect(this.connection.roster.remove).toHaveBeenCalled(); expect(view.$el.closest('html').length).toBeFalsy();
expect(this.connection.roster.unauthorize).toHaveBeenCalled(); expect(converse.emit).toHaveBeenCalledWith('onRosterViewUpdated');
expect(this.rosterview.model.remove).toHaveBeenCalled();
// The element must now be detached from the DOM.
expect(view.$el.closest('html').length).toBeFalsy();
expect(converse.emit).toHaveBeenCalledWith('onRosterViewUpdated');
}, converse));
}, converse)); }, converse));
it("will lose their own heading once the last one has been removed", $.proxy(function () { it("will lose their own heading once the last one has been removed", $.proxy(function () {
var view;
spyOn(window, 'confirm').andReturn(true);
for (i=0; i<mock.pend_names.length; i++) {
view = this.rosterview.get(mock.pend_names[i].replace(/ /g,'.').toLowerCase() + '@localhost');
view.$el.find('.remove-xmpp-contact').click();
}
expect(this.rosterview.$el.find('dt#pending-xmpp-contacts').is(':visible')).toBeFalsy(); expect(this.rosterview.$el.find('dt#pending-xmpp-contacts').is(':visible')).toBeFalsy();
}, converse)); }, converse));
it("can be added to the roster and they will be sorted alphabetically", $.proxy(function () { it("can be added to the roster and they will be sorted alphabetically", $.proxy(function () {
converse.rosterview.model.reset(); // We want to manually create users so that we can spy
var i, t, is_last; var i, t, is_last;
spyOn(converse, 'emit'); spyOn(converse, 'emit');
spyOn(this.rosterview, 'render').andCallThrough(); spyOn(this.rosterview, 'render').andCallThrough();
...@@ -195,21 +200,13 @@ ...@@ -195,21 +200,13 @@
} }
}, converse)); }, converse));
it("will have their own heading once they have been added", $.proxy(function () {
expect(this.rosterview.$el.find('dt#pending-xmpp-contacts').css('display')).toEqual('block');
}, converse));
}, converse)); }, converse));
describe("Existing Contacts", $.proxy(function () { describe("Existing Contacts", $.proxy(function () {
beforeEach($.proxy(function () { beforeEach($.proxy(function () {
runs(function () { runs(function () {
converse.rosterview.model.reset(); converse.rosterview.model.reset();
utils.createCurrentContacts(); utils.createContacts().openControlBox();
});
waits(50);
runs(function () {
utils.openControlBox();
}); });
waits(50); waits(50);
runs(function () { runs(function () {
...@@ -393,13 +390,26 @@ ...@@ -393,13 +390,26 @@
}, converse)); }, converse));
describe("Requesting Contacts", $.proxy(function () { describe("Requesting Contacts", $.proxy(function () {
// by default the dts are hidden from css class and only later they will be hidden beforeEach($.proxy(function () {
// by jQuery therefore for the first check we will see if visible instead of none runs(function () {
converse.rosterview.model.reset();
utils.createContacts('requesting').openControlBox();
});
waits(50);
runs(function () {
utils.openContactsPanel();
});
}, converse));
it("do not have a heading if there aren't any", $.proxy(function () { it("do not have a heading if there aren't any", $.proxy(function () {
// by default the dts are hidden from css class and only later they will be hidden
// by jQuery therefore for the first check we will see if visible instead of none
converse.rosterview.model.reset();
expect(this.rosterview.$el.find('dt#xmpp-contact-requests').is(':visible')).toEqual(false); expect(this.rosterview.$el.find('dt#xmpp-contact-requests').is(':visible')).toEqual(false);
}, converse)); }, converse));
it("can be added to the roster and they will be sorted alphabetically", $.proxy(function () { it("can be added to the roster and they will be sorted alphabetically", $.proxy(function () {
converse.rosterview.model.reset(); // We want to manually create users so that we can spy
var i, t; var i, t;
spyOn(converse, 'emit'); spyOn(converse, 'emit');
spyOn(this.rosterview, 'render').andCallThrough(); spyOn(this.rosterview, 'render').andCallThrough();
...@@ -458,11 +468,24 @@ ...@@ -458,11 +468,24 @@
expect(this.connection.roster.unauthorize).toHaveBeenCalled(); expect(this.connection.roster.unauthorize).toHaveBeenCalled();
expect(converse.emit).toHaveBeenCalledWith('onRosterViewUpdated'); expect(converse.emit).toHaveBeenCalledWith('onRosterViewUpdated');
// There should now be one less contact // There should now be one less contact
expect(this.roster.length).toEqual(mock.num_contacts-1); expect(this.roster.length).toEqual(mock.req_names.length-1);
}, converse)); }, converse));
}, converse)); }, converse));
describe("All Contacts", $.proxy(function () { describe("All Contacts", $.proxy(function () {
beforeEach($.proxy(function () {
runs(function () {
utils.clearBrowserStorage();
converse.rosterview.model.reset();
converse.rosterview.model.browserStorage._clear();
utils.createContacts('all').openControlBox();
});
waits(50);
runs(function () {
utils.openContactsPanel();
});
}, converse));
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, old_roster; var new_attrs, old_attrs, attrs, old_roster;
var num_contacts = this.roster.length; var num_contacts = this.roster.length;
......
...@@ -15,7 +15,7 @@ ...@@ -15,7 +15,7 @@
utils.removeControlBox(); utils.removeControlBox();
converse.roster.browserStorage._clear(); converse.roster.browserStorage._clear();
utils.initConverse(); utils.initConverse();
utils.createCurrentContacts(); utils.createContacts();
utils.openControlBox(); utils.openControlBox();
utils.openContactsPanel(); utils.openContactsPanel();
converse.minimized_chats.toggleview.model.browserStorage._clear(); converse.minimized_chats.toggleview.model.browserStorage._clear();
......
...@@ -92,6 +92,7 @@ ...@@ -92,6 +92,7 @@
utils.clearBrowserStorage = function () { utils.clearBrowserStorage = function () {
window.localStorage.clear(); window.localStorage.clear();
window.sessionStorage.clear(); window.sessionStorage.clear();
return this;
}; };
utils.clearChatBoxMessages = function (jid) { utils.clearChatBoxMessages = function (jid) {
...@@ -101,16 +102,37 @@ ...@@ -101,16 +102,37 @@
view.model.messages.browserStorage._clear(); view.model.messages.browserStorage._clear();
}; };
utils.createCurrentContacts = function () { utils.createContacts = function (type) {
// 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.
for (i=0; i<mock.cur_names.length; i++) { var names;
if (type === 'requesting') {
names = mock.req_names;
subscription = 'none';
requesting = true;
ask = null;
} else if (type === 'pending') {
names = mock.pend_names;
subscription = 'none';
requesting = false;
ask = 'subscribe';
} else if (type === 'all') {
this.createContacts().createContacts('request').createContacts('pending');
return this;
} else {
names = mock.cur_names;
subscription = 'both';
requesting = false;
ask = null;
}
for (i=0; i<names.length; i++) {
converse.roster.create({ converse.roster.create({
jid: mock.cur_names[i].replace(/ /g,'.').toLowerCase() + '@localhost', ask: ask,
subscription: 'both', fullname: names[i],
ask: null, is_last: i===(names.length-1),
fullname: mock.cur_names[i], jid: names[i].replace(/ /g,'.').toLowerCase() + '@localhost',
is_last: i===(mock.cur_names.length-1) requesting: requesting,
subscription: subscription
}); });
} }
return this; return this;
......
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