var require = patchRequire( require ), spaceghost = require( 'spaceghost' ).fromCasper( casper ), xpath = require( 'casper' ).selectXPath, utils = require( 'utils' ), format = utils.format; spaceghost.test.begin( 'Test the tools API', 0, function suite( test ){ spaceghost.start(); // =================================================================== SET UP var email = spaceghost.user.getRandomEmail(), password = '123456'; if( spaceghost.fixtureData.testUser ){ email = spaceghost.fixtureData.testUser.email; password = spaceghost.fixtureData.testUser.password; } spaceghost.user.loginOrRegisterUser( email, password ); function compareObjs( obj1, where ){ for( var key in where ){ if( where.hasOwnProperty( key ) ){ if( !obj1.hasOwnProperty( key ) ){ return false; } if( obj1[ key ] !== where[ key ] ){ return false; } } } return true; } function findObject( objectArray, where, start ){ start = start || 0; for( var i=start; i= 1, 'Has at least one tool section' ); this.test.comment( 'index panel form should be separated into sections (by default)' ); var firstSection = toolIndex[0]; // get data //this.debug( this.jsonStr( firstSection ) ); this.test.assert( this.hasKeys( firstSection, panelSectionKeys ), 'Has the proper keys' ); //TODO: test form of indiv. keys this.test.comment( 'index sections have a list of tool "elems"' ); this.test.assert( utils.isArray( firstSection.elems ), firstSection.name + ".elems is an array: " + "length " + firstSection.elems.length ); this.test.assert( firstSection.elems.length >= 1, 'Has at least one tool' ); var firstTool = firstSection.elems[0]; // get data //this.debug( this.jsonStr( firstTool ) ); this.test.assert( this.hasKeys( firstTool, panelToolKeys ), 'Has the proper keys' ); // ........................................................................................... in_panel=False this.test.comment( 'index should get a list of all tools when in_panel=false' ); toolIndex = this.api.tools.index( false ); //this.debug( this.jsonStr( toolIndex ) ); this.test.assert( utils.isArray( toolIndex ), "index returned an array: length " + toolIndex.length ); this.test.assert( toolIndex.length >= 1, 'Has at least one tool' ); this.test.comment( 'index non-panel form should be a simple list of tool summaries' ); firstSection = toolIndex[0]; //this.debug( this.jsonStr( firstSection ) ); this.test.assert( this.hasKeys( firstSection, toolSummaryKeys ), 'Has the proper keys' ); //TODO: test uniqueness of ids //TODO: test form of indiv. keys // ........................................................................................... trackster=True this.test.comment( '(like in_panel=True) index with trackster=True should ' + 'get a (smaller) list of tools in panel form (by default)' ); toolIndex = this.api.tools.index( undefined, true ); //this.debug( this.jsonStr( toolIndex ) ); this.test.assert( utils.isArray( toolIndex ), "index returned an array: length " + toolIndex.length ); this.test.assert( toolIndex.length >= 1, 'Has at least one tool section' ); this.test.comment( 'index with trackster=True should be separated into sections (by default)' ); firstSection = toolIndex[0]; // get data //this.debug( this.jsonStr( firstSection ) ); this.test.assert( this.hasKeys( firstSection, panelSectionKeys ), 'Has the proper keys' ); //TODO: test form of indiv. keys this.test.comment( 'index sections with trackster=True have a list of tool "elems"' ); this.test.assert( utils.isArray( firstSection.elems ), firstSection.name + ".elems is an array: " + "length " + firstSection.elems.length ); this.test.assert( firstSection.elems.length >= 1, 'Has at least one tool' ); firstTool = firstSection.elems[0]; // get data //this.debug( this.jsonStr( firstTool ) ); this.test.assert( this.hasKeys( firstTool, panelToolKeys ), 'Has the proper keys' ); // ............................................................................ trackster=True, in_panel=False // this yields the same as in_panel=False... // ------------------------------------------------------------------------------------------- SHOW this.test.comment( 'show should get detailed data about the tool with the given id' ); // get the tool select first from tool index toolIndex = this.api.tools.index(); var selectFirst = findObject( findObject( toolIndex, { id: 'textutil' }).elems, { id: 'Show beginning1' }); //this.debug( this.jsonStr( selectFirst ) ); var toolShow = this.api.tools.show( selectFirst.id ); //this.debug( this.jsonStr( toolShow ) ); this.test.assert( utils.isObject( toolShow ), "show returned an object" ); this.test.assert( this.hasKeys( toolShow, toolDetailKeys ), 'Has the proper keys' ); this.test.comment( 'show data should include an array of input objects' ); this.test.assert( utils.isArray( toolShow.inputs ), "inputs is an array: " + "length " + toolShow.inputs.length ); this.test.assert( toolShow.inputs.length >= 1, 'Has at least one element' ); for( var i=0; i