Make sure password is last

This commit is contained in:
Alex Notov
2012-12-26 15:59:52 -08:00
committed by Avital Oliver
parent 6356b73ef8
commit 09d5c94522
2 changed files with 33 additions and 11 deletions

View File

@@ -1,11 +1,23 @@
Tinytest.add(
'accounts-ui - getLoginServices retuns an array of service hashes',
function (test) {
// setup
var services;
Accounts._loginButtons.loginServices.push('password');
services = Accounts._loginButtons.getLoginServices();
(function(environment) {
// setup
Accounts._loginButtons.loginServices.push('password');
environment.meteorServices = function() {
return Accounts._loginButtons.getLoginServices();
};
Tinytest.add(
'accounts-ui - getLoginServices retuns an array of service hashes',
function (test) {
test.equal(_.first(environment.meteorServices()), {name: "password"});
}
);
Tinytest.add(
'accounts-ui - getLoginServices should always return password last',
function (test) {
Accounts._loginButtons.loginServices.push('some_other_service');
test.equal(_.last(environment.meteorServices()), {name: "password"});
}
);
})(Tinytest);
test.equal(_.first(services), {name: "password"});
}
);

View File

@@ -119,7 +119,17 @@
Accounts._loginButtons.getLoginServices = function () {
var self = this,
services = self.loginServices;
services = self.loginServices, // memoize services array
passwordIndex = services.indexOf("password"), // memoize password idx.
lastServiceAt = services.length - 1; // memoize last service idx.
// make sure to put password last, since this is how it is styled
// if we had found password, swap w last service
if (passwordIndex !== -1) {
services[lastServiceAt] = services[passwordIndex];
services[passwordIndex] = services[lastServiceAt];
}
return _.map(services, function(service) {
return {name: service};
});