Skip to content

Commit

Permalink
add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Tucchhaa committed Apr 14, 2024
1 parent 43baec8 commit 9f2dd8c
Show file tree
Hide file tree
Showing 2 changed files with 74 additions and 9 deletions.
61 changes: 52 additions & 9 deletions lib/__tests__/__snapshots__/text.tsx.snap
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ Array [
>
http://google.com
</a>,
"",
],
<span>
Please go to
Expand All @@ -18,7 +17,6 @@ Array [
>
http://google.com
</a>
</span>,
]
`;
Expand All @@ -27,13 +25,11 @@ exports[`text linkify attach link on nested elements containing links 1`] = `
<span>
Please go to
<span>
<a
href="http://google.com"
>
http://google.com
</a>
</span>
lalala
</span>
Expand All @@ -47,7 +43,6 @@ exports[`text linkify attach link on simple elements containing links 1`] = `
>
http://google.com
</a>
</span>
`;

Expand All @@ -59,7 +54,6 @@ Array [
>
http://google.com
</a>,
"",
]
`;

Expand All @@ -71,7 +65,6 @@ Array [
>
http://www.rumtoast.com/5444/line群組行動條碼邀請-一定要關掉,不然駭客會入侵
</a>,
"",
]
`;

Expand All @@ -90,7 +83,58 @@ Array [
駭客會入侵
</React.Fragment>
</a>,
"",
]
`;

exports[`text linkify parses half-width brackets correctly 1`] = `
Array [
<a
href="http://foo.com/blah_(a)_(b)"
target="_blank"
>
http://foo.com/blah_(a)_(b)
</a>,
" (",
<a
href="http://foo.com/blah_(a)_(b)"
target="_blank"
>
http://foo.com/blah_(a)_(b)
</a>,
") ",
<a
href="http://foo.com/blah_(a)_(b)"
target="_blank"
>
http://foo.com/blah_(a)_(b)
</a>,
")",
]
`;

exports[`text linkify parses full-width brackets correctly 1`] = `
Array [
<a
href="http://foo.com/blah_(a)_(b)"
target="_blank"
>
http://foo.com/blah_(a)_(b)
</a>,
" (",
<a
href="http://foo.com/blah_(a)_(b)"
target="_blank"
>
http://foo.com/blah_(a)_(b)
</a>,
") ",
<a
href="http://foo.com/blah_(a)_(b)"
target="_blank"
>
http://foo.com/blah_(a)_(b)
</a>,
")",
]
`;

Expand All @@ -103,7 +147,6 @@ Array [
>
http://google.com
</a>,
"",
]
`;

Expand Down
22 changes: 22 additions & 0 deletions lib/__tests__/text.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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', () => {
Expand Down

0 comments on commit 9f2dd8c

Please sign in to comment.