From 01bacafac83b0f814b10c3e6e53143e2a0c204f2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ken-H=C3=A5vard=20Lieng?= Date: Sat, 27 May 2017 06:47:17 +0200 Subject: [PATCH] Add linkify tests --- client/src/js/util/__tests__/util.test.js | 56 +++++++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100644 client/src/js/util/__tests__/util.test.js diff --git a/client/src/js/util/__tests__/util.test.js b/client/src/js/util/__tests__/util.test.js new file mode 100644 index 00000000..12d6c24f --- /dev/null +++ b/client/src/js/util/__tests__/util.test.js @@ -0,0 +1,56 @@ +import React from 'react'; +import linkify from '../linkify'; + +describe('linkify()', () => { + const proto = href => href.indexOf('http') !== 0 ? `http://${href}` : href; + const linkTo = href => {href}; + + it('returns the arg when no matches are found', () => [ + null, + undefined, + 10, + false, + true, + 'just some text', + '' + ].forEach(input => expect(linkify(input)).toBe(input))); + + it('linkifies text', () => Object.entries({ + 'google.com': linkTo('google.com'), + 'google.com stuff': [ + linkTo('google.com'), + ' stuff' + ], + 'cake google.com stuff': [ + 'cake ', + linkTo('google.com'), + ' stuff' + ], + 'cake google.com stuff https://google.com': [ + 'cake ', + linkTo('google.com'), + ' stuff ', + linkTo('https://google.com') + ], + 'cake google.com stuff pie https://google.com ': [ + 'cake ', + linkTo('google.com'), + ' stuff pie ', + linkTo('https://google.com'), + ' ' + ], + ' google.com': [ + ' ', + linkTo('google.com') + ], + 'google.com ': [ + linkTo('google.com'), + ' ' + ], + '/google.com?': [ + '/', + linkTo('google.com'), + '?' + ] + }).forEach(([ input, expected ]) => expect(linkify(input)).toEqual(expected))); +});