2017-03-23 12:54:29 +00:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								var  testPackage  =  require ( '../../helpers/test-package' ) ;  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								var  Dgeni  =  require ( 'dgeni' ) ;  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								describe ( 'getExampleRegion' ,  ( )  =>  {  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  var  dgeni ,  injector ,  getExampleRegion ,  collectExamples ,  exampleMap ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  beforeEach ( function ( )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    dgeni  =  new  Dgeni ( [ testPackage ( 'examples-package' ,  true ) ] ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    injector  =  dgeni . configureInjector ( ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    getExampleRegion  =  injector . get ( 'getExampleRegion' ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    collectExamples  =  injector . get ( 'collectExamples' ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    exampleMap  =  injector . get ( 'exampleMap' ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    collectExamples . exampleFolders  =  [ 'examples' ] ; 
							 
						 
					
						
							
								
									
										
										
										
											2017-09-19 10:15:39 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    collectExamples . registerIgnoredExamples ( [ 'filtered/path' ] ,  'some/gitignore' ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2017-03-23 12:54:29 +00:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								    exampleMap [ 'examples' ]  =  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								      'test/url' :  {  regions :  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        '' :  {  renderedContent :  'whole file'  } , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        'region-1' :  {  renderedContent :  'region 1 contents'  } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								      }  } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    } ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  } ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  it ( 'should contain the whole contents from the example file if no region is specified' ,  ( )  =>  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    expect ( getExampleRegion ( { } ,  'test/url' ) ) . toEqual ( 'whole file' ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  } ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  it ( 'should contain the region contents from the example file if a region is specified' ,  ( )  =>  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    expect ( getExampleRegion ( { } ,  'test/url' ,  'region-1' ) ) . toEqual ( 'region 1 contents' ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  } ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2017-07-06 12:17:57 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2017-09-19 10:15:39 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								  it ( 'should throw an error if an example doesn\'t exist' ,  ( )  =>  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    expect ( ( )  =>  { 
							 
						 
					
						
							
								
									
										
										
										
											2017-07-06 12:17:57 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								      getExampleRegion ( { } ,  'missing/file' ,  'region-1' ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2017-09-19 10:15:39 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    } ) . toThrowError ( 'Missing example file... relativePath: "missing/file". - doc\nExample files can be found in the following relative paths: "examples"' ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    expect ( ( )  =>  { 
							 
						 
					
						
							
								
									
										
										
										
											2017-07-06 12:17:57 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								      getExampleRegion ( { } ,  'test/url' ,  'missing-region' ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2017-09-19 10:15:39 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    } ) . toThrowError ( 'Missing example region... relativePath: "test/url", region: "missing-region". - doc\nRegions available are: "", "region-1"' ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  } ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  it ( 'should throw an error if an example has been filtered out' ,  ( )  =>  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    expect ( ( )  =>  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								      getExampleRegion ( { } ,  'filtered/path' ,  'any-region' ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    } ) . toThrowError ( 'Ignored example file... relativePath: "filtered/path" - doc\n'  + 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                    'This example file exists but has been ignored by a rule, in "some/gitignore".' ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2017-07-06 12:17:57 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								  } ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2017-03-23 12:54:29 +00:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								} ) ;