@@ -174,6 +174,163 @@ describe("test String with URL", () => {
174174 expect ( openLink ) . toBeCalledWith ( url2 ) ;
175175 } ) ;
176176
177+ it ( "renders multiple URLs with various spacing" , ( ) => {
178+ const url1 = "http://example.com" ;
179+ const url2 = "https://example.com/foo" ;
180+ const string = ` ${ url1 } ${ url2 } ${ url2 } ${ url1 } ` ;
181+ const element = renderRep ( string , { useQuotes : false } ) ;
182+ expect ( element . text ( ) ) . toEqual ( string ) ;
183+ const links = element . find ( "a" ) ;
184+ expect ( links . length ) . toBe ( 4 ) ;
185+ } ) ;
186+
187+ it ( "renders a cropped URL" , ( ) => {
188+ const url = "http://example.com" ;
189+ const openLink = jest . fn ( ) ;
190+ const element = renderRep ( url , {
191+ openLink,
192+ useQuotes : false ,
193+ cropLimit : 15
194+ } ) ;
195+
196+ expect ( element . text ( ) ) . toEqual ( "http://…ple.com" ) ;
197+ const link = element . find ( "a" ) ;
198+ expect ( link . prop ( "href" ) ) . toBe ( url ) ;
199+ expect ( link . prop ( "title" ) ) . toBe ( url ) ;
200+
201+ link . simulate ( "click" ) ;
202+ expect ( openLink ) . toBeCalledWith ( url ) ;
203+ } ) ;
204+
205+ it ( "renders URLs with a stripped string between" , ( ) => {
206+ const text = "- http://example.fr --- http://example.us -" ;
207+ const openLink = jest . fn ( ) ;
208+ const element = renderRep ( text , {
209+ openLink,
210+ useQuotes : false ,
211+ cropLimit : 41
212+ } ) ;
213+
214+ expect ( element . text ( ) ) . toEqual ( "- http://example.fr … http://example.us -" ) ;
215+ const linkFr = element . find ( "a" ) . at ( 0 ) ;
216+ expect ( linkFr . prop ( "href" ) ) . toBe ( "http://example.fr" ) ;
217+ expect ( linkFr . prop ( "title" ) ) . toBe ( "http://example.fr" ) ;
218+
219+ const linkUs = element . find ( "a" ) . at ( 1 ) ;
220+ expect ( linkUs . prop ( "href" ) ) . toBe ( "http://example.us" ) ;
221+ expect ( linkUs . prop ( "title" ) ) . toBe ( "http://example.us" ) ;
222+ } ) ;
223+
224+ it ( "renders URLs with a cropped string between" , ( ) => {
225+ const text = "- http://example.fr ---- http://example.us -" ;
226+ const openLink = jest . fn ( ) ;
227+ const element = renderRep ( text , {
228+ openLink,
229+ useQuotes : false ,
230+ cropLimit : 42
231+ } ) ;
232+
233+ expect ( element . text ( ) ) . toEqual ( "- http://example.fr -…- http://example.us -" ) ;
234+ const linkFr = element . find ( "a" ) . at ( 0 ) ;
235+ expect ( linkFr . prop ( "href" ) ) . toBe ( "http://example.fr" ) ;
236+ expect ( linkFr . prop ( "title" ) ) . toBe ( "http://example.fr" ) ;
237+
238+ const linkUs = element . find ( "a" ) . at ( 1 ) ;
239+ expect ( linkUs . prop ( "href" ) ) . toBe ( "http://example.us" ) ;
240+ expect ( linkUs . prop ( "title" ) ) . toBe ( "http://example.us" ) ;
241+ } ) ;
242+
243+ it ( "renders successive cropped URLs, one at the start, one at the end" , ( ) => {
244+ const text = "- http://example-long.fr http://example.us -" ;
245+ const openLink = jest . fn ( ) ;
246+ const element = renderRep ( text , {
247+ openLink,
248+ useQuotes : false ,
249+ cropLimit : 20
250+ } ) ;
251+
252+ expect ( element . text ( ) ) . toEqual ( "- http://e…ample.us -" ) ;
253+ const linkFr = element . find ( "a" ) . at ( 0 ) ;
254+ expect ( linkFr . prop ( "href" ) ) . toBe ( "http://example-long.fr" ) ;
255+ expect ( linkFr . prop ( "title" ) ) . toBe ( "http://example-long.fr" ) ;
256+
257+ const linkUs = element . find ( "a" ) . at ( 1 ) ;
258+ expect ( linkUs . prop ( "href" ) ) . toBe ( "http://example.us" ) ;
259+ expect ( linkUs . prop ( "title" ) ) . toBe ( "http://example.us" ) ;
260+ } ) ;
261+
262+ it ( "renders successive URLs, one cropped in the middle" , ( ) => {
263+ const text = "- http://example-long.fr http://example.com http://example.us -" ;
264+ const openLink = jest . fn ( ) ;
265+ const element = renderRep ( text , {
266+ openLink,
267+ useQuotes : false ,
268+ cropLimit : 60
269+ } ) ;
270+
271+ expect ( element . text ( ) ) . toEqual ( "- http://example-long.fr http:…xample.com http://example.us -" ) ;
272+ const linkFr = element . find ( "a" ) . at ( 0 ) ;
273+ expect ( linkFr . prop ( "href" ) ) . toBe ( "http://example-long.fr" ) ;
274+ expect ( linkFr . prop ( "title" ) ) . toBe ( "http://example-long.fr" ) ;
275+
276+ const linkCom = element . find ( "a" ) . at ( 1 ) ;
277+ expect ( linkCom . prop ( "href" ) ) . toBe ( "http://example.com" ) ;
278+ expect ( linkCom . prop ( "title" ) ) . toBe ( "http://example.com" ) ;
279+
280+ const linkUs = element . find ( "a" ) . at ( 2 ) ;
281+ expect ( linkUs . prop ( "href" ) ) . toBe ( "http://example.us" ) ;
282+ expect ( linkUs . prop ( "title" ) ) . toBe ( "http://example.us" ) ;
283+ } ) ;
284+
285+ it ( "renders successive cropped URLs with cropped elements between" , ( ) => {
286+ const text = "- http://example.fr test http://example.fr test http://example.us -" ;
287+ const openLink = jest . fn ( ) ;
288+ const element = renderRep ( text , {
289+ openLink,
290+ useQuotes : false ,
291+ cropLimit : 20
292+ } ) ;
293+
294+ expect ( element . text ( ) ) . toEqual ( "- http://e…ample.us -" ) ;
295+ const linkFr = element . find ( "a" ) . at ( 0 ) ;
296+ expect ( linkFr . prop ( "href" ) ) . toBe ( "http://example.fr" ) ;
297+ expect ( linkFr . prop ( "title" ) ) . toBe ( "http://example.fr" ) ;
298+
299+ const linkUs = element . find ( "a" ) . at ( 1 ) ;
300+ expect ( linkUs . prop ( "href" ) ) . toBe ( "http://example.us" ) ;
301+ expect ( linkUs . prop ( "title" ) ) . toBe ( "http://example.us" ) ;
302+ } ) ;
303+
304+ it ( "renders a cropped URL followed by a cropped string" , ( ) => {
305+ const text = "http://example.fr abcdefghijkl" ;
306+ const openLink = jest . fn ( ) ;
307+ const element = renderRep ( text , {
308+ openLink,
309+ useQuotes : false ,
310+ cropLimit : 20
311+ } ) ;
312+
313+ expect ( element . text ( ) ) . toEqual ( "http://exa…cdefghijkl" ) ;
314+ const linkFr = element . find ( "a" ) . at ( 0 ) ;
315+ expect ( linkFr . prop ( "href" ) ) . toBe ( "http://example.fr" ) ;
316+ expect ( linkFr . prop ( "title" ) ) . toBe ( "http://example.fr" ) ;
317+ } ) ;
318+
319+ it ( "renders a cropped string followed by a cropped URL" , ( ) => {
320+ const text = "abcdefghijkl stripped http://example.fr " ;
321+ const openLink = jest . fn ( ) ;
322+ const element = renderRep ( text , {
323+ openLink,
324+ useQuotes : false ,
325+ cropLimit : 20
326+ } ) ;
327+
328+ expect ( element . text ( ) ) . toEqual ( "abcdefghij…xample.fr " ) ;
329+ const linkFr = element . find ( "a" ) . at ( 0 ) ;
330+ expect ( linkFr . prop ( "href" ) ) . toBe ( "http://example.fr" ) ;
331+ expect ( linkFr . prop ( "title" ) ) . toBe ( "http://example.fr" ) ;
332+ } ) ;
333+
177334 it ( "does not render a link if the URL has no scheme" , ( ) => {
178335 const url = "example.com" ;
179336 const element = renderRep ( url , { useQuotes : false } ) ;
0 commit comments