const assert = require ( 'assert' ) ; const Blueprint = require ( '../dist/factorio-blueprint.min.js' ) ; const Victor = require ( 'victor' ) ; describe ( 'Blueprint Generation' , ( ) => { describe ( 'simple, small' , ( ) => { it ( 'single wall piece' , ( ) => { const bp = new Blueprint ( ) ; bp . createEntity ( 'stone_wall' , { x : 3 , y : 4 } ) ; const obj = bp . toObject ( ) ; assert . equal ( obj . blueprint . entities [ 0 ] . name , 'stone-wall' ) ; } ) ; } ) ; describe ( 'directions' , ( ) => { it ( 'supports belts going in all directions' , ( ) => { const bp = new Blueprint ( ) ; bp . createEntity ( 'express_transport_belt' , { x : 1 , y : 0 } , Blueprint . DOWN ) ; bp . createEntity ( 'express_transport_belt' , { x : 2 , y : 1 } , Blueprint . LEFT ) ; bp . createEntity ( 'express_transport_belt' , { x : 1 , y : 2 } , Blueprint . UP ) ; bp . createEntity ( 'express_transport_belt' , { x : 0 , y : 1 } , Blueprint . RIGHT ) ; const obj = bp . toObject ( ) ; assert . equal ( obj . blueprint . entities [ 0 ] . direction , 4 ) ; assert . equal ( obj . blueprint . entities [ 0 ] . name , 'express-transport-belt' ) ; assert . equal ( obj . blueprint . entities [ 1 ] . direction , 6 ) ; assert . equal ( obj . blueprint . entities [ 1 ] . name , 'express-transport-belt' ) ; assert . equal ( obj . blueprint . entities [ 2 ] . direction , 0 ) ; assert . equal ( obj . blueprint . entities [ 2 ] . name , 'express-transport-belt' ) ; assert . equal ( obj . blueprint . entities [ 3 ] . direction , 2 ) ; assert . equal ( obj . blueprint . entities [ 3 ] . name , 'express-transport-belt' ) ; } ) ; } ) ; describe ( 'recipes' , ( ) => { it ( 'supports recipes in assemblers' , ( ) => { const bp = new Blueprint ( ) ; bp . name = 'Stone Assembler3' ; const e = bp . createEntity ( 'assembling_machine_3' , { x : 0 , y : 0 } , Blueprint . DOWN ) ; e . setRecipe ( 'stone_wall' ) ; const obj = bp . toObject ( ) ; assert . equal ( obj . blueprint . entities [ 0 ] . direction , 4 ) ; assert . equal ( obj . blueprint . entities [ 0 ] . recipe , 'stone-wall' ) ; assert . equal ( obj . blueprint . entities [ 0 ] . name , 'assembling-machine-3' ) ; } ) ; } ) ; describe ( 'modules' , ( ) => { it ( 'supports modules in assemblers' , ( ) => { const bp = new Blueprint ( ) ; bp . name = 'Stone Assembler3' ; const e = bp . createEntity ( 'assembling_machine_3' , { x : 0 , y : 0 } , Blueprint . UP ) ; e . setRecipe ( 'stone_wall' ) ; e . modules [ 'speed_module_3' ] = 1 ; e . modules [ 'productivity_module_3' ] = 2 ; e . modules [ 'effectivity_module_3' ] = 1 ; const obj = bp . toObject ( ) ; assert . equal ( obj . blueprint . entities [ 0 ] . direction , 0 ) ; assert . equal ( obj . blueprint . entities [ 0 ] . recipe , 'stone-wall' ) ; assert . equal ( obj . blueprint . entities [ 0 ] . name , 'assembling-machine-3' ) ; assert . equal ( obj . blueprint . entities [ 0 ] . items [ 'productivity-module-3' ] , 2 ) ; assert . equal ( obj . blueprint . entities [ 0 ] . items [ 'effectivity-module-3' ] , 1 ) ; assert . equal ( obj . blueprint . entities [ 0 ] . items [ 'speed-module-3' ] , 1 ) ; } ) ; } ) ; describe ( 'filter inserters' , ( ) => { it ( 'stack filter inserters have only one filter' , ( ) => { const bp = new Blueprint ( ) ; bp . name = 'stack filter inserter' ; const e = bp . createEntity ( 'stack_filter_inserter' , { x : 0 , y : 0 } , Blueprint . UP ) ; e . setFilter ( 0 , 'stone_wall' ) ; const obj = bp . toObject ( ) ; assert . equal ( obj . blueprint . entities [ 0 ] . direction , 0 ) ; assert . equal ( obj . blueprint . entities [ 0 ] . name , 'stack-filter-inserter' ) ; assert . equal ( obj . blueprint . entities [ 0 ] . filters [ 0 ] . index , 1 ) ; assert . equal ( obj . blueprint . entities [ 0 ] . filters [ 0 ] . name , 'stone-wall' ) ; } ) ; it ( 'have multiple filters' , ( ) => { const bp = new Blueprint ( ) ; bp . name = 'filter inserter' ; const e = bp . createEntity ( 'filter_inserter' , { x : 0 , y : 0 } , Blueprint . UP ) ; e . setFilter ( 0 , 'stone_wall' ) ; e . setFilter ( 4 , 'iron_plate' ) ; const obj = bp . toObject ( ) ; assert . equal ( obj . blueprint . entities [ 0 ] . direction , 0 ) ; assert . equal ( obj . blueprint . entities [ 0 ] . name , 'filter-inserter' ) ; assert . equal ( obj . blueprint . entities [ 0 ] . filters [ 0 ] . index , 1 ) ; assert . equal ( obj . blueprint . entities [ 0 ] . filters [ 0 ] . name , 'stone-wall' ) ; assert . equal ( obj . blueprint . entities [ 0 ] . filters [ 1 ] . index , 5 ) ; assert . equal ( obj . blueprint . entities [ 0 ] . filters [ 1 ] . name , 'iron-plate' ) ; } ) ; } ) ; describe ( 'inventory filters' , ( ) => { } ) ; describe ( 'logistic request filters' , ( ) => { } ) ; describe ( 'bars' , ( ) => { it ( 'has a box with no bar' , ( ) => { const bp = new Blueprint ( ) ; bp . name = 'box with bar' ; const e = bp . createEntity ( 'wooden_chest' , { x : 0 , y : 0 } , Blueprint . UP ) ; const obj = bp . toObject ( ) ; assert . equal ( obj . blueprint . entities [ 0 ] . name , 'wooden-chest' ) ; assert . equal ( 'undefined' , typeof obj . blueprint . entities [ 0 ] . bar ) ; } ) ; it ( 'has a box with some bar' , ( ) => { const bp = new Blueprint ( ) ; bp . name = 'box with bar' ; const e = bp . createEntity ( 'wooden_chest' , { x : 0 , y : 0 } , Blueprint . UP ) ; e . setBar ( 4 ) ; const obj = bp . toObject ( ) ; assert . equal ( obj . blueprint . entities [ 0 ] . name , 'wooden-chest' ) ; assert . equal ( obj . blueprint . entities [ 0 ] . bar , 4 ) ; } ) ; it ( 'fails when trying to add a bar to something that does not have an inventory' , ( ) => { const bp = new Blueprint ( ) ; bp . name = 'box with bar' ; const e = bp . createEntity ( 'stone_wall' , { x : 0 , y : 0 } , Blueprint . UP ) ; assert . throws ( ( ) => { e . setBar ( 'not a number' ) ; } , Error ) ; } ) ; it ( 'fails when trying to add a bar with a negative number' , ( ) => { const bp = new Blueprint ( ) ; bp . name = 'box with bar' ; const e = bp . createEntity ( 'wooden_chest' , { x : 0 , y : 0 } , Blueprint . UP ) ; assert . throws ( ( ) => { e . setBar ( - 9001 ) ; } , Error ) ; } ) ; } ) ; describe ( 'circuit conditions' , ( ) => { } ) ; describe ( 'connections' , ( ) => { it ( 'has two power poles connected with red wire' , ( ) => { const bp = new Blueprint ( ) ; bp . name = 'Connected Wires' ; const e1 = bp . createEntity ( 'medium_electric_pole' , { x : 0 , y : 0 } , Blueprint . UP ) ; const e2 = bp . createEntity ( 'medium_electric_pole' , { x : 0 , y : 5 } , Blueprint . UP ) ; e1 . connect ( e2 , null , null , 'red' ) ; const obj = bp . toObject ( ) ; assert . equal ( obj . blueprint . entities [ 0 ] . name , 'medium-electric-pole' ) ; assert . equal ( obj . blueprint . entities [ 0 ] . entity_number , 1 ) ; assert . equal ( obj . blueprint . entities [ 0 ] . connections [ '1' ] . red [ 0 ] . entity_id , 2 ) ; assert . equal ( obj . blueprint . entities [ 1 ] . name , 'medium-electric-pole' ) ; assert . equal ( obj . blueprint . entities [ 1 ] . entity_number , 2 ) ; assert . equal ( obj . blueprint . entities [ 1 ] . connections [ '1' ] . red [ 0 ] . entity_id , 1 ) ; } ) ; } ) ; describe ( 'splitters' , ( ) => { it ( 'correctly sets filter and priorities' , ( ) => { const bp = new Blueprint ( ) ; const ent = bp . createEntity ( 'express_splitter' , { x : 0 , y : 0 } , Blueprint . UP ) ; ent . setSplitterFilter ( 'electronic_circuit' ) ; ent . setInputPriority ( 'left' ) ; ent . setOutputPriority ( 'right' ) ; const obj = bp . toObject ( ) ; assert . equal ( obj . blueprint . entities [ 0 ] . filter , 'electronic-circuit' ) ; assert . equal ( obj . blueprint . entities [ 0 ] . input_priority , 'left' ) ; assert . equal ( obj . blueprint . entities [ 0 ] . output_priority , 'right' ) ; } ) ; } ) ; } ) ; describe ( 'Blueprint Books' , ( ) => { const bp = new Blueprint ( ) ; const bookString = Blueprint . toBook ( [ bp ] ) ; it ( 'is a string' , ( ) => { assert . equal ( typeof bookString , 'string' ) ; } ) ; it ( 'checks bp string type' , ( ) => { assert . equal ( Blueprint . isBook ( bookString ) , true ) ; assert . equal ( Blueprint . isBook ( bp . encode ( ) ) , false ) ; } ) ; it ( 'parses book' , ( ) => { assert . equal ( Blueprint . getBook ( bookString ) . length , 1 ) ; } ) ; } ) ;