Skip to content

Commit

Permalink
Merge pull request #1360 from leider/blanksagain
Browse files Browse the repository at this point in the history
fixes #1356 without breaking legacy data
  • Loading branch information
NicoleRauch committed Jun 30, 2018
2 parents 633d287 + cb38158 commit 8d95010
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 11 deletions.
2 changes: 1 addition & 1 deletion commonComponents/frontend-js/frontendutils.js
Expand Up @@ -6,7 +6,7 @@ function surroundWithLink(text) {
// shamelessly stolen from http://stackoverflow.com/questions/1500260/detect-urls-in-text-with-javascript // shamelessly stolen from http://stackoverflow.com/questions/1500260/detect-urls-in-text-with-javascript
var urlRegex = /(\b(https?|ftp|file):\/\/[\-A-Z0-9+&@#\/%?=~_|!:,.;]*[\-A-Z0-9+&@#\/%=~_|])/ig; var urlRegex = /(\b(https?|ftp|file):\/\/[\-A-Z0-9+&@#\/%?=~_|!:,.;]*[\-A-Z0-9+&@#\/%=~_|])/ig;
return text.replace(urlRegex, function (url) { return text.replace(urlRegex, function (url) {
return '<a href="' + url + '" target="_blank">' + '<i class="fa fa-external-link"/> ' + url + '</a>'; return '<a href="' + url + '" target="_blank">' + '<i class="fa fa-external-link"/> ' + url + ' </a>';
}); });
} }


Expand Down
12 changes: 6 additions & 6 deletions softwerkskammer/frontendtests/surroundWithLink-tests.js
Expand Up @@ -10,29 +10,29 @@
describe('surround with link', function () { describe('surround with link', function () {
it('surrounds a text starting with "http" with a link consisting of the text', function () { it('surrounds a text starting with "http" with a link consisting of the text', function () {
var result = surroundWithLink('http://my.link'); var result = surroundWithLink('http://my.link');
expect(result).to.equal('<a href="http://my.link" target="_blank"><i class="fa fa-external-link"/> http://my.link</a>'); expect(result).to.equal('<a href="http://my.link" target="_blank"><i class="fa fa-external-link"/> http://my.link </a>');
}); });


it('surrounds each link in a text with two "http" links', function () { it('surrounds each link in a text with two "http" links', function () {
var result = surroundWithLink('http://my.link, http://your.link'); var result = surroundWithLink('http://my.link, http://your.link');
expect(result).to.equal('<a href="http://my.link" target="_blank"><i class="fa fa-external-link"/> http://my.link</a>, <a href="http://your.link" target="_blank"><i class="fa fa-external-link"/> http://your.link</a>'); expect(result).to.equal('<a href="http://my.link" target="_blank"><i class="fa fa-external-link"/> http://my.link </a>, <a href="http://your.link" target="_blank"><i class="fa fa-external-link"/> http://your.link </a>');
}); });


it('surrounds only links in a text', function () { it('surrounds only links in a text', function () {
var result = surroundWithLink('http://my.link, your.link'); var result = surroundWithLink('http://my.link, your.link');
expect(result).to.equal('<a href="http://my.link" target="_blank"><i class="fa fa-external-link"/> http://my.link</a>, your.link'); expect(result).to.equal('<a href="http://my.link" target="_blank"><i class="fa fa-external-link"/> http://my.link </a>, your.link');
}); });


it('links an element inside class "urlify"', function () { it('links an element inside class "urlify"', function () {
expect($('#first').html()).to.equal('<a href="http://my.first.link" target="_blank"><i class="fa fa-external-link"></i> http://my.first.link</a>'); expect($('#first').html()).to.equal('<a href="http://my.first.link" target="_blank"><i class="fa fa-external-link"></i> http://my.first.link </a>');
}); });


it('links two elements inside class "urlify"', function () { it('links two elements inside class "urlify"', function () {
expect($('#second').html()).to.equal('<a href="http://my.first.link" target="_blank"><i class="fa fa-external-link"></i> http://my.first.link</a>, <a href="http://my.first.link.again" target="_blank"><i class="fa fa-external-link"></i> http://my.first.link.again</a>'); expect($('#second').html()).to.equal('<a href="http://my.first.link" target="_blank"><i class="fa fa-external-link"></i> http://my.first.link </a>, <a href="http://my.first.link.again" target="_blank"><i class="fa fa-external-link"></i> http://my.first.link.again </a>');
}); });


it('links one of two elements inside class "urlify"', function () { it('links one of two elements inside class "urlify"', function () {
expect($('#third').html()).to.equal('<a href="http://my.first.link" target="_blank"><i class="fa fa-external-link"></i> http://my.first.link</a>, my.first.link.again'); expect($('#third').html()).to.equal('<a href="http://my.first.link" target="_blank"><i class="fa fa-external-link"></i> http://my.first.link </a>, my.first.link.again');
}); });
}); });


Expand Down
4 changes: 2 additions & 2 deletions softwerkskammer/lib/members/member.js
Expand Up @@ -143,11 +143,11 @@ class Member {
} }


interests() { interests() {
return this.state.interests; return this.interestsForSelect2().join(', ');
} }


interestsForSelect2() { interestsForSelect2() {
return (this.interests() || '').split(',').map(s => s.trim()); return (this.state.interests || '').split(',').map(s => s.trim());
} }


reference() { reference() {
Expand Down
15 changes: 13 additions & 2 deletions softwerkskammer/test/members/member_object_test.js
Expand Up @@ -68,7 +68,8 @@ describe('Member initial filling', () => {
expect(member.twitter()).not.to.exist(); expect(member.twitter()).not.to.exist();
expect(member.location()).not.to.exist(); expect(member.location()).not.to.exist();
expect(member.profession()).not.to.exist(); expect(member.profession()).not.to.exist();
expect(member.interests()).not.to.exist(); expect(member.state.interests).not.to.exist();
expect(member.interests()).to.eql('');
expect(member.site()).not.to.exist(); expect(member.site()).not.to.exist();
expect(member.reference()).not.to.exist(); expect(member.reference()).not.to.exist();
}); });
Expand All @@ -92,7 +93,8 @@ describe('fillFromUI', () => {
expect(member.twitter()).not.to.exist(); expect(member.twitter()).not.to.exist();
expect(member.location()).not.to.exist(); expect(member.location()).not.to.exist();
expect(member.profession()).not.to.exist(); expect(member.profession()).not.to.exist();
expect(member.interests()).not.to.exist(); expect(member.state.interests).not.to.exist();
expect(member.interests()).to.eql('');
expect(member.site()).not.to.exist(); expect(member.site()).not.to.exist();
expect(member.reference()).not.to.exist(); expect(member.reference()).not.to.exist();
expect(member.notifyOnWikiChanges()).to.be.false(); expect(member.notifyOnWikiChanges()).to.be.false();
Expand Down Expand Up @@ -128,6 +130,15 @@ describe('fillFromUI', () => {
expect(member.notifyOnWikiChanges()).to.be.true(); expect(member.notifyOnWikiChanges()).to.be.true();
}); });


it('handles interests correctly - saving as string without blanks for legacy compatibilty - but displaying it with blanks', () => {
const record = {
interests: ['Everything', 'And more'],
};
const member = new Member().fillFromUI(record);
expect(member.state.interests).to.equal('Everything,And more');
expect(member.interests()).to.equal('Everything, And more');
});

}); });


describe('Member twitter field autocorrection', () => { describe('Member twitter field autocorrection', () => {
Expand Down

0 comments on commit 8d95010

Please sign in to comment.