-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
30 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,6 +11,10 @@ const description1WithoutUrl = `PRESSE / ILS EN PARLENT ! | |
« Hilarant » Vanity Fair | ||
Voir plus de critiques en suivant le lien suivant :` | ||
|
||
const descriptionWithoutSpaceAfterDot = `Lorem ipsum dolor sit amet consectetur adipiscing elit.Sed non risus.` | ||
|
||
const descriptionWitUppercaseLink = `Lorem ipsum dolor sit amet consectetur adipiscing Elit.sed non risus.` | ||
|
||
const description1 = description1WithoutUrl + 'https://fauxliencritique.com/' | ||
|
||
const description2 = `https://www.google.com/ Lorem ipsum dolor sit amet, consectetur adipiscing elit. | ||
|
@@ -37,8 +41,7 @@ describe('customFindUrlChunks', () => { | |
}) | ||
|
||
expect(highlightedChunks1).toHaveLength(1) | ||
// @ts-expect-error: because of noUncheckedIndexedAccess | ||
expect(description1.slice(0, highlightedChunks1[0].start)).toBe(description1WithoutUrl) | ||
expect(description1.slice(0, highlightedChunks1[0]?.start)).toBe(description1WithoutUrl) | ||
}) | ||
|
||
it('finds url chunks and mark them as highlited', () => { | ||
|
@@ -61,7 +64,7 @@ describe('highlightLinks', () => { | |
const parsedDescription = highlightLinks('perdu.com') | ||
|
||
expect(parsedDescription).toEqual([ | ||
<ExternalLink key="external-link-0" url="http://perdu.com" />, | ||
<ExternalLink key="external-link-0" url="perdu.com" />, | ||
]) | ||
}) | ||
|
||
|
@@ -86,31 +89,31 @@ describe('highlightLinks', () => { | |
const parsedDescription = highlightLinks('www.penofchaos.com') | ||
|
||
expect(parsedDescription).toEqual([ | ||
<ExternalLink key="external-link-0" url="http://www.penofchaos.com" />, | ||
<ExternalLink key="external-link-0" url="www.penofchaos.com" />, | ||
]) | ||
}) | ||
|
||
it('with path', () => { | ||
const parsedDescription = highlightLinks('httpstat.us/418') | ||
|
||
expect(parsedDescription).toEqual([ | ||
<ExternalLink key="external-link-0" url="http://httpstat.us/418" />, | ||
<ExternalLink key="external-link-0" url="httpstat.us/418" />, | ||
]) | ||
}) | ||
|
||
it('with query params', () => { | ||
const parsedDescription = highlightLinks('httpstat.us/200?sleep=500') | ||
|
||
expect(parsedDescription).toEqual([ | ||
<ExternalLink key="external-link-0" url="http://httpstat.us/200?sleep=500" />, | ||
<ExternalLink key="external-link-0" url="httpstat.us/200?sleep=500" />, | ||
]) | ||
}) | ||
|
||
it('with hash', () => { | ||
const parsedDescription = highlightLinks('httpstat.us#anchor') | ||
|
||
expect(parsedDescription).toEqual([ | ||
<ExternalLink key="external-link-0" url="http://httpstat.us#anchor" />, | ||
<ExternalLink key="external-link-0" url="httpstat.us#anchor" />, | ||
]) | ||
}) | ||
}) | ||
|
@@ -124,10 +127,7 @@ describe('highlightLinks', () => { | |
|
||
expect(parsedDescription).toEqual([ | ||
`${description1WithoutUrl} `, | ||
<ExternalLink | ||
key="external-link-1" | ||
url="http://www.penofchaos.com/warham/donjon.htm" | ||
/>, | ||
<ExternalLink key="external-link-1" url="www.penofchaos.com/warham/donjon.htm" />, | ||
]) | ||
}) | ||
|
||
|
@@ -145,12 +145,9 @@ describe('highlightLinks', () => { | |
const parsedDescription = highlightLinks(description) | ||
|
||
expect(parsedDescription).toEqual([ | ||
<ExternalLink | ||
key="external-link-0" | ||
url="http://www.penofchaos.com/warham/donjon.htm" | ||
/>, | ||
<ExternalLink key="external-link-0" url="www.penofchaos.com/warham/donjon.htm" />, | ||
'\n', | ||
<ExternalLink key="external-link-2" url="http://perdu.com" />, | ||
<ExternalLink key="external-link-2" url="perdu.com" />, | ||
]) | ||
}) | ||
}) | ||
|
@@ -177,7 +174,7 @@ describe('highlightLinks', () => { | |
) | ||
|
||
expect(parsedDescription).toEqual([ | ||
<ExternalLink key="external-link-0" url="http://www.penofchaos.com/warham/donjon.htm" />, | ||
<ExternalLink key="external-link-0" url="www.penofchaos.com/warham/donjon.htm" />, | ||
` ${description1WithoutUrl}`, | ||
]) | ||
}) | ||
|
@@ -188,5 +185,17 @@ describe('highlightLinks', () => { | |
|
||
expect(parsedDescription).toEqual(['[email protected]']) | ||
}) | ||
|
||
it('exclude uppercase after dot', () => { | ||
const parsedDescription = highlightLinks(descriptionWithoutSpaceAfterDot) | ||
|
||
expect(parsedDescription).toEqual([descriptionWithoutSpaceAfterDot]) | ||
}) | ||
|
||
it('exclude uppercase at link start', () => { | ||
const parsedDescription = highlightLinks(descriptionWitUppercaseLink) | ||
|
||
expect(parsedDescription).toEqual([descriptionWitUppercaseLink]) | ||
}) | ||
}) | ||
}) |