Add another test and another template. refs #117

This commit is contained in:
JC Brand 2014-12-01 20:31:01 +01:00
parent 0ae8008201
commit 03ec659b50
5 changed files with 97 additions and 32 deletions

View File

@ -4498,7 +4498,7 @@
connect_cb(req, callback, raw);
} else {
if (this.getRegistrationFields(req, callback, raw)) {
delete this._registering;
this._registering = false;
}
}
}, this);
@ -4529,8 +4529,9 @@
}
if (register.length === 0) {
conn._changeConnectStatus(
Strophe.Status.REGIFAIL,
'Sorry, the given provider does not support in band account registration. Please try with a different provider.');
Strophe.Status.REGIFAIL,
__('Sorry, the given provider does not support in band account registration. Please try with a different provider.')
);
return true;
}
// Send an IQ stanza to get all required data fields
@ -4588,9 +4589,10 @@
return;
}
$form.find('input[type=submit]').hide()
.after('<button class="cancel hor_centered">Cancel</button>')
.after('<span class="spinner login-submit"/>')
.after('<p class="info">Requesting a registration form from the XMPP server</p>');
.after(converse.templates.registration_request({
cancel: __('Cancel'),
info_message: __('Requesting a registration form from the XMPP server')
}));
$form.find('button.cancel').on('click', $.proxy(this.cancelRegistration, this));
this.reset({
domain: Strophe.getDomainFromJid(domain),
@ -4613,7 +4615,9 @@
if (_.contains([
Strophe.Status.DISCONNECTED,
Strophe.Status.CONNFAIL,
Strophe.Status.REGIFAIL
Strophe.Status.REGIFAIL,
Strophe.Status.NOTACCEPTABLE,
Strophe.Status.CONFLICT
], status)) {
converse.log('Problem during registration: Strophe.Status is: '+status);
@ -4622,16 +4626,10 @@
this.giveFeedback(error, 'error');
} else {
this.giveFeedback(__(
'Something went wrong establishing a connection with "%1$s". Are you sure it exists?',
'Something went wrong while establishing a connection with "%1$s". Are you sure it exists?',
this.domain
), 'error');
}
} else if (status == Strophe.Status.CONFLICT) {
// TODO
converse.log('CONFLICT');
} else if (status == Strophe.Status.NOTACCEPTABLE) {
// TODO
converse.log('NOTACCEPTABLE');
} else if (status == Strophe.Status.REGISTERED) {
converse.log("Registered successfully.");
converse.connection.reset();
@ -4694,9 +4692,9 @@
}, this));
}
if (this.fields) {
$form.append('<input type="submit" class="submit" value="'+__('Register')+'"/>');
$form.append('<input type="submit" class="save-submit" value="'+__('Register')+'"/>');
$form.on('submit', $.proxy(this.submitRegistrationForm, this));
$form.append('<input type="button" class="submit" value="'+__('Cancel')+'"/>');
$form.append('<input type="button" class="cancel-submit" value="'+__('Cancel')+'"/>');
$form.find('input[type=button]').on('click', $.proxy(this.cancelRegistration, this));
} else {
$form.append('<input type="button" class="submit" value="'+__('Return')+'"/>');

View File

@ -110,6 +110,7 @@ require.config({
"register_panel": "src/templates/register_panel",
"register_tab": "src/templates/register_tab",
"registration_form": "src/templates/registration_form",
"registration_request": "src/templates/registration_request",
"requesting_contact": "src/templates/requesting_contact",
"requesting_contacts": "src/templates/requesting_contacts",
"room_description": "src/templates/room_description",

View File

@ -11,12 +11,27 @@
describe("The Registration Panel", $.proxy(function (mock, test_utils) {
beforeEach(function () {
test_utils.closeControlBox();
connection = mock.mock_connection;
connection.connected = false;
converse._tearDown();
converse.initialize({
bosh_service_url: 'localhost',
allow_registration: true,
auto_subscribe: false,
animate: false,
connection: connection,
no_trimming: true,
debug: true
});
test_utils.openControlBox();
});
afterEach(function () {
afterEach($.proxy(function () {
this.connection.connected = false;
test_utils.closeControlBox();
});
}, converse));
it("is not available unless allow_registration=true", $.proxy(function () {
test_utils.closeControlBox();
@ -61,6 +76,9 @@
var $panels = cbview.$('.controlbox-panes');
var $login = $panels.children().first();
var $registration = $panels.children().last();
expect($tabs.find('li').first().text()).toBe('Sign in');
expect($tabs.find('li').last().text()).toBe('Register');
spyOn(cbview, 'switchTab').andCallThrough();
cbview.delegateEvents(); // We need to rebind all events otherwise our spy won't be called
$tabs.find('li').last().find('a').click(); // Click the Register tab
@ -94,7 +112,50 @@
}, converse));
it("will render a registration form as received from the XMPP provider", $.proxy(function () {
// TODO
var cbview = this.chatboxviews.get('controlbox');
cbview.$('#controlbox-tabs').find('li').last().find('a').click(); // Click the Register tab
var registerview = this.chatboxviews.get('controlbox').registerpanel;
spyOn(registerview, 'onProviderChosen').andCallThrough();
spyOn(registerview, 'getRegistrationFields').andCallThrough();
spyOn(registerview, 'onRegistrationFields').andCallThrough();
spyOn(registerview, 'renderRegistrationForm').andCallThrough();
registerview.delegateEvents(); // We need to rebind all events otherwise our spy won't be called
spyOn(this.connection, 'connect').andCallThrough();
expect(registerview._registering).toBeFalsy();
expect(this.connection.connected).toBeFalsy();
registerview.$('input[name=domain]').val('conversejs.org');
registerview.$('input[type=submit]').click();
expect(registerview.onProviderChosen).toHaveBeenCalled();
expect(registerview._registering).toBeTruthy();
expect(this.connection.connect).toHaveBeenCalled();
var stanza = new Strophe.Builder("stream:features", {
'xmlns:stream': "http://etherx.jabber.org/streams",
'xmlns': "jabber:client"
})
.c('register', {xmlns: "http://jabber.org/features/iq-register"}).up()
.c('mechanisms', {xmlns: "urn:ietf:params:xml:ns:xmpp-sasl"});
this.connection._connect_cb(test_utils.createRequest(stanza));
expect(registerview.getRegistrationFields).toHaveBeenCalled();
expect(this.connection.connected).toBeTruthy();
stanza = $iq({
'type': 'result',
'id': 'reg1'
}).c('query', {'xmlns': 'jabber:iq:register'})
.c('instructions')
.t('Please choose a username, password and provide your email address').up()
.c('username').up()
.c('password').up()
.c('email');
this.connection._dataRecv(test_utils.createRequest(stanza));
expect(registerview.onRegistrationFields).toHaveBeenCalled();
expect(registerview.renderRegistrationForm).toHaveBeenCalled();
expect(registerview.$('input').length).toBe(5);
expect(registerview.$('input[type=submit]').length).toBe(1);
expect(registerview.$('input[type=button]').length).toBe(1);
}, converse));
}, converse, mock, test_utils));

View File

@ -35,6 +35,7 @@ define("converse-templates", [
"tpl!register_panel",
"tpl!register_tab",
"tpl!registration_form",
"tpl!registration_request",
"tpl!requesting_contact",
"tpl!requesting_contacts",
"tpl!room_description",
@ -86,18 +87,19 @@ define("converse-templates", [
register_panel: arguments[33],
register_tab: arguments[34],
registration_form: arguments[35],
requesting_contact: arguments[36],
requesting_contacts: arguments[37],
room_description: arguments[38],
room_item: arguments[39],
room_panel: arguments[40],
roster: arguments[41],
roster_item: arguments[42],
search_contact: arguments[43],
select_option: arguments[44],
status_option: arguments[45],
toggle_chats: arguments[46],
toolbar: arguments[47],
trimmed_chat: arguments[48]
registration_request: arguments[36],
requesting_contact: arguments[37],
requesting_contacts: arguments[38],
room_description: arguments[39],
room_item: arguments[40],
room_panel: arguments[41],
roster: arguments[42],
roster_item: arguments[43],
search_contact: arguments[44],
select_option: arguments[45],
status_option: arguments[46],
toggle_chats: arguments[47],
toolbar: arguments[48],
trimmed_chat: arguments[49]
};
});

View File

@ -0,0 +1,3 @@
<span class="spinner login-submit"/>
<p class="info">{{info_message}}</p>
<button class="cancel hor_centered">{{cancel}}</button>