|
| 1 | +/* |
| 2 | + * Copyright (c) 2002-2019 "Neo4j," |
| 3 | + * Neo4j Sweden AB [http://neo4j.com] |
| 4 | + * This file is part of Neo4j. |
| 5 | + * Neo4j is free software: you can redistribute it and/or modify |
| 6 | + * it under the terms of the GNU General Public License as published by |
| 7 | + * the Free Software Foundation, either version 3 of the License, or |
| 8 | + * (at your option) any later version. |
| 9 | + * This program is distributed in the hope that it will be useful, |
| 10 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 | + * GNU General Public License for more details. |
| 13 | + * You should have received a copy of the GNU General Public License |
| 14 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 15 | + * |
| 16 | + */ |
| 17 | + |
| 18 | +import { convertUrlsToHrefTags } from './clickable-urls' |
| 19 | + |
| 20 | +describe('clickable-urls', () => { |
| 21 | + describe('convertUrlsToHrefTags', () => { |
| 22 | + test('handles most common URL formats', () => { |
| 23 | + const urls = [ |
| 24 | + 'bolt://127.0.0.1:7687', |
| 25 | + 'http://foo.com', |
| 26 | + 'http://goo.gl', |
| 27 | + 'https://foo.com', |
| 28 | + 'https://www.foo.com', |
| 29 | + 'https://www.foo.com/', |
| 30 | + 'https://www.foo.com/bar', |
| 31 | + 'http://goo.gl/1', |
| 32 | + 'http://goo.gl/2', |
| 33 | + 'http://firstround.com/review/thoughts-on-gender-and-radical-candor/?ct=t(How_Does_Your_Leadership_Team_Rate_12_3_2015)', |
| 34 | + 'https://google.com', |
| 35 | + 'http://www.cool.com.au', |
| 36 | + 'http://www.cool.com.au/ersdfs', |
| 37 | + 'http://www.cool.com.au/ersdfs?dfd=dfgd@s=1', |
| 38 | + 'http://www.cool.com:81/index.html' |
| 39 | + ] |
| 40 | + const expected = urls.map( |
| 41 | + url => `<a href="${url}" target="_blank">${url}</a>` |
| 42 | + ) |
| 43 | + |
| 44 | + expect(urls.map(convertUrlsToHrefTags)).toEqual(expected) |
| 45 | + }) |
| 46 | + |
| 47 | + test('does not catch invalid or missing protocol urls', () => { |
| 48 | + expect(convertUrlsToHrefTags('https:google.com')).toBe('https:google.com') |
| 49 | + expect(convertUrlsToHrefTags('google.com')).toBe('google.com') |
| 50 | + }) |
| 51 | + |
| 52 | + test('handles urls inside parentheses', () => { |
| 53 | + expect(convertUrlsToHrefTags('(http://goo.gl/1)')).toBe( |
| 54 | + '(<a href="http://goo.gl/1" target="_blank">http://goo.gl/1</a>)' |
| 55 | + ) |
| 56 | + }) |
| 57 | + |
| 58 | + test('does not include puncuation, comma, exclamation', () => { |
| 59 | + expect(convertUrlsToHrefTags('http://foo.com/.')).toBe( |
| 60 | + '<a href="http://foo.com/" target="_blank">http://foo.com/</a>.' |
| 61 | + ) |
| 62 | + expect(convertUrlsToHrefTags('http://foo.com/!')).toBe( |
| 63 | + '<a href="http://foo.com/" target="_blank">http://foo.com/</a>!' |
| 64 | + ) |
| 65 | + expect(convertUrlsToHrefTags('http://foo.com/,')).toBe( |
| 66 | + '<a href="http://foo.com/" target="_blank">http://foo.com/</a>,' |
| 67 | + ) |
| 68 | + }) |
| 69 | + }) |
| 70 | +}) |
0 commit comments