Commit c25f33b1 authored by JC Brand's avatar JC Brand

Add proper separation between controlbox tests

parent 5034ae33
......@@ -15,7 +15,7 @@
utils.removeControlBox();
converse.roster.browserStorage._clear();
utils.initConverse();
utils.createCurrentContacts();
utils.createContacts();
utils.openControlBox();
utils.openContactsPanel();
});
......@@ -694,7 +694,7 @@
utils.removeControlBox();
converse.roster.browserStorage._clear();
utils.initConverse();
utils.createCurrentContacts();
utils.createContacts();
utils.openControlBox();
utils.openContactsPanel();
});
......
......@@ -106,27 +106,30 @@
}, converse, 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 () {
beforeEach(function () {
beforeEach($.proxy(function () {
runs(function () {
utils.openControlBox();
converse.rosterview.model.reset();
utils.createContacts('pending').openControlBox();
});
waits(50);
runs(function () {
utils.openContactsPanel();
});
waits(50);
runs(function () {});
});
}, converse));
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');
}, 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 () {
converse.rosterview.model.reset(); // We want to manually create users so that we can spy
spyOn(converse, 'emit');
spyOn(this.rosterview, 'render').andCallThrough();
runs($.proxy(function () {
......@@ -155,11 +158,7 @@
spyOn(this.connection.roster, 'unauthorize');
spyOn(this.rosterview.model, 'remove').andCallThrough();
runs($.proxy(function () {
view.$el.find('.remove-xmpp-contact').click();
}, converse));
waits(250);
runs($.proxy(function () {
expect(window.confirm).toHaveBeenCalled();
expect(this.connection.roster.remove).toHaveBeenCalled();
expect(this.connection.roster.unauthorize).toHaveBeenCalled();
......@@ -168,13 +167,19 @@
expect(view.$el.closest('html').length).toBeFalsy();
expect(converse.emit).toHaveBeenCalledWith('onRosterViewUpdated');
}, converse));
}, converse));
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();
}, converse));
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;
spyOn(converse, 'emit');
spyOn(this.rosterview, 'render').andCallThrough();
......@@ -195,21 +200,13 @@
}
}, 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));
describe("Existing Contacts", $.proxy(function () {
beforeEach($.proxy(function () {
runs(function () {
converse.rosterview.model.reset();
utils.createCurrentContacts();
});
waits(50);
runs(function () {
utils.openControlBox();
utils.createContacts().openControlBox();
});
waits(50);
runs(function () {
......@@ -393,13 +390,26 @@
}, converse));
describe("Requesting Contacts", $.proxy(function () {
beforeEach($.proxy(function () {
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 () {
// 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
it("do not have a heading if there aren't any", $.proxy(function () {
converse.rosterview.model.reset();
expect(this.rosterview.$el.find('dt#xmpp-contact-requests').is(':visible')).toEqual(false);
}, converse));
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;
spyOn(converse, 'emit');
spyOn(this.rosterview, 'render').andCallThrough();
......@@ -458,11 +468,24 @@
expect(this.connection.roster.unauthorize).toHaveBeenCalled();
expect(converse.emit).toHaveBeenCalledWith('onRosterViewUpdated');
// 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));
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 () {
var new_attrs, old_attrs, attrs, old_roster;
var num_contacts = this.roster.length;
......
......@@ -15,7 +15,7 @@
utils.removeControlBox();
converse.roster.browserStorage._clear();
utils.initConverse();
utils.createCurrentContacts();
utils.createContacts();
utils.openControlBox();
utils.openContactsPanel();
converse.minimized_chats.toggleview.model.browserStorage._clear();
......
......@@ -92,6 +92,7 @@
utils.clearBrowserStorage = function () {
window.localStorage.clear();
window.sessionStorage.clear();
return this;
};
utils.clearChatBoxMessages = function (jid) {
......@@ -101,16 +102,37 @@
view.model.messages.browserStorage._clear();
};
utils.createCurrentContacts = function () {
utils.createContacts = function (type) {
// Create current (as opposed to requesting or pending) contacts
// 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({
jid: mock.cur_names[i].replace(/ /g,'.').toLowerCase() + '@localhost',
subscription: 'both',
ask: null,
fullname: mock.cur_names[i],
is_last: i===(mock.cur_names.length-1)
ask: ask,
fullname: names[i],
is_last: i===(names.length-1),
jid: names[i].replace(/ /g,'.').toLowerCase() + '@localhost',
requesting: requesting,
subscription: subscription
});
}
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