Fix failing tests.
Somehow the tests are flaky when the router sets a URL fragment for login or registration, so I've now added an event handler which does the work without setting the URL fragment. The router is still there so that one can manually link to a URL that has the registration form open. (Issue #828)
This commit is contained in:
parent
2bb6565168
commit
7cfe81ea1f
@ -21,8 +21,7 @@
|
||||
|
||||
test_utils.openControlBox();
|
||||
var cbview = _converse.chatboxviews.get('controlbox');
|
||||
expect(cbview.$('#controlbox-tabs li').length).toBe(1);
|
||||
expect(cbview.$('#controlbox-tabs li').text().trim()).toBe("Sign in");
|
||||
expect(cbview.$('a.register-account').length).toBe(0);
|
||||
done();
|
||||
});
|
||||
}));
|
||||
@ -41,21 +40,20 @@
|
||||
|
||||
var cbview = _converse.chatboxviews.get('controlbox');
|
||||
test_utils.openControlBox();
|
||||
var $tabs = cbview.$('#controlbox-tabs');
|
||||
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').and.callThrough();
|
||||
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
|
||||
var $register_link = cbview.$('a.register-account');
|
||||
expect($register_link.text()).toBe("Register an account");
|
||||
$register_link.click();
|
||||
test_utils.waitUntil(function () {
|
||||
return $registration.is(':visible');
|
||||
}, 300).then(function () {
|
||||
expect($login.is(':visible')).toBe(false);
|
||||
expect($registration.is(':visible')).toBe(true);
|
||||
expect(cbview.switchTab).toHaveBeenCalled();
|
||||
done();
|
||||
});
|
||||
});
|
||||
}));
|
||||
|
||||
it("allows the user to choose an XMPP provider's domain",
|
||||
|
@ -188,6 +188,7 @@
|
||||
// Looks like _converse.initialized was called again without logging
|
||||
// out or disconnecting in the previous session.
|
||||
// This happens in tests. We therefore first clean up.
|
||||
Backbone.history.stop();
|
||||
delete _converse.controlboxtoggle;
|
||||
_converse.connection.reset();
|
||||
_converse.off();
|
||||
|
@ -77,13 +77,29 @@
|
||||
|
||||
ControlBoxView: {
|
||||
|
||||
events: {
|
||||
'click .toggle-register-login': 'switchToRegisterForm',
|
||||
},
|
||||
|
||||
initialize () {
|
||||
this.__super__.initialize.apply(this, arguments);
|
||||
this.model.on('change:active-form', this.showLoginOrRegisterForm.bind(this))
|
||||
},
|
||||
|
||||
showLoginOrRegisterForm (ev) {
|
||||
switchToRegisterForm (ev) {
|
||||
ev.preventDefault();
|
||||
if (this.model.get('active-form') == "register") {
|
||||
this.model.set('active-form', 'login');
|
||||
} else {
|
||||
this.model.set('active-form', 'register');
|
||||
}
|
||||
},
|
||||
|
||||
showLoginOrRegisterForm () {
|
||||
const { _converse } = this.__super__;
|
||||
if (_.isNil(this.registerpanel)) {
|
||||
return;
|
||||
}
|
||||
if (this.model.get('active-form') == "register") {
|
||||
this.loginpanel.el.classList.add('hidden');
|
||||
this.registerpanel.el.classList.remove('hidden');
|
||||
@ -145,11 +161,7 @@
|
||||
setActiveForm (value) {
|
||||
_converse.api.waitUntil('controlboxInitialized').then(() => {
|
||||
const controlbox = _converse.chatboxes.get('controlbox')
|
||||
if (controlbox.get('connected')) {
|
||||
controlbox.save({'active-form': value});
|
||||
} else {
|
||||
controlbox.set({'active-form': value});
|
||||
}
|
||||
}).catch(_.partial(_converse.log, _, Strophe.LogLevel.FATAL));
|
||||
}
|
||||
});
|
||||
@ -162,7 +174,7 @@
|
||||
className: 'controlbox-pane fade-in',
|
||||
events: {
|
||||
'submit form#converse-register': 'onProviderChosen',
|
||||
'click .button-cancel': 'cancelRegistration'
|
||||
'click .button-cancel': 'cancelRegistration',
|
||||
},
|
||||
|
||||
initialize (cfg) {
|
||||
|
Loading…
Reference in New Issue
Block a user