Merge pull request #6848 from ErisDS/twitter-facebook

Improvements to twitter & facebook handling
This commit is contained in:
Hannah Wolfe 2016-05-17 20:59:15 +01:00
commit 5948277a95
23 changed files with 634 additions and 154 deletions

View File

@ -125,48 +125,65 @@ export default Controller.extend(SettingsSaveMixin, {
let oldUrl = this.get('model.facebook'); let oldUrl = this.get('model.facebook');
let errMessage = ''; let errMessage = '';
if (!newUrl) { if (newUrl === '') {
// Clear out the Facebook url // Clear out the Facebook url
this.set('model.facebook', ''); this.set('model.facebook', '');
this.get('model.errors').remove('facebook'); this.get('model.errors').remove('facebook');
return; return;
} }
// _scratchFacebook will be null unless the user has input something
if (!newUrl) {
newUrl = oldUrl;
}
// If new url didn't change, exit // If new url didn't change, exit
if (newUrl === oldUrl) { if (newUrl === oldUrl) {
this.get('model.errors').remove('facebook');
return; return;
} }
if (!newUrl.match(/(^https:\/\/www\.facebook\.com\/)(\S+)/g)) { if (newUrl.match(/(?:facebook\.com\/)(\S+)/) || newUrl.match(/([a-z\d\.]+)/i)) {
if (newUrl.match(/(?:facebook\.com\/)(\S+)/) || (!validator.isURL(newUrl) && newUrl.match(/([a-zA-Z0-9\.]+)/))) { let username = [];
let [ , username] = newUrl.match(/(?:facebook\.com\/)(\S+)/) || newUrl.match(/([a-zA-Z0-9\.]+)/);
newUrl = `https://www.facebook.com/${username}`;
this.set('model.facebook', newUrl); if (newUrl.match(/(?:facebook\.com\/)(\S+)/)) {
[ , username ] = newUrl.match(/(?:facebook\.com\/)(\S+)/);
this.get('model.errors').remove('facebook');
this.get('model.hasValidated').pushObject('facebook');
// User input is validated
return this.save().then(() => {
this.set('model.facebook', '');
run.schedule('afterRender', this, function () {
this.set('model.facebook', newUrl);
});
});
} else if (validator.isURL(newUrl)) {
errMessage = 'The URL must be in a format like ' +
'https://www.facebook.com/yourPage';
this.get('model.errors').add('facebook', errMessage);
this.get('model.hasValidated').pushObject('facebook');
return;
} else { } else {
errMessage = 'The URL must be in a format like ' + [ , username ] = newUrl.match(/(?:https\:\/\/|http\:\/\/)?(?:www\.)?(?:\w+\.\w+\/+)?(\S+)/mi);
'https://www.facebook.com/yourPage'; }
// check if we have a /page/username or without
if (username.match(/^(?:\/)?(pages?\/\S+)/mi)) {
// we got a page url, now save the username without the / in the beginning
[ , username ] = username.match(/^(?:\/)?(pages?\/\S+)/mi);
} else if (username.match(/^(http|www)|(\/)/) || !username.match(/^([a-z\d\.]{5,50})$/mi)) {
errMessage = !username.match(/^([a-z\d\.]{5,50})$/mi) ? 'Your Page name is not a valid Facebook Page name' : 'The URL must be in a format like https://www.facebook.com/yourPage';
this.get('model.errors').add('facebook', errMessage); this.get('model.errors').add('facebook', errMessage);
this.get('model.hasValidated').pushObject('facebook'); this.get('model.hasValidated').pushObject('facebook');
return; return;
} }
newUrl = `https://www.facebook.com/${username}`;
this.set('model.facebook', newUrl);
this.get('model.errors').remove('facebook');
this.get('model.hasValidated').pushObject('facebook');
// User input is validated
return this.save().then(() => {
this.set('model.facebook', '');
run.schedule('afterRender', this, function () {
this.set('model.facebook', newUrl);
});
});
} else {
errMessage = 'The URL must be in a format like ' +
'https://www.facebook.com/yourPage';
this.get('model.errors').add('facebook', errMessage);
this.get('model.hasValidated').pushObject('facebook');
return;
} }
}, },
@ -175,48 +192,61 @@ export default Controller.extend(SettingsSaveMixin, {
let oldUrl = this.get('model.twitter'); let oldUrl = this.get('model.twitter');
let errMessage = ''; let errMessage = '';
if (!newUrl) { if (newUrl === '') {
// Clear out the Facebook url // Clear out the Twitter url
this.set('model.twitter', ''); this.set('model.twitter', '');
this.get('model.errors').remove('twitter'); this.get('model.errors').remove('twitter');
return; return;
} }
// _scratchTwitter will be null unless the user has input something
if (!newUrl) {
newUrl = oldUrl;
}
// If new url didn't change, exit // If new url didn't change, exit
if (newUrl === oldUrl) { if (newUrl === oldUrl) {
this.get('model.errors').remove('twitter');
return; return;
} }
if (!newUrl.match(/(^https:\/\/twitter\.com\/)(\S+)/g)) { if (newUrl.match(/(?:twitter\.com\/)(\S+)/) || newUrl.match(/([a-z\d\.]+)/i)) {
if (newUrl.match(/(?:twitter\.com\/)(\S+)/) || (!validator.isURL(newUrl) && newUrl.match(/([a-zA-Z0-9\.]+)/))) { let username = [];
let [ , username] = newUrl.match(/(?:twitter\.com\/)(\S+)/) || newUrl.match(/([a-zA-Z0-9\.]+)/);
newUrl = `https://twitter.com/${username}`;
this.set('model.twitter', newUrl); if (newUrl.match(/(?:twitter\.com\/)(\S+)/)) {
[ , username] = newUrl.match(/(?:twitter\.com\/)(\S+)/);
this.get('model.errors').remove('twitter');
this.get('model.hasValidated').pushObject('twitter');
// User input is validated
return this.save().then(() => {
this.set('model.twitter', '');
run.schedule('afterRender', this, function () {
this.set('model.twitter', newUrl);
});
});
} else if (validator.isURL(newUrl)) {
errMessage = 'The URL must be in a format like ' +
'https://twitter.com/yourUsername';
this.get('model.errors').add('twitter', errMessage);
this.get('model.hasValidated').pushObject('twitter');
return;
} else { } else {
errMessage = 'The URL must be in a format like ' + [username] = newUrl.match(/([^/]+)\/?$/mi);
'https://twitter.com/yourUsername'; }
// check if username starts with http or www and show error if so
if (username.match(/^(http|www)|(\/)/) || !username.match(/^[a-z\d\.\_]{1,15}$/mi)) {
errMessage = !username.match(/^[a-z\d\.\_]{1,15}$/mi) ? 'Your Username is not a valid Twitter Username' : 'The URL must be in a format like https://twitter.com/yourUsername';
this.get('model.errors').add('twitter', errMessage); this.get('model.errors').add('twitter', errMessage);
this.get('model.hasValidated').pushObject('twitter'); this.get('model.hasValidated').pushObject('twitter');
return; return;
} }
newUrl = `https://twitter.com/${username}`;
this.set('model.twitter', newUrl);
this.get('model.errors').remove('twitter');
this.get('model.hasValidated').pushObject('twitter');
// User input is validated
return this.save().then(() => {
this.set('model.twitter', '');
run.schedule('afterRender', this, function () {
this.set('model.twitter', newUrl);
});
});
} else {
errMessage = 'The URL must be in a format like ' +
'https://twitter.com/yourUsername';
this.get('model.errors').add('twitter', errMessage);
this.get('model.hasValidated').pushObject('twitter');
return;
} }
} }
} }

View File

@ -249,50 +249,67 @@ export default Controller.extend({
let oldUrl = this.get('user.facebook'); let oldUrl = this.get('user.facebook');
let errMessage = ''; let errMessage = '';
if (!newUrl) { if (newUrl === '') {
// Clear out the Facebook url // Clear out the Facebook url
this.set('user.facebook', ''); this.set('user.facebook', '');
this.get('user.errors').remove('facebook'); this.get('user.errors').remove('facebook');
return; return;
} }
// _scratchFacebook will be null unless the user has input something
if (!newUrl) {
newUrl = oldUrl;
}
// If new url didn't change, exit // If new url didn't change, exit
if (newUrl === oldUrl) { if (newUrl === oldUrl) {
this.get('user.errors').remove('facebook');
return; return;
} }
// TODO: put the validation here into a validator // TODO: put the validation here into a validator
if (!newUrl.match(/(^https:\/\/www\.facebook\.com\/)(\S+)/g)) { if (newUrl.match(/(?:facebook\.com\/)(\S+)/) || newUrl.match(/([a-z\d\.]+)/i)) {
if (newUrl.match(/(?:facebook\.com\/)(\S+)/) || (!validator.isURL(newUrl) && newUrl.match(/([a-zA-Z0-9\.]+)/))) { let username = [];
let [ , username] = newUrl.match(/(?:facebook\.com\/)(\S+)/) || newUrl.match(/([a-zA-Z0-9\.]+)/);
newUrl = `https://www.facebook.com/${username}`;
this.set('user.facebook', newUrl); if (newUrl.match(/(?:facebook\.com\/)(\S+)/)) {
[ , username ] = newUrl.match(/(?:facebook\.com\/)(\S+)/);
this.get('user.errors').remove('facebook');
this.get('user.hasValidated').pushObject('facebook');
// User input is validated
invoke(this, 'save').then(() => {
// necessary to update the value in the input field
this.set('user.facebook', '');
run.schedule('afterRender', this, function () {
this.set('user.facebook', newUrl);
});
});
} else if (validator.isURL(newUrl)) {
errMessage = 'The URL must be in a format like ' +
'https://www.facebook.com/yourUsername';
this.get('user.errors').add('facebook', errMessage);
this.get('user.hasValidated').pushObject('facebook');
return;
} else { } else {
errMessage = 'The URL must be in a format like ' + [ , username ] = newUrl.match(/(?:https\:\/\/|http\:\/\/)?(?:www\.)?(?:\w+\.\w+\/+)?(\S+)/mi);
'https://www.facebook.com/yourUsername'; }
// check if we have a /page/username or without
if (username.match(/^(?:\/)?(pages?\/\S+)/mi)) {
// we got a page url, now save the username without the / in the beginning
[ , username ] = username.match(/^(?:\/)?(pages?\/\S+)/mi);
} else if (username.match(/^(http|www)|(\/)/) || !username.match(/^([a-z\d\.]{5,50})$/mi)) {
errMessage = !username.match(/^([a-z\d\.]{5,50})$/mi) ? 'Your Username is not a valid Facebook Username' : 'The URL must be in a format like https://www.facebook.com/yourUsername';
this.get('user.errors').add('facebook', errMessage); this.get('user.errors').add('facebook', errMessage);
this.get('user.hasValidated').pushObject('facebook'); this.get('user.hasValidated').pushObject('facebook');
return; return;
} }
newUrl = `https://www.facebook.com/${username}`;
this.set('user.facebook', newUrl);
this.get('user.errors').remove('facebook');
this.get('user.hasValidated').pushObject('facebook');
// User input is validated
invoke(this, 'save').then(() => {
// necessary to update the value in the input field
this.set('user.facebook', '');
run.schedule('afterRender', this, function () {
this.set('user.facebook', newUrl);
});
});
} else {
errMessage = 'The URL must be in a format like ' +
'https://www.facebook.com/yourUsername';
this.get('user.errors').add('facebook', errMessage);
this.get('user.hasValidated').pushObject('facebook');
return;
} }
}, },
@ -301,50 +318,63 @@ export default Controller.extend({
let oldUrl = this.get('user.twitter'); let oldUrl = this.get('user.twitter');
let errMessage = ''; let errMessage = '';
if (!newUrl) { if (newUrl === '') {
// Clear out the Twitter url // Clear out the Twitter url
this.set('user.twitter', ''); this.set('user.twitter', '');
this.get('user.errors').remove('twitter'); this.get('user.errors').remove('twitter');
return; return;
} }
// _scratchTwitter will be null unless the user has input something
if (!newUrl) {
newUrl = oldUrl;
}
// If new url didn't change, exit // If new url didn't change, exit
if (newUrl === oldUrl) { if (newUrl === oldUrl) {
this.get('user.errors').remove('twitter');
return; return;
} }
// TODO: put the validation here into a validator // TODO: put the validation here into a validator
if (!newUrl.match(/(^https:\/\/twitter\.com\/)(\S+)/g)) { if (newUrl.match(/(?:twitter\.com\/)(\S+)/) || newUrl.match(/([a-z\d\.]+)/i)) {
if (newUrl.match(/(?:twitter\.com\/)(\S+)/) || (!validator.isURL(newUrl) && newUrl.match(/([a-zA-Z0-9\.]+)/))) { let username = [];
let [ , username] = newUrl.match(/(?:twitter\.com\/)(\S+)/) || newUrl.match(/([a-zA-Z0-9\.]+)/);
newUrl = `https://twitter.com/${username}`;
this.set('user.twitter', newUrl); if (newUrl.match(/(?:twitter\.com\/)(\S+)/)) {
[ , username] = newUrl.match(/(?:twitter\.com\/)(\S+)/);
this.get('user.errors').remove('twitter');
this.get('user.hasValidated').pushObject('twitter');
// User input is validated
invoke(this, 'save').then(() => {
// necessary to update the value in the input field
this.set('user.twitter', '');
run.schedule('afterRender', this, function () {
this.set('user.twitter', newUrl);
});
});
} else if (validator.isURL(newUrl)) {
errMessage = 'The URL must be in a format like ' +
'https://twitter.com/yourUsername';
this.get('user.errors').add('twitter', errMessage);
this.get('user.hasValidated').pushObject('twitter');
return;
} else { } else {
errMessage = 'The URL must be in a format like ' + [username] = newUrl.match(/([^/]+)\/?$/mi);
'https://twitter.com/yourUsername'; }
// check if username starts with http or www and show error if so
if (username.match(/^(http|www)|(\/)/) || !username.match(/^[a-z\d\.\_]{1,15}$/mi)) {
errMessage = !username.match(/^[a-z\d\.\_]{1,15}$/mi) ? 'Your Username is not a valid Twitter Username' : 'The URL must be in a format like https://twitter.com/yourUsername';
this.get('user.errors').add('twitter', errMessage); this.get('user.errors').add('twitter', errMessage);
this.get('user.hasValidated').pushObject('twitter'); this.get('user.hasValidated').pushObject('twitter');
return; return;
} }
newUrl = `https://twitter.com/${username}`;
this.set('user.twitter', newUrl);
this.get('user.errors').remove('twitter');
this.get('user.hasValidated').pushObject('twitter');
// User input is validated
invoke(this, 'save').then(() => {
// necessary to update the value in the input field
this.set('user.twitter', '');
run.schedule('afterRender', this, function () {
this.set('user.twitter', newUrl);
});
});
} else {
errMessage = 'The URL must be in a format like ' +
'https://twitter.com/yourUsername';
this.get('user.errors').add('twitter', errMessage);
this.get('user.hasValidated').pushObject('twitter');
return;
} }
}, },

View File

@ -188,7 +188,7 @@ export default [
updated_at: '2016-05-08T15:20:25.953Z', updated_at: '2016-05-08T15:20:25.953Z',
updated_by: 1, updated_by: 1,
uuid: 'd4387e5c-3230-46dd-a89b-0d8a40365c35', uuid: 'd4387e5c-3230-46dd-a89b-0d8a40365c35',
value: '' value: 'test'
}, },
{ {
created_at: '2016-05-05T15:40:12.134Z', created_at: '2016-05-05T15:40:12.134Z',
@ -199,7 +199,7 @@ export default [
updated_at: '2016-05-08T15:20:25.954Z', updated_at: '2016-05-08T15:20:25.954Z',
updated_by: 1, updated_by: 1,
uuid: '5130441f-e4c7-4750-9692-a22d841ab049', uuid: '5130441f-e4c7-4750-9692-a22d841ab049',
value: '' value: '@test'
}, },
{ {
key: 'availableThemes', key: 'availableThemes',

View File

@ -18,7 +18,7 @@ export default Model.extend(ValidationEngine, {
availableThemes: attr(), availableThemes: attr(),
ghost_head: attr('string'), ghost_head: attr('string'),
ghost_foot: attr('string'), ghost_foot: attr('string'),
facebook: attr('string'), facebook: attr('facebook-url-user'),
twitter: attr('twitter-url-user'), twitter: attr('twitter-url-user'),
labs: attr('string'), labs: attr('string'),
navigation: attr('navigation-settings'), navigation: attr('navigation-settings'),

View File

@ -38,8 +38,8 @@ export default Model.extend(ValidationEngine, {
async: false async: false
}), }),
count: attr('raw'), count: attr('raw'),
facebook: attr('string'), facebook: attr('facebook-url-user'),
twitter: attr('string'), twitter: attr('twitter-url-user'),
ghostPaths: service(), ghostPaths: service(),
ajax: service(), ajax: service(),

View File

@ -0,0 +1,21 @@
import Transform from 'ember-data/transform';
export default Transform.extend({
deserialize(serialized) {
if (serialized) {
let [ , user ] = serialized.match(/(\S+)/);
return `https://www.facebook.com/${user}`;
}
return serialized;
},
serialize(deserialized) {
if (deserialized) {
let [ , user] = deserialized.match(/(?:https:\/\/)(?:www\.)(?:facebook\.com)\/(?:#!\/)?(\w+\/?\S+)/mi);
return user;
}
return deserialized;
}
});

View File

@ -163,6 +163,23 @@ describe('Acceptance: Settings - General', function () {
}); });
// validates a facebook url correctly // validates a facebook url correctly
andThen(() => {
// loads fixtures and performs transform
expect(find('input[name="general[facebook]"]').val(), 'initial facebook value')
.to.equal('https://www.facebook.com/test');
});
triggerEvent('#settings-general input[name="general[facebook]"]', 'focus');
triggerEvent('#settings-general input[name="general[facebook]"]', 'blur');
andThen(() => {
// regression test: we still have a value after the input is
// focused and then blurred without any changes
expect(find('input[name="general[facebook]"]').val(), 'facebook value after blur with no change')
.to.equal('https://www.facebook.com/test');
});
fillIn('#settings-general input[name="general[facebook]"]', 'facebook.com/username'); fillIn('#settings-general input[name="general[facebook]"]', 'facebook.com/username');
triggerEvent('#settings-general input[name="general[facebook]"]', 'blur'); triggerEvent('#settings-general input[name="general[facebook]"]', 'blur');
@ -172,6 +189,15 @@ describe('Acceptance: Settings - General', function () {
.to.equal(''); .to.equal('');
}); });
fillIn('#settings-general input[name="general[facebook]"]', 'facebook.com/pages/some-facebook-page/857469375913?ref=ts');
triggerEvent('#settings-general input[name="general[facebook]"]', 'blur');
andThen(() => {
expect(find('#settings-general input[name="general[facebook]"]').val()).to.be.equal('https://www.facebook.com/pages/some-facebook-page/857469375913?ref=ts');
expect(find('#settings-general .error .response').text().trim(), 'inline validation response')
.to.equal('');
});
fillIn('#settings-general input[name="general[facebook]"]', '*(&*(%%))'); fillIn('#settings-general input[name="general[facebook]"]', '*(&*(%%))');
triggerEvent('#settings-general input[name="general[facebook]"]', 'blur'); triggerEvent('#settings-general input[name="general[facebook]"]', 'blur');
@ -184,8 +210,18 @@ describe('Acceptance: Settings - General', function () {
triggerEvent('#settings-general input[name="general[facebook]"]', 'blur'); triggerEvent('#settings-general input[name="general[facebook]"]', 'blur');
andThen(() => { andThen(() => {
expect(find('#settings-general input[name="general[facebook]"]').val()).to.be.equal('https://www.facebook.com/username');
expect(find('#settings-general .error .response').text().trim(), 'inline validation response') expect(find('#settings-general .error .response').text().trim(), 'inline validation response')
.to.equal('The URL must be in a format like https://www.facebook.com/yourPage'); .to.equal('');
});
fillIn('#settings-general input[name="general[facebook]"]', 'http://github.com/pages/username');
triggerEvent('#settings-general input[name="general[facebook]"]', 'blur');
andThen(() => {
expect(find('#settings-general input[name="general[facebook]"]').val()).to.be.equal('https://www.facebook.com/pages/username');
expect(find('#settings-general .error .response').text().trim(), 'inline validation response')
.to.equal('');
}); });
fillIn('#settings-general input[name="general[facebook]"]', 'testuser'); fillIn('#settings-general input[name="general[facebook]"]', 'testuser');
@ -197,7 +233,50 @@ describe('Acceptance: Settings - General', function () {
.to.equal(''); .to.equal('');
}); });
fillIn('#settings-general input[name="general[facebook]"]', 'ab99');
triggerEvent('#settings-general input[name="general[facebook]"]', 'blur');
andThen(() => {
expect(find('#settings-general .error .response').text().trim(), 'inline validation response')
.to.equal('Your Page name is not a valid Facebook Page name');
});
fillIn('#settings-general input[name="general[facebook]"]', 'page/ab99');
triggerEvent('#settings-general input[name="general[facebook]"]', 'blur');
andThen(() => {
expect(find('#settings-general input[name="general[facebook]"]').val()).to.be.equal('https://www.facebook.com/page/ab99');
expect(find('#settings-general .error .response').text().trim(), 'inline validation response')
.to.equal('');
});
fillIn('#settings-general input[name="general[facebook]"]', 'page/*(&*(%%))');
triggerEvent('#settings-general input[name="general[facebook]"]', 'blur');
andThen(() => {
expect(find('#settings-general input[name="general[facebook]"]').val()).to.be.equal('https://www.facebook.com/page/*(&*(%%))');
expect(find('#settings-general .error .response').text().trim(), 'inline validation response')
.to.equal('');
});
// validates a twitter url correctly // validates a twitter url correctly
andThen(() => {
// loads fixtures and performs transform
expect(find('input[name="general[twitter]"]').val(), 'initial twitter value')
.to.equal('https://twitter.com/test');
});
triggerEvent('#settings-general input[name="general[twitter]"]', 'focus');
triggerEvent('#settings-general input[name="general[twitter]"]', 'blur');
andThen(() => {
// regression test: we still have a value after the input is
// focused and then blurred without any changes
expect(find('input[name="general[twitter]"]').val(), 'twitter value after blur with no change')
.to.equal('https://twitter.com/test');
});
fillIn('#settings-general input[name="general[twitter]"]', 'twitter.com/username'); fillIn('#settings-general input[name="general[twitter]"]', 'twitter.com/username');
triggerEvent('#settings-general input[name="general[twitter]"]', 'blur'); triggerEvent('#settings-general input[name="general[twitter]"]', 'blur');
@ -219,8 +298,17 @@ describe('Acceptance: Settings - General', function () {
triggerEvent('#settings-general input[name="general[twitter]"]', 'blur'); triggerEvent('#settings-general input[name="general[twitter]"]', 'blur');
andThen(() => { andThen(() => {
expect(find('#settings-general input[name="general[twitter]"]').val()).to.be.equal('https://twitter.com/username');
expect(find('#settings-general .error .response').text().trim(), 'inline validation response') expect(find('#settings-general .error .response').text().trim(), 'inline validation response')
.to.equal('The URL must be in a format like https://twitter.com/yourUsername'); .to.equal('');
});
fillIn('#settings-general input[name="general[twitter]"]', 'thisusernamehasmorethan15characters');
triggerEvent('#settings-general input[name="general[twitter]"]', 'blur');
andThen(() => {
expect(find('#settings-general .error .response').text().trim(), 'inline validation response')
.to.equal('Your Username is not a valid Twitter Username');
}); });
fillIn('#settings-general input[name="general[twitter]"]', 'testuser'); fillIn('#settings-general input[name="general[twitter]"]', 'testuser');

View File

@ -239,7 +239,12 @@ describe('Acceptance: Team', function () {
let user; let user;
beforeEach(function () { beforeEach(function () {
server.create('user', {slug: 'test-1', name: 'Test User'}); server.create('user', {
slug: 'test-1',
name: 'Test User',
facebook: 'test',
twitter: '@test'
});
server.loadFixtures(); server.loadFixtures();
}); });
@ -313,6 +318,24 @@ describe('Acceptance: Team', function () {
expect(find('.user-details-bottom .form-group:nth-of-type(4)').hasClass('error'), 'website input should be in error state').to.be.true; expect(find('.user-details-bottom .form-group:nth-of-type(4)').hasClass('error'), 'website input should be in error state').to.be.true;
}); });
// Testing Facebook input
andThen(() => {
// displays initial value
expect(find('#user-facebook').val(), 'initial facebook value')
.to.equal('https://www.facebook.com/test');
});
triggerEvent('#user-facebook', 'focus');
triggerEvent('#user-facebook', 'blur');
andThen(() => {
// regression test: we still have a value after the input is
// focused and then blurred without any changes
expect(find('#user-facebook').val(), 'facebook value after blur with no change')
.to.equal('https://www.facebook.com/test');
});
fillIn('#user-facebook', ''); fillIn('#user-facebook', '');
fillIn('#user-facebook', ')(*&%^%)'); fillIn('#user-facebook', ')(*&%^%)');
triggerEvent('#user-facebook', 'blur'); triggerEvent('#user-facebook', 'blur');
@ -322,16 +345,34 @@ describe('Acceptance: Team', function () {
}); });
fillIn('#user-facebook', ''); fillIn('#user-facebook', '');
fillIn('#user-facebook', 'name'); fillIn('#user-facebook', 'pages/)(*&%^%)');
triggerEvent('#user-facebook', 'blur'); triggerEvent('#user-facebook', 'blur');
andThen(() => { andThen(() => {
expect(find('#user-facebook').val()).to.be.equal('https://www.facebook.com/name'); expect(find('#user-facebook').val()).to.be.equal('https://www.facebook.com/pages/)(*&%^%)');
expect(find('.user-details-bottom .form-group:nth-of-type(5)').hasClass('error'), 'facebook input should be in error state').to.be.false; expect(find('.user-details-bottom .form-group:nth-of-type(5)').hasClass('error'), 'facebook input should be in error state').to.be.false;
}); });
fillIn('#user-facebook', ''); fillIn('#user-facebook', '');
fillIn('#user-facebook', 'http://twitter.com/user'); fillIn('#user-facebook', 'testing');
triggerEvent('#user-facebook', 'blur');
andThen(() => {
expect(find('#user-facebook').val()).to.be.equal('https://www.facebook.com/testing');
expect(find('.user-details-bottom .form-group:nth-of-type(5)').hasClass('error'), 'facebook input should be in error state').to.be.false;
});
fillIn('#user-facebook', '');
fillIn('#user-facebook', 'somewebsite.com/pages/some-facebook-page/857469375913?ref=ts');
triggerEvent('#user-facebook', 'blur');
andThen(() => {
expect(find('#user-facebook').val()).to.be.equal('https://www.facebook.com/pages/some-facebook-page/857469375913?ref=ts');
expect(find('.user-details-bottom .form-group:nth-of-type(5)').hasClass('error'), 'facebook input should be in error state').to.be.false;
});
fillIn('#user-facebook', '');
fillIn('#user-facebook', 'test');
triggerEvent('#user-facebook', 'blur'); triggerEvent('#user-facebook', 'blur');
andThen(() => { andThen(() => {
@ -339,14 +380,41 @@ describe('Acceptance: Team', function () {
}); });
fillIn('#user-facebook', ''); fillIn('#user-facebook', '');
fillIn('#user-facebook', 'facebook.com/user'); fillIn('#user-facebook', 'http://twitter.com/testuser');
triggerEvent('#user-facebook', 'blur'); triggerEvent('#user-facebook', 'blur');
andThen(() => { andThen(() => {
expect(find('#user-facebook').val()).to.be.equal('https://www.facebook.com/user'); expect(find('#user-facebook').val()).to.be.equal('https://www.facebook.com/testuser');
expect(find('.user-details-bottom .form-group:nth-of-type(5)').hasClass('error'), 'facebook input should be in error state').to.be.false; expect(find('.user-details-bottom .form-group:nth-of-type(5)').hasClass('error'), 'facebook input should be in error state').to.be.false;
}); });
fillIn('#user-facebook', '');
fillIn('#user-facebook', 'facebook.com/testing');
triggerEvent('#user-facebook', 'blur');
andThen(() => {
expect(find('#user-facebook').val()).to.be.equal('https://www.facebook.com/testing');
expect(find('.user-details-bottom .form-group:nth-of-type(5)').hasClass('error'), 'facebook input should be in error state').to.be.false;
});
// Testing Twitter input
andThen(() => {
// loads fixtures and performs transform
expect(find('#user-twitter').val(), 'initial twitter value')
.to.equal('https://twitter.com/test');
});
triggerEvent('#user-twitter', 'focus');
triggerEvent('#user-twitter', 'blur');
andThen(() => {
// regression test: we still have a value after the input is
// focused and then blurred without any changes
expect(find('#user-twitter').val(), 'twitter value after blur with no change')
.to.equal('https://twitter.com/test');
});
fillIn('#user-twitter', ''); fillIn('#user-twitter', '');
fillIn('#user-twitter', ')(*&%^%)'); fillIn('#user-twitter', ')(*&%^%)');
triggerEvent('#user-twitter', 'blur'); triggerEvent('#user-twitter', 'blur');
@ -369,7 +437,8 @@ describe('Acceptance: Team', function () {
triggerEvent('#user-twitter', 'blur'); triggerEvent('#user-twitter', 'blur');
andThen(() => { andThen(() => {
expect(find('.user-details-bottom .form-group:nth-of-type(6)').hasClass('error'), 'twitter input should be in error state').to.be.true; expect(find('#user-twitter').val()).to.be.equal('https://twitter.com/user');
expect(find('.user-details-bottom .form-group:nth-of-type(6)').hasClass('error'), 'twitter input should be in error state').to.be.false;
}); });
fillIn('#user-twitter', ''); fillIn('#user-twitter', '');

View File

@ -0,0 +1,32 @@
/* jshint expr:true */
import { expect } from 'chai';
import { describeModule, it } from 'ember-mocha';
import Ember from 'ember';
const emberA = Ember.A;
describeModule(
'transform:facebook-url-user',
'Unit: Transform: facebook-url-user',
{
// Specify the other units that are required for this test.
// needs: ['transform:foo']
},
function() {
it('deserializes facebook url', function () {
let transform = this.subject();
let serialized = 'testuser';
let result = transform.deserialize(serialized);
expect(result).to.equal('https://www.facebook.com/testuser');
});
it('serializes url to facebook username', function () {
let transform = this.subject();
let deserialized = 'https://www.facebook.com/testuser';
let result = transform.serialize(deserialized);
expect(result).to.equal('testuser');
});
}
);

View File

@ -1,5 +1,6 @@
var config = require('../../config'), var config = require('../../config'),
hbs = require('express-hbs'), hbs = require('express-hbs'),
socialUrls = require('../../utils/social-urls'),
escapeExpression = hbs.handlebars.Utils.escapeExpression, escapeExpression = hbs.handlebars.Utils.escapeExpression,
_ = require('lodash'); _ = require('lodash');
@ -23,20 +24,20 @@ function trimSameAs(data, context) {
sameAs.push(data.post.author.website); sameAs.push(data.post.author.website);
} }
if (data.post.author.facebook) { if (data.post.author.facebook) {
sameAs.push(data.post.author.facebook); sameAs.push(socialUrls.facebookUrl(data.post.author.facebook));
} }
if (data.post.author.twitter) { if (data.post.author.twitter) {
sameAs.push(data.post.author.twitter); sameAs.push(socialUrls.twitterUrl(data.post.author.twitter));
} }
} else if (context === 'author') { } else if (context === 'author') {
if (data.author.website) { if (data.author.website) {
sameAs.push(data.author.website); sameAs.push(data.author.website);
} }
if (data.author.facebook) { if (data.author.facebook) {
sameAs.push(data.author.facebook); sameAs.push(socialUrls.facebookUrl(data.author.facebook));
} }
if (data.author.twitter) { if (data.author.twitter) {
sameAs.push(data.author.twitter); sameAs.push(socialUrls.twitterUrl(data.author.twitter));
} }
} }

View File

@ -1,16 +1,13 @@
var socialUrls = require('../../utils/social-urls');
function getStructuredData(metaData) { function getStructuredData(metaData) {
var structuredData, var structuredData,
card = 'summary', card = 'summary';
twitterUser;
if (metaData.coverImage) { if (metaData.coverImage) {
card = 'summary_large_image'; card = 'summary_large_image';
} }
if (metaData.creatorTwitter) {
twitterUser = '@' + metaData.creatorTwitter.match(/(?:https:\/\/)(?:twitter\.com)\/(?:#!\/)?@?([^\/]*)/)[1];
}
structuredData = { structuredData = {
'og:site_name': metaData.blog.title, 'og:site_name': metaData.blog.title,
'og:type': metaData.ogType, 'og:type': metaData.ogType,
@ -21,8 +18,8 @@ function getStructuredData(metaData) {
'article:published_time': metaData.publishedDate, 'article:published_time': metaData.publishedDate,
'article:modified_time': metaData.modifiedDate, 'article:modified_time': metaData.modifiedDate,
'article:tag': metaData.keywords, 'article:tag': metaData.keywords,
'article:publisher': metaData.blog.facebook || undefined, 'article:publisher': metaData.blog.facebook ? socialUrls.facebookUrl(metaData.blog.facebook) : undefined,
'article:author': metaData.authorFacebook || undefined, 'article:author': metaData.authorFacebook ? socialUrls.facebookUrl(metaData.authorFacebook) : undefined,
'twitter:card': card, 'twitter:card': card,
'twitter:title': metaData.metaTitle, 'twitter:title': metaData.metaTitle,
'twitter:description': metaData.metaDescription || metaData.excerpt, 'twitter:description': metaData.metaDescription || metaData.excerpt,
@ -33,7 +30,7 @@ function getStructuredData(metaData) {
'twitter:label2': metaData.keywords ? 'Filed under' : undefined, 'twitter:label2': metaData.keywords ? 'Filed under' : undefined,
'twitter:data2': metaData.keywords ? metaData.keywords.join(', ') : undefined, 'twitter:data2': metaData.keywords ? metaData.keywords.join(', ') : undefined,
'twitter:site': metaData.blog.twitter || undefined, 'twitter:site': metaData.blog.twitter || undefined,
'twitter:creator': twitterUser || undefined 'twitter:creator': metaData.creatorTwitter || undefined
}; };
// return structured data removing null or undefined keys // return structured data removing null or undefined keys

View File

@ -35,8 +35,8 @@ module.exports = {
bio: {type: 'string', maxlength: 200, nullable: true}, bio: {type: 'string', maxlength: 200, nullable: true},
website: {type: 'text', maxlength: 2000, nullable: true, validations: {isEmptyOrURL: true}}, website: {type: 'text', maxlength: 2000, nullable: true, validations: {isEmptyOrURL: true}},
location: {type: 'text', maxlength: 65535, nullable: true}, location: {type: 'text', maxlength: 65535, nullable: true},
facebook: {type: 'text', maxlength: 2000, nullable: true, validations: {isEmptyOrURL: true}}, facebook: {type: 'text', maxlength: 2000, nullable: true},
twitter: {type: 'text', maxlength: 2000, nullable: true, validations: {isEmptyOrURL: true}}, twitter: {type: 'text', maxlength: 2000, nullable: true},
accessibility: {type: 'text', maxlength: 65535, nullable: true}, accessibility: {type: 'text', maxlength: 65535, nullable: true},
status: {type: 'string', maxlength: 150, nullable: false, defaultTo: 'active'}, status: {type: 'string', maxlength: 150, nullable: false, defaultTo: 'active'},
language: {type: 'string', maxlength: 6, nullable: false, defaultTo: 'en_US'}, language: {type: 'string', maxlength: 6, nullable: false, defaultTo: 'en_US'},

View File

@ -0,0 +1,26 @@
// # Facebook URL Helper
// Usage: `{{facebook_url}}` or `{{facebook_url author.facebook}}`
//
// Output a url for a twitter username
//
// We use the name facebook_url to match the helper for consistency:
// jscs:disable requireCamelCaseOrUpperCaseIdentifiers
var socialUrls = require('../utils/social-urls'),
findKey = require('./utils').findKey,
facebook_url;
facebook_url = function (username, options) {
if (!options) {
options = username;
username = findKey('facebook', this, options.data.blog);
}
if (username) {
return socialUrls.facebookUrl(username);
}
return null;
};
module.exports = facebook_url;

View File

@ -17,6 +17,7 @@ coreHelpers.content = require('./content');
coreHelpers.date = require('./date'); coreHelpers.date = require('./date');
coreHelpers.encode = require('./encode'); coreHelpers.encode = require('./encode');
coreHelpers.excerpt = require('./excerpt'); coreHelpers.excerpt = require('./excerpt');
coreHelpers.facebook_url = require('./facebook_url');
coreHelpers.foreach = require('./foreach'); coreHelpers.foreach = require('./foreach');
coreHelpers.get = require('./get'); coreHelpers.get = require('./get');
coreHelpers.ghost_foot = require('./ghost_foot'); coreHelpers.ghost_foot = require('./ghost_foot');
@ -34,6 +35,7 @@ coreHelpers.prev_post = require('./prev_next');
coreHelpers.next_post = require('./prev_next'); coreHelpers.next_post = require('./prev_next');
coreHelpers.tags = require('./tags'); coreHelpers.tags = require('./tags');
coreHelpers.title = require('./title'); coreHelpers.title = require('./title');
coreHelpers.twitter_url = require('./twitter_url');
coreHelpers.url = require('./url'); coreHelpers.url = require('./url');
// Specialist helpers for certain templates // Specialist helpers for certain templates
@ -110,6 +112,8 @@ registerHelpers = function (adminHbs) {
registerThemeHelper('post_class', coreHelpers.post_class); registerThemeHelper('post_class', coreHelpers.post_class);
registerThemeHelper('tags', coreHelpers.tags); registerThemeHelper('tags', coreHelpers.tags);
registerThemeHelper('title', coreHelpers.title); registerThemeHelper('title', coreHelpers.title);
registerThemeHelper('twitter_url', coreHelpers.twitter_url);
registerThemeHelper('facebook_url', coreHelpers.facebook_url);
registerThemeHelper('url', coreHelpers.url); registerThemeHelper('url', coreHelpers.url);
// Async theme helpers // Async theme helpers

View File

@ -0,0 +1,26 @@
// # Twitter URL Helper
// Usage: `{{twitter_url}}` or `{{twitter_url author.twitter}}`
//
// Output a url for a twitter username
//
// We use the name twitter_url to match the helper for consistency:
// jscs:disable requireCamelCaseOrUpperCaseIdentifiers
var socialUrls = require('../utils/social-urls'),
findKey = require('./utils').findKey,
twitter_url;
twitter_url = function twitter_url(username, options) {
if (!options) {
options = username;
username = findKey('twitter', this, options.data.blog);
}
if (username) {
return socialUrls.twitterUrl(username);
}
return null;
};
module.exports = twitter_url;

View File

@ -6,7 +6,19 @@ utils = {
linkTemplate: _.template('<a href="<%= url %>"><%= text %></a>'), linkTemplate: _.template('<a href="<%= url %>"><%= text %></a>'),
scriptTemplate: _.template('<script src="<%= source %>?v=<%= version %>"></script>'), scriptTemplate: _.template('<script src="<%= source %>?v=<%= version %>"></script>'),
inputTemplate: _.template('<input class="<%= className %>" type="<%= type %>" name="<%= name %>" <%= extras %> />'), inputTemplate: _.template('<input class="<%= className %>" type="<%= type %>" name="<%= name %>" <%= extras %> />'),
isProduction: process.env.NODE_ENV === 'production' isProduction: process.env.NODE_ENV === 'production',
// @TODO this can probably be made more generic and used in more places
findKey: function findKey(key, object, data) {
if (object && _.has(object, key) && !_.isEmpty(object[key])) {
return object[key];
}
if (data && _.has(data, key) && !_.isEmpty(data[key])) {
return data[key];
}
return null;
}
}; };
module.exports = utils; module.exports = utils;

View File

@ -0,0 +1,9 @@
module.exports.twitterUrl = function twitterUrl(username) {
// Creates the canonical twitter URL without the '@'
return 'https://twitter.com/' + username.replace(/^@/, '');
};
module.exports.facebookUrl = function facebookUrl(username) {
// Handles a starting slash, this shouldn't happen, but just in case
return 'https://www.facebook.com/' + username.replace(/^\//, '');
};

View File

@ -10,7 +10,7 @@ describe('getSchema', function () {
logo: 'http://mysite.com/author/image/url/logo.jpg' logo: 'http://mysite.com/author/image/url/logo.jpg'
}, },
authorImage: 'http://mysite.com/author/image/url/me.jpg', authorImage: 'http://mysite.com/author/image/url/me.jpg',
authorFacebook: 'https://facebook.com/testuser', authorFacebook: 'testuser',
creatorTwitter: '@testuser', creatorTwitter: '@testuser',
authorUrl: 'http://mysite.com/author/me/', authorUrl: 'http://mysite.com/author/me/',
metaTitle: 'Post Title', metaTitle: 'Post Title',
@ -27,8 +27,8 @@ describe('getSchema', function () {
name: 'Post Author', name: 'Post Author',
website: 'http://myblogsite.com/', website: 'http://myblogsite.com/',
bio: 'My author bio.', bio: 'My author bio.',
facebook: 'https://www.facebook.com/testuser', facebook: 'testuser',
twitter: 'https://twitter.com/testuser' twitter: '@testuser'
} }
} }
}, schema = getSchema(metadata, data); }, schema = getSchema(metadata, data);
@ -175,7 +175,7 @@ describe('getSchema', function () {
author: { author: {
name: 'Author Name', name: 'Author Name',
website: 'http://myblogsite.com/', website: 'http://myblogsite.com/',
twitter: 'https://twitter.com/testuser' twitter: '@testuser'
} }
}, schema = getSchema(metadata, data); }, schema = getSchema(metadata, data);

View File

@ -7,7 +7,7 @@ describe('getStructuredData', function () {
var metadata = { var metadata = {
blog: { blog: {
title: 'Blog Title', title: 'Blog Title',
facebook: 'https://www.facebook.com/testuser', facebook: 'testuser',
twitter: '@testuser' twitter: '@testuser'
}, },
authorName: 'Test User', authorName: 'Test User',
@ -17,8 +17,8 @@ describe('getStructuredData', function () {
publishedDate: '2015-12-25T05:35:01.234Z', publishedDate: '2015-12-25T05:35:01.234Z',
modifiedDate: '2016-01-21T22:13:05.412Z', modifiedDate: '2016-01-21T22:13:05.412Z',
coverImage: 'http://mysite.com/content/image/mypostcoverimage.jpg', coverImage: 'http://mysite.com/content/image/mypostcoverimage.jpg',
authorFacebook: 'https://www.facebook.com/testpage', authorFacebook: 'testpage',
creatorTwitter: 'https://twitter.com/twitterpage', creatorTwitter: '@twitterpage',
keywords: ['one', 'two', 'tag'], keywords: ['one', 'two', 'tag'],
metaDescription: 'Post meta description' metaDescription: 'Post meta description'
}, structuredData = getStructuredData(metadata); }, structuredData = getStructuredData(metadata);

View File

@ -0,0 +1,48 @@
/*globals describe, before, beforeEach, it*/
var should = require('should'),
hbs = require('express-hbs'),
utils = require('./utils'),
// Stuff we are testing
handlebars = hbs.handlebars,
helpers = require('../../../server/helpers');
describe('{{facebook_url}} helper', function () {
var options = {data: {blog: {}}};
before(function () {
utils.loadHelpers();
});
beforeEach(function () {
options.data.blog = {facebook: ''};
});
it('has loaded facebook_url helper', function () {
should.exist(handlebars.helpers.facebook_url);
});
it('should output the facebook url for @blog, if no other facebook username is provided', function () {
options.data.blog = {facebook: 'hey'};
helpers.facebook_url.call({}, options).should.equal('https://www.facebook.com/hey');
});
it('should output the facebook url for the local object, if it has one', function () {
options.data.blog = {facebook: 'hey'};
helpers.facebook_url.call({facebook: 'you/there'}, options).should.equal('https://www.facebook.com/you/there');
});
it('should output the facebook url for the provided username when it is explicitly passed in', function () {
options.data.blog = {facebook: 'hey'};
helpers.facebook_url.call({facebook: 'you/there'}, 'i/see/you/over/there', options)
.should.equal('https://www.facebook.com/i/see/you/over/there');
});
it('should return null if there are no facebook usernames', function () {
should.equal(helpers.facebook_url(options), null);
});
});

View File

@ -124,8 +124,8 @@ describe('{{ghost_head}} helper', function () {
slug: 'Author', slug: 'Author',
image: '/content/images/test-author-image.png', image: '/content/images/test-author-image.png',
website: 'http://authorwebsite.com', website: 'http://authorwebsite.com',
facebook: 'https://www.facebook.com/testuser', facebook: 'testuser',
twitter: 'https://twitter.com/testuser', twitter: '@testuser',
bio: 'Author bio' bio: 'Author bio'
} }
}; };
@ -301,8 +301,8 @@ describe('{{ghost_head}} helper', function () {
image: '/content/images/test-author-image.png', image: '/content/images/test-author-image.png',
cover: '/content/images/author-cover-image.png', cover: '/content/images/author-cover-image.png',
website: 'http://authorwebsite.com', website: 'http://authorwebsite.com',
facebook: 'https://www.facebook.com/testuser', facebook: 'testuser',
twitter: 'https://twitter.com/testuser' twitter: '@testuser'
}, authorBk = _.cloneDeep(author); }, authorBk = _.cloneDeep(author);
helpers.ghost_head.call( helpers.ghost_head.call(
@ -393,8 +393,8 @@ describe('{{ghost_head}} helper', function () {
image: '/content/images/test-author-image.png', image: '/content/images/test-author-image.png',
website: 'http://authorwebsite.com', website: 'http://authorwebsite.com',
bio: 'Author bio', bio: 'Author bio',
facebook: 'https://www.facebook.com/testuser', facebook: 'testuser',
twitter: 'https://twitter.com/testuser' twitter: '@testuser'
} }
}, postBk = _.cloneDeep(post); }, postBk = _.cloneDeep(post);
@ -470,8 +470,8 @@ describe('{{ghost_head}} helper', function () {
slug: 'Author', slug: 'Author',
image: '/content/images/test-author-image.png', image: '/content/images/test-author-image.png',
website: 'http://authorwebsite.com', website: 'http://authorwebsite.com',
facebook: 'https://www.facebook.com/testuser', facebook: 'testuser',
twitter: 'https://twitter.com/testuser' twitter: '@testuser'
} }
}; };
@ -546,8 +546,8 @@ describe('{{ghost_head}} helper', function () {
slug: 'Author', slug: 'Author',
image: '/content/images/test-author-image.png', image: '/content/images/test-author-image.png',
website: 'http://authorwebsite.com', website: 'http://authorwebsite.com',
facebook: 'https://www.facebook.com/testuser', facebook: 'testuser',
twitter: 'https://twitter.com/testuser' twitter: '@testuser'
} }
}; };
@ -618,8 +618,8 @@ describe('{{ghost_head}} helper', function () {
slug: 'Author', slug: 'Author',
image: null, image: null,
website: 'http://authorwebsite.com', website: 'http://authorwebsite.com',
facebook: 'https://www.facebook.com/testuser', facebook: 'testuser',
twitter: 'https://twitter.com/testuser' twitter: '@testuser'
} }
}; };
@ -833,8 +833,8 @@ describe('{{ghost_head}} helper', function () {
slug: 'Author', slug: 'Author',
image: 'content/images/test-author-image.png', image: 'content/images/test-author-image.png',
website: 'http://authorwebsite.com', website: 'http://authorwebsite.com',
facebook: 'https://www.facebook.com/testuser', facebook: 'testuser',
twitter: 'https://twitter.com/testuser' twitter: '@testuser'
} }
}; };

View File

@ -0,0 +1,48 @@
/*globals describe, before, beforeEach, it*/
var should = require('should'),
hbs = require('express-hbs'),
utils = require('./utils'),
// Stuff we are testing
handlebars = hbs.handlebars,
helpers = require('../../../server/helpers');
describe('{{twitter_url}} helper', function () {
var options = {data: {blog: {}}};
before(function () {
utils.loadHelpers();
});
beforeEach(function () {
options.data.blog = {twitter: ''};
});
it('has loaded twitter_url helper', function () {
should.exist(handlebars.helpers.twitter_url);
});
it('should output the twitter url for @blog, if no other twitter username is provided', function () {
options.data.blog = {twitter: '@hey'};
helpers.twitter_url.call({}, options).should.equal('https://twitter.com/hey');
});
it('should output the twitter url for the local object, if it has one', function () {
options.data.blog = {twitter: '@hey'};
helpers.twitter_url.call({twitter: '@youthere'}, options).should.equal('https://twitter.com/youthere');
});
it('should output the twitter url for the provided username when it is explicitly passed in', function () {
options.data.blog = {twitter: '@hey'};
helpers.twitter_url.call({twitter: '@youthere'}, '@iseeyouoverthere', options)
.should.equal('https://twitter.com/iseeyouoverthere');
});
it('should return null if there are no twitter usernames', function () {
should.equal(helpers.twitter_url(options), null);
});
});

View File

@ -0,0 +1,39 @@
/*globals describe, it*/
var should = require('should'),
// Stuff we are testing
socialUrls = require('../../server/utils/social-urls');
describe('Social Urls', function () {
it('should have a twitter url function', function () {
should.exist(socialUrls.twitterUrl);
});
it('should have a facebook url function', function () {
should.exist(socialUrls.facebookUrl);
});
describe('twitter', function () {
it('should return a correct concatenated URL', function () {
socialUrls.twitterUrl('myusername').should.eql('https://twitter.com/myusername');
});
it('should return a url without an @ sign if one is provided', function () {
socialUrls.twitterUrl('@myusername').should.eql('https://twitter.com/myusername');
});
});
describe('facebook', function () {
it('should return a correct concatenated URL', function () {
socialUrls.facebookUrl('myusername').should.eql('https://www.facebook.com/myusername');
});
it('should return a correct concatenated URL for usernames with slashes', function () {
socialUrls.facebookUrl('page/xxx/123').should.eql('https://www.facebook.com/page/xxx/123');
});
it('should return a correct concatenated URL for usernames which start with a slash', function () {
socialUrls.facebookUrl('/page/xxx/123').should.eql('https://www.facebook.com/page/xxx/123');
});
});
});