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();
|
test_utils.openControlBox();
|
||||||
var cbview = _converse.chatboxviews.get('controlbox');
|
var cbview = _converse.chatboxviews.get('controlbox');
|
||||||
expect(cbview.$('#controlbox-tabs li').length).toBe(1);
|
expect(cbview.$('a.register-account').length).toBe(0);
|
||||||
expect(cbview.$('#controlbox-tabs li').text().trim()).toBe("Sign in");
|
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
}));
|
}));
|
||||||
@ -41,20 +40,19 @@
|
|||||||
|
|
||||||
var cbview = _converse.chatboxviews.get('controlbox');
|
var cbview = _converse.chatboxviews.get('controlbox');
|
||||||
test_utils.openControlBox();
|
test_utils.openControlBox();
|
||||||
var $tabs = cbview.$('#controlbox-tabs');
|
|
||||||
var $panels = cbview.$('.controlbox-panes');
|
var $panels = cbview.$('.controlbox-panes');
|
||||||
var $login = $panels.children().first();
|
var $login = $panels.children().first();
|
||||||
var $registration = $panels.children().last();
|
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();
|
var $register_link = cbview.$('a.register-account');
|
||||||
cbview.delegateEvents(); // We need to rebind all events otherwise our spy won't be called
|
expect($register_link.text()).toBe("Register an account");
|
||||||
$tabs.find('li').last().find('a').click(); // Click the Register tab
|
$register_link.click();
|
||||||
expect($login.is(':visible')).toBe(false);
|
test_utils.waitUntil(function () {
|
||||||
expect($registration.is(':visible')).toBe(true);
|
return $registration.is(':visible');
|
||||||
expect(cbview.switchTab).toHaveBeenCalled();
|
}, 300).then(function () {
|
||||||
done();
|
expect($login.is(':visible')).toBe(false);
|
||||||
|
done();
|
||||||
|
});
|
||||||
});
|
});
|
||||||
}));
|
}));
|
||||||
|
|
||||||
|
@ -188,6 +188,7 @@
|
|||||||
// Looks like _converse.initialized was called again without logging
|
// Looks like _converse.initialized was called again without logging
|
||||||
// out or disconnecting in the previous session.
|
// out or disconnecting in the previous session.
|
||||||
// This happens in tests. We therefore first clean up.
|
// This happens in tests. We therefore first clean up.
|
||||||
|
Backbone.history.stop();
|
||||||
delete _converse.controlboxtoggle;
|
delete _converse.controlboxtoggle;
|
||||||
_converse.connection.reset();
|
_converse.connection.reset();
|
||||||
_converse.off();
|
_converse.off();
|
||||||
|
@ -77,13 +77,29 @@
|
|||||||
|
|
||||||
ControlBoxView: {
|
ControlBoxView: {
|
||||||
|
|
||||||
|
events: {
|
||||||
|
'click .toggle-register-login': 'switchToRegisterForm',
|
||||||
|
},
|
||||||
|
|
||||||
initialize () {
|
initialize () {
|
||||||
this.__super__.initialize.apply(this, arguments);
|
this.__super__.initialize.apply(this, arguments);
|
||||||
this.model.on('change:active-form', this.showLoginOrRegisterForm.bind(this))
|
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__;
|
const { _converse } = this.__super__;
|
||||||
|
if (_.isNil(this.registerpanel)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
if (this.model.get('active-form') == "register") {
|
if (this.model.get('active-form') == "register") {
|
||||||
this.loginpanel.el.classList.add('hidden');
|
this.loginpanel.el.classList.add('hidden');
|
||||||
this.registerpanel.el.classList.remove('hidden');
|
this.registerpanel.el.classList.remove('hidden');
|
||||||
@ -145,11 +161,7 @@
|
|||||||
setActiveForm (value) {
|
setActiveForm (value) {
|
||||||
_converse.api.waitUntil('controlboxInitialized').then(() => {
|
_converse.api.waitUntil('controlboxInitialized').then(() => {
|
||||||
const controlbox = _converse.chatboxes.get('controlbox')
|
const controlbox = _converse.chatboxes.get('controlbox')
|
||||||
if (controlbox.get('connected')) {
|
controlbox.set({'active-form': value});
|
||||||
controlbox.save({'active-form': value});
|
|
||||||
} else {
|
|
||||||
controlbox.set({'active-form': value});
|
|
||||||
}
|
|
||||||
}).catch(_.partial(_converse.log, _, Strophe.LogLevel.FATAL));
|
}).catch(_.partial(_converse.log, _, Strophe.LogLevel.FATAL));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@ -162,7 +174,7 @@
|
|||||||
className: 'controlbox-pane fade-in',
|
className: 'controlbox-pane fade-in',
|
||||||
events: {
|
events: {
|
||||||
'submit form#converse-register': 'onProviderChosen',
|
'submit form#converse-register': 'onProviderChosen',
|
||||||
'click .button-cancel': 'cancelRegistration'
|
'click .button-cancel': 'cancelRegistration',
|
||||||
},
|
},
|
||||||
|
|
||||||
initialize (cfg) {
|
initialize (cfg) {
|
||||||
|
Loading…
Reference in New Issue
Block a user