Skip to content

Commit be47aba

Browse files
committed
Reorganize tests relating to input HTML processing under the proper define() block.
1 parent fc1cae1 commit be47aba

File tree

1 file changed

+48
-41
lines changed

1 file changed

+48
-41
lines changed

tests/AutolinkerSpec.js

Lines changed: 48 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -153,42 +153,12 @@ describe( "Autolinker", function() {
153153
} );
154154

155155

156-
it( "should NOT automatically link URLs within HTML tags", function() {
157-
var result = Autolinker.link( '<p>Joe went to <a href="http://www.yahoo.com">yahoo</a></p>' );
158-
expect( result ).toBe( '<p>Joe went to <a href="http://www.yahoo.com">yahoo</a></p>' );
159-
} );
160-
161-
162156
it( "should automatically link URLs past the last HTML tag", function() {
163157
var result = Autolinker.link( '<p>Joe went to <a href="http://www.yahoo.com">yahoo</a></p> and http://google.com' );
164158
expect( result ).toBe( '<p>Joe went to <a href="http://www.yahoo.com">yahoo</a></p> and <a href="http://google.com" target="_blank">google.com</a>' );
165159
} );
166160

167161

168-
it( "should NOT automatically link a URL found within the inner text of a pre-existing anchor tag", function() {
169-
var result = Autolinker.link( '<p>Joe went to <a href="http://www.yahoo.com">yahoo.com</a></p> yesterday.' );
170-
expect( result ).toBe( '<p>Joe went to <a href="http://www.yahoo.com">yahoo.com</a></p> yesterday.' );
171-
} );
172-
173-
174-
it( "should NOT automatically link a URL found within the inner text of a pre-existing anchor tag, but link others", function() {
175-
var result = Autolinker.link( '<p>Joe went to google.com, <a href="http://www.yahoo.com">yahoo.com</a>, and weather.com</p> yesterday.' );
176-
expect( result ).toBe( '<p>Joe went to <a href="http://google.com" target="_blank">google.com</a>, <a href="http://www.yahoo.com">yahoo.com</a>, and <a href="http://weather.com" target="_blank">weather.com</a></p> yesterday.' );
177-
} );
178-
179-
180-
it( "should NOT automatically link an image tag with a URL inside it, inside an anchor tag", function() {
181-
var result = Autolinker.link( '<a href="http://google.com"><img src="http://google.com/someImage.jpg" /></a>' );
182-
expect( result ).toBe( '<a href="http://google.com"><img src="http://google.com/someImage.jpg" /></a>' );
183-
} );
184-
185-
186-
it( "should NOT automatically link an image tag with a URL inside it, inside an anchor tag, but match urls around the tags", function() {
187-
var result = Autolinker.link( 'google.com looks like <a href="http://google.com"><img src="http://google.com/someImage.jpg" /></a> (at google.com)' );
188-
expect( result ).toBe( '<a href="http://google.com" target="_blank">google.com</a> looks like <a href="http://google.com"><img src="http://google.com/someImage.jpg" /></a> (at <a href="http://google.com" target="_blank">google.com</a>)' );
189-
} );
190-
191-
192162
it( "should NOT automatically link URLs in the form of http://www.yahoo.com if URL support is disabled", function() {
193163
var result = Autolinker.link( "Joe went to http://www.yahoo.com", { urls: false } );
194164
expect( result ).toBe( 'Joe went to http://www.yahoo.com' );
@@ -207,51 +177,87 @@ describe( "Autolinker", function() {
207177
} );
208178

209179

210-
describe( "proper HTML handling", function() {
180+
describe( "proper input HTML handling", function() {
181+
var autolinker;
182+
183+
beforeEach( function() {
184+
autolinker = new Autolinker( { newWindow: false } ); // just to stop the target="_blank" from coming into the autolinked results
185+
} );
186+
187+
188+
it( "should NOT automatically link URLs within existing HTML tags", function() {
189+
var result = autolinker.link( '<p>Joe went to <a href="http://www.yahoo.com">yahoo</a></p>' );
190+
expect( result ).toBe( '<p>Joe went to <a href="http://www.yahoo.com">yahoo</a></p>' );
191+
} );
192+
193+
194+
it( "should NOT automatically link a URL found within the inner text of a pre-existing anchor tag", function() {
195+
var result = autolinker.link( '<p>Joe went to <a href="http://www.yahoo.com">yahoo.com</a></p> yesterday.' );
196+
expect( result ).toBe( '<p>Joe went to <a href="http://www.yahoo.com">yahoo.com</a></p> yesterday.' );
197+
} );
198+
199+
200+
it( "should NOT automatically link a URL found within the inner text of a pre-existing anchor tag, but link others", function() {
201+
var result = autolinker.link( '<p>Joe went to google.com, <a href="http://www.yahoo.com">yahoo.com</a>, and weather.com</p> yesterday.' );
202+
expect( result ).toBe( '<p>Joe went to <a href="http://google.com">google.com</a>, <a href="http://www.yahoo.com">yahoo.com</a>, and <a href="http://weather.com">weather.com</a></p> yesterday.' );
203+
} );
204+
205+
206+
it( "should NOT automatically link an image tag with a URL inside it, inside an anchor tag", function() {
207+
var result = autolinker.link( '<a href="http://google.com"><img src="http://google.com/someImage.jpg" /></a>' );
208+
expect( result ).toBe( '<a href="http://google.com"><img src="http://google.com/someImage.jpg" /></a>' );
209+
} );
210+
211+
212+
it( "should NOT automatically link an image tag with a URL inside it, inside an anchor tag, but match urls around the tags", function() {
213+
var result = autolinker.link( 'google.com looks like <a href="http://google.com"><img src="http://google.com/someImage.jpg" /></a> (at google.com)' );
214+
expect( result ).toBe( '<a href="http://google.com">google.com</a> looks like <a href="http://google.com"><img src="http://google.com/someImage.jpg" /></a> (at <a href="http://google.com">google.com</a>)' );
215+
} );
216+
211217

212218
it( "should allow the full range of HTML attribute name characters as specified in the W3C HTML syntax document (http://www.w3.org/TR/html-markup/syntax.html)", function() {
213219
// Note: We aren't actually expecting the HTML to be modified by this test
214-
var inAndOutHtml = '<ns:p>Foo <a data-qux-="" href="http://www.example.com" target="_blank">Bar<\/a> Baz<\/ns:p>';
215-
expect( Autolinker.link( inAndOutHtml ) ).toBe( inAndOutHtml );
220+
var inAndOutHtml = '<ns:p>Foo <a data-qux-="" href="http://www.example.com">Bar<\/a> Baz<\/ns:p>';
221+
expect( autolinker.link( inAndOutHtml ) ).toBe( inAndOutHtml );
216222
} );
217223

218224

219225
it( "should properly autolink text within namespaced HTML elements, skipping over html elements with urls in attribute values", function() {
220226
var html = '<ns:p>Go to google.com or <a data-qux-="test" href="http://www.example.com" target="_blank">Bar<\/a> Baz<\/ns:p>';
221227

222-
var result = Autolinker.link( html, { newWindow: false } ); // newWindow: false just to remove target="_blank" from the generated anchor
228+
var result = autolinker.link( html );
223229
expect( result ).toBe( '<ns:p>Go to <a href="http://google.com">google.com</a> or <a data-qux-="test" href="http://www.example.com" target="_blank">Bar<\/a> Baz<\/ns:p>' );
224230
} );
225231

226232

227233
it( "should properly skip over attribute names that could be interpreted as urls, while still autolinking urls in their inner text", function() {
228234
var html = '<div google.com anotherAttr yahoo.com>My div that has an attribute of google.com</div>';
229235

230-
var result = Autolinker.link( html, { newWindow: false } );
236+
var result = autolinker.link( html );
231237
expect( result ).toBe( '<div google.com anotherAttr yahoo.com>My div that has an attribute of <a href="http://google.com">google.com</a></div>' );
232238
} );
233239

234240

235241
it( "should properly skip over attribute names that could be interpreted as urls when they have a value, while still autolinking urls in their inner text", function() {
236242
var html = '<div google.com="yes" anotherAttr=true yahoo.com="true">My div that has an attribute of google.com</div>';
237243

238-
var result = Autolinker.link( html, { newWindow: false } );
244+
var result = autolinker.link( html );
239245
expect( result ).toBe( '<div google.com="yes" anotherAttr=true yahoo.com="true">My div that has an attribute of <a href="http://google.com">google.com</a></div>' );
240246
} );
241247

242248

243249
it( "should properly skip over attribute names that could be interpreted as urls when they have a value and any number of spaces between attrs, while still autolinking urls in their inner text", function() {
244250
var html = '<div google.com="yes" \t\t anotherAttr=true yahoo.com="true" \t>My div that has an attribute of google.com</div>';
245251

246-
var result = Autolinker.link( html, { newWindow: false } );
252+
var result = autolinker.link( html );
247253
expect( result ).toBe( '<div google.com="yes" \t\t anotherAttr=true yahoo.com="true" \t>My div that has an attribute of <a href="http://google.com">google.com</a></div>' );
248254
} );
249255

250256

251257
it( "should properly skip over attribute values that could be interpreted as urls/emails/twitter accts, while still autolinking urls in their inner text", function() {
252258
var html = '<div url="google.com" email="asdf@asdf.com" twitter="@asdf">google.com asdf@asdf.com @asdf</div>';
253259

254-
var result = Autolinker.link( html, { newWindow: false } );
260+
var result = autolinker.link( html );
255261
expect( result ).toBe( [
256262
'<div url="google.com" email="asdf@asdf.com" twitter="@asdf">',
257263
'<a href="http://google.com">google.com</a> ',
@@ -265,7 +271,7 @@ describe( "Autolinker", function() {
265271
it( "should properly skip over attribute names and values that could be interpreted as urls/emails/twitter accts, while still autolinking urls in their inner text", function() {
266272
var html = '<div google.com="google.com" asdf@asdf.com="asdf@asdf.com" @asdf="@asdf">google.com asdf@asdf.com @asdf</div>';
267273

268-
var result = Autolinker.link( html, { newWindow: false } );
274+
var result = autolinker.link( html );
269275
expect( result ).toBe( [
270276
'<div google.com="google.com" asdf@asdf.com="asdf@asdf.com" @asdf="@asdf">',
271277
'<a href="http://google.com">google.com</a> ',
@@ -279,7 +285,7 @@ describe( "Autolinker", function() {
279285
it( "should attempt to handle some invalid HTML markup relating to <a> tags, esp if there are extraneous closing </a> tags", function() {
280286
var html = '</a><a href="http://google.com">google.com</a>';
281287

282-
var result = Autolinker.link( html, { newWindow: false } );
288+
var result = autolinker.link( html );
283289
expect( result ).toBe( html );
284290
} );
285291

@@ -296,7 +302,7 @@ describe( "Autolinker", function() {
296302
'twitter.com'
297303
].join( "" );
298304

299-
var result = Autolinker.link( html, { newWindow: false } );
305+
var result = autolinker.link( html );
300306
expect( result ).toBe( [
301307
'</a>', // invalid - left alone
302308
'<a href="http://google.com">google.com</a>', // valid tag - left alone
@@ -311,6 +317,7 @@ describe( "Autolinker", function() {
311317

312318
} );
313319

320+
314321
describe( "parenthesis handling", function() {
315322

316323
it( "should include parentheses in URLs", function() {

0 commit comments

Comments
 (0)