2017-03-25 17:07:34 -04:00
var testPackage = require ( '../../helpers/test-package' ) ;
var Dgeni = require ( 'dgeni' ) ;
describe ( 'renderExamples processor' , ( ) => {
2017-04-01 14:34:10 -04:00
var injector , processor , exampleMap , collectExamples ;
2017-03-25 17:07:34 -04:00
beforeEach ( function ( ) {
const dgeni = new Dgeni ( [ testPackage ( 'examples-package' , true ) ] ) ;
injector = dgeni . configureInjector ( ) ;
exampleMap = injector . get ( 'exampleMap' ) ;
processor = injector . get ( 'renderExamples' ) ;
collectExamples = injector . get ( 'collectExamples' ) ;
exampleMap = injector . get ( 'exampleMap' ) ;
collectExamples . exampleFolders = [ 'examples' ] ;
exampleMap [ 'examples' ] = {
'test/url' : { regions : {
'' : { renderedContent : 'whole file' } ,
'region-1' : { renderedContent : 'region 1 contents' }
} }
} ;
} ) ;
it ( 'should run before the correct processor' , ( ) => {
2017-04-01 14:34:10 -04:00
expect ( processor . $runBefore ) . toEqual ( [ 'writing-files' ] ) ;
2017-03-25 17:07:34 -04:00
} ) ;
it ( 'should run after the correct processor' , ( ) => {
expect ( processor . $runAfter ) . toEqual ( [ 'docs-rendered' ] ) ;
} ) ;
[ 'code-example' , 'code-pane' ] . forEach ( CODE _TAG =>
describe ( CODE _TAG , ( ) => {
it ( ` should ignore a < ${ CODE _TAG } > tags with no path attribute ` , ( ) => {
const docs = [
{ renderedContent : ` Some text \n < ${ CODE _TAG } >Some code</ ${ CODE _TAG } > \n < ${ CODE _TAG } class="anti-pattern" title="Bad Code">do not do this</ ${ CODE _TAG } > ` }
] ;
processor . $process ( docs ) ;
expect ( docs [ 0 ] . renderedContent ) . toEqual ( ` Some text \n < ${ CODE _TAG } >Some code</ ${ CODE _TAG } > \n < ${ CODE _TAG } class="anti-pattern" title="Bad Code">do not do this</ ${ CODE _TAG } > ` ) ;
} ) ;
it ( ` should replace the content of the < ${ CODE _TAG } > tag with the whole contents from an example file if a path is provided ` , ( ) => {
const docs = [
{ renderedContent : ` < ${ CODE _TAG } path="test/url">Some code</ ${ CODE _TAG } > ` }
] ;
processor . $process ( docs ) ;
expect ( docs [ 0 ] . renderedContent ) . toEqual ( ` < ${ CODE _TAG } > \n whole file \n </ ${ CODE _TAG } > ` ) ;
} ) ;
2017-03-27 11:37:44 -04:00
it ( ` should replace all instances of < ${ CODE _TAG } > tags ` , ( ) => {
const docs = [
{ renderedContent : ` < ${ CODE _TAG } path="test/url">Some code</ ${ CODE _TAG } >< ${ CODE _TAG } path="test/url" region="region-1">Other code</ ${ CODE _TAG } > ` }
] ;
processor . $process ( docs ) ;
expect ( docs [ 0 ] . renderedContent ) . toEqual ( ` < ${ CODE _TAG } > \n whole file \n </ ${ CODE _TAG } >< ${ CODE _TAG } > \n region 1 contents \n </ ${ CODE _TAG } > ` ) ;
} ) ;
2017-03-25 17:07:34 -04:00
it ( 'should contain the region contents from the example file if a region is specified' , ( ) => {
const docs = [
{ renderedContent : ` < ${ CODE _TAG } path="test/url" region="region-1">Some code</ ${ CODE _TAG } > ` }
] ;
processor . $process ( docs ) ;
expect ( docs [ 0 ] . renderedContent ) . toEqual ( ` < ${ CODE _TAG } > \n region 1 contents \n </ ${ CODE _TAG } > ` ) ;
} ) ;
it ( ` should replace the content of the < ${ CODE _TAG } > tag with the whole contents from an example file if the region is empty ` , ( ) => {
const docs = [
{ renderedContent : ` < ${ CODE _TAG } path="test/url" region="">Some code</ ${ CODE _TAG } > ` }
] ;
processor . $process ( docs ) ;
expect ( docs [ 0 ] . renderedContent ) . toEqual ( ` < ${ CODE _TAG } > \n whole file \n </ ${ CODE _TAG } > ` ) ;
} ) ;
it ( 'should remove the path and region attributes but leave the other attributes alone' , ( ) => {
const docs = [
{ renderedContent : ` < ${ CODE _TAG } class="special" path="test/url" linenums="15" region="region-1" id="some-id">Some code</ ${ CODE _TAG } > ` }
] ;
processor . $process ( docs ) ;
expect ( docs [ 0 ] . renderedContent ) . toEqual ( ` < ${ CODE _TAG } class="special" linenums="15" id="some-id"> \n region 1 contents \n </ ${ CODE _TAG } > ` ) ;
} ) ;
it ( 'should cope with spaces and double quotes inside attribute values' , ( ) => {
const docs = [
{ renderedContent : ` < ${ CODE _TAG } title='a "quoted" value' path="test/url"></ ${ CODE _TAG } > ` }
] ;
processor . $process ( docs ) ;
expect ( docs [ 0 ] . renderedContent ) . toEqual ( ` < ${ CODE _TAG } title="a "quoted" value"> \n whole file \n </ ${ CODE _TAG } > ` ) ;
} ) ;
} )
) ;
2017-04-01 14:34:10 -04:00
} ) ;