From 9f2dd8c933b1ae03961281f32619d6a53b896acd Mon Sep 17 00:00:00 2001 From: Eldar Iusupzhanov Date: Sun, 14 Apr 2024 17:27:01 +0800 Subject: [PATCH] add tests --- lib/__tests__/__snapshots__/text.tsx.snap | 61 +++++++++++++++++++---- lib/__tests__/text.tsx | 22 ++++++++ 2 files changed, 74 insertions(+), 9 deletions(-) diff --git a/lib/__tests__/__snapshots__/text.tsx.snap b/lib/__tests__/__snapshots__/text.tsx.snap index 1a5181c8..133fe4b6 100644 --- a/lib/__tests__/__snapshots__/text.tsx.snap +++ b/lib/__tests__/__snapshots__/text.tsx.snap @@ -9,7 +9,6 @@ Array [ > http://google.com , - "", ], Please go to @@ -18,7 +17,6 @@ Array [ > http://google.com - , ] `; @@ -27,13 +25,11 @@ exports[`text linkify attach link on nested elements containing links 1`] = ` Please go to - http://google.com - lalala @@ -47,7 +43,6 @@ exports[`text linkify attach link on simple elements containing links 1`] = ` > http://google.com - `; @@ -59,7 +54,6 @@ Array [ > http://google.com , - "", ] `; @@ -71,7 +65,6 @@ Array [ > http://www.rumtoast.com/5444/line群組行動條碼邀請-一定要關掉,不然駭客會入侵 , - "", ] `; @@ -90,7 +83,58 @@ Array [ 駭客會入侵 , - "", +] +`; + +exports[`text linkify parses half-width brackets correctly 1`] = ` +Array [ + + http://foo.com/blah_(a)_(b) + , + " (", + + http://foo.com/blah_(a)_(b) + , + ") ", + + http://foo.com/blah_(a)_(b) + , + ")", +] +`; + +exports[`text linkify parses full-width brackets correctly 1`] = ` +Array [ + + http://foo.com/blah_(a)_(b) + , + " (", + + http://foo.com/blah_(a)_(b) + , + ") ", + + http://foo.com/blah_(a)_(b) + , + ")", ] `; @@ -103,7 +147,6 @@ Array [ > http://google.com , - "", ] `; diff --git a/lib/__tests__/text.tsx b/lib/__tests__/text.tsx index 66bb69c6..ff906d94 100644 --- a/lib/__tests__/text.tsx +++ b/lib/__tests__/text.tsx @@ -73,6 +73,28 @@ describe('text', () => { }) ).toMatchSnapshot(); }); + + it('parses half-width brackets correctly', () => { + expect( + linkify( + 'http://foo.com/blah_(a)_(b) (http://foo.com/blah_(a)_(b)) http://foo.com/blah_(a)_(b))', + { + props: { target: '_blank' }, + } + ) + ).toMatchSnapshot(); + }); + + it('parses full-width brackets correctly', () => { + expect( + linkify( + 'http://foo.com/blah_(a)_(b) (http://foo.com/blah_(a)_(b)) http://foo.com/blah_(a)_(b))', + { + props: { target: '_blank' }, + } + ) + ).toMatchSnapshot(); + }); }); describe('nl2br', () => {