diff --git a/spec/register.js b/spec/register.js index 241a10621..2f8820a15 100644 --- a/spec/register.js +++ b/spec/register.js @@ -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,20 +40,19 @@ 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 - expect($login.is(':visible')).toBe(false); - expect($registration.is(':visible')).toBe(true); - expect(cbview.switchTab).toHaveBeenCalled(); - done(); + 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); + done(); + }); }); })); diff --git a/src/converse-core.js b/src/converse-core.js index 3130940f7..fa96478dd 100755 --- a/src/converse-core.js +++ b/src/converse-core.js @@ -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(); diff --git a/src/converse-register.js b/src/converse-register.js index fbd86817e..e73a5e7c6 100644 --- a/src/converse-register.js +++ b/src/converse-register.js @@ -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}); - } + 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) {