Skip to content

Instantly share code, notes, and snippets.

@zaus
Last active August 6, 2016 18:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save zaus/20aabf6a8f8da4872370 to your computer and use it in GitHub Desktop.
Save zaus/20aabf6a8f8da4872370 to your computer and use it in GitHub Desktop.
Chrome DevTools Snippets (because it doesn't save when you clear your user data...)
(function($) {
// what gets faked
var fields = {
names: [
'billing.firstName',
'billing.lastName',
'billing.companyName'
],
emails: [
'billing.email'
],
phones: [
'billing.phone'
],
addresses: [
{
streetAddress: 'billing.address1',
secondaryAddress: 'billing.address2',
city: 'billing.city',
state: 'billing.state',
//country: 'billing.country',
zipCode: 'billing.zipCode'
}
]
};
// how it gets selected
var grab = function(iden) {
return $('[data-ng-model="' + iden + '"]');
}
// how it gets updated
var set = function(iden, valfn) {
grab(iden).each(function(i, o) {
var val = valfn();
console.log('setting ', i, iden, 'ex:' + val);
$(o).val(val);
});
}
var setop = function(valfn) {
return function(i,field) {
set(field, valfn);
}
}
// loop 'em
function execute(script, textStatus) {
console.log("Executing form faker", textStatus, script);
$.each(fields.names, setop(faker.name.firstName));
$.each(fields.emails, setop(faker.internet.email));
$.each(fields.phones, setop(faker.phone.phoneNumberFormat));
$.each(fields.addresses, function(i, addr) {
$.each(addr, function(type, field) {
setop(faker.address[type])(0, field);
});
});
}
// load faker and run
// $.getScript('//cdnjs.cloudflare.com/ajax/libs/faker/0.7.2/Minfaker.js');
if(!window.faker) $.getScript('http://marak.com/faker.js/js/faker.js').done(execute);
else execute();
})(jQuery);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment