@@ -38,7 +38,7 @@ describe('react-router-component (on server)', function() {
38
38
} ) ,
39
39
React . createElement ( Location , {
40
40
path : / \/ z \/ ( .* ) \/ ( .* ) / ,
41
- matchKeys : [ 'match1' , 'match2' ] ,
41
+ urlPatternOptions : [ 'match1' , 'match2' ] ,
42
42
handler : React . createClass ( {
43
43
render : function ( ) {
44
44
return React . createElement ( 'div' , null , this . props . match1 + this . props . match2 ) ;
@@ -71,7 +71,7 @@ describe('react-router-component (on server)', function() {
71
71
assert ( markup . match ( / o h h a i / ) ) ;
72
72
} ) ;
73
73
74
- it ( 'renders with regex and matchKeys' , function ( ) {
74
+ it ( 'renders with regex and urlPatternOptions( matchKeys) ' , function ( ) {
75
75
var markup = ReactDOMServer . renderToString ( React . createElement ( App , { path : '/z/one/two' } ) ) ;
76
76
assert ( markup . match ( / c l a s s = " A p p " / ) ) ;
77
77
assert ( markup . match ( / o n e t w o / ) ) ;
@@ -318,4 +318,106 @@ describe('react-router-component (on server)', function() {
318
318
} ) ;
319
319
} ) ;
320
320
321
+ describe ( 'urlPatternOptions hierarchy' , function ( ) {
322
+ var Inner = React . createClass ( {
323
+ displayName : 'Inner' ,
324
+
325
+ render : function ( ) {
326
+ return React . createElement ( 'div' , { } , this . props . foo + '|' + this . props . bar + this . props . _ ) ;
327
+ }
328
+ } ) ;
329
+
330
+ var App = React . createClass ( {
331
+
332
+ getRoutes : function ( ) {
333
+ return [
334
+ // Direct passthrough from Locations
335
+ React . createElement ( Location , {
336
+ path : '/1/$foo/$bar' ,
337
+ handler : Inner
338
+ } ) ,
339
+ // Merge one property
340
+ React . createElement ( Location , {
341
+ path : '/2/$foo/$bar' ,
342
+ handler : Inner ,
343
+ urlPatternOptions : {
344
+ segmentValueCharset : 'A-Z'
345
+ }
346
+ } ) ,
347
+ // Override a property
348
+ React . createElement ( Location , {
349
+ path : '/3/!foo/!bar' ,
350
+ handler : Inner ,
351
+ urlPatternOptions : {
352
+ segmentNameStartChar : '!'
353
+ }
354
+ } ) ,
355
+ // Inherit from parent contextual
356
+ React . createElement ( Location , {
357
+ path : '/4/[foo]?' ,
358
+ handler : Inner ,
359
+ urlPatternOptions : {
360
+ optionalSegmentStartChar : '[' ,
361
+ optionalSegmentEndChar : ']'
362
+ }
363
+ } ) ,
364
+ // Parent props
365
+ React . createElement ( NotFound , {
366
+ handler : React . createElement ( 'div' , null , 'not found' )
367
+ } )
368
+ ]
369
+ } ,
370
+
371
+ render : function ( ) {
372
+ return React . createElement ( 'div' , { className : 'App' } ,
373
+ React . createElement ( Locations , {
374
+ path : this . props . path ,
375
+ urlPatternOptions : {
376
+ wildcardChar : '?'
377
+ }
378
+ } ,
379
+ React . createElement ( Location , {
380
+ path : '/start?' ,
381
+ handler : React . createElement ( 'div' , null ,
382
+ React . createElement ( Locations , {
383
+ contextual : true ,
384
+ children : this . getRoutes ( ) ,
385
+ urlPatternOptions : {
386
+ segmentNameStartChar : '$'
387
+ }
388
+ } )
389
+ )
390
+ } ) ,
391
+ React . createElement ( NotFound , {
392
+ handler : React . createElement ( 'div' , null , 'not found' )
393
+ } )
394
+ )
395
+ ) ;
396
+ }
397
+ } ) ;
398
+
399
+
400
+ it ( 'passes urlPatternOptions from parent <Locations>' , function ( ) {
401
+ var markup = ReactDOMServer . renderToString ( React . createElement ( App , { path : '/start/1/biff/baz' } ) ) ;
402
+ assert ( markup . match ( / b i f f \| b a z / ) ) ;
403
+ } ) ;
404
+
405
+ it ( 'merges urlPatternOptions from parent <Locations> and a <Location>' , function ( ) {
406
+ var markup = ReactDOMServer . renderToString ( React . createElement ( App , { path : '/start/2/BIFF/BA' } ) ) ;
407
+ assert ( markup . match ( / B I F F \| B A / ) ) ;
408
+ markup = ReactDOMServer . renderToString ( React . createElement ( App , { path : '/start/2/biff/ba' } ) ) ;
409
+ assert ( markup . match ( / n o t f o u n d / ) ) ;
410
+ } ) ;
411
+
412
+ it ( 'gives urlPatternOptions on route precedence over router' , function ( ) {
413
+ var markup = ReactDOMServer . renderToString ( React . createElement ( App , { path : '/start/3/biff/boff' } ) ) ;
414
+ assert ( markup . match ( / b i f f \| b o f f / ) ) ;
415
+ } ) ;
416
+
417
+ it ( 'inherits from parent contextual router' , function ( ) {
418
+ var markup = ReactDOMServer . renderToString ( React . createElement ( App , { path : '/start/4/foobar' } ) ) ;
419
+ assert ( markup . match ( / u n d e f i n e d \| u n d e f i n e d b a r / ) ) ;
420
+ } ) ;
421
+ } ) ;
422
+
321
423
} ) ;
0 commit comments