import ITransaction from '../../src/interfaces/ITransaction' ; import ISmartContract from '../../src/interfaces/ISmartContract' ; import IAssociatedTxdata from '../../src/interfaces/IAssociatedTxdata' ; import IDataFileTransaction from '../../src/interfaces/IDataFileTransaction' ; import { ITransactionViewData } from '../../src/interfaces/IAppState' ; chai . should ( ) ; interface IMessage { path : string ; transactionViewData : ITransactionViewData ; } describe ( 'Transaction page' , ( ) => { const emptyTransaction = { name : '' , parameters : [ ] , returns : { type : '' , } , tag : [ ] , } ; const transactionOne = { name : 'transactionOne' , parameters : [ { description : '' , name : 'name' , schema : { } } ] , returns : { type : '' } , tag : [ 'submit' ] } ; const transactionTwo = { name : 'transactionTwo' , parameters : [ { description : '' , name : 'size' , schema : { } } ] , returns : { type : '' } , tag : [ 'submit' ] } ; const greenContract = { name : 'greenContract' , version : '0.0.1' , channel : 'mychannel' , label : 'greenContract@0.0.1' , transactions : [ transactionOne , transactionTwo ] , namespace : 'GreenContract' , contractName : 'GreenContract' , peerNames : [ 'peer1' , 'peer2' ] } ; const mockMessage = { path : 'transaction' , transactionViewData : { gatewayName : 'myGateway' , smartContracts : [ greenContract ] , preselectedSmartContract : greenContract , preselectedTransaction : emptyTransaction , associatedTxdata : { } , } } ; const mockOutput = { transactionOutput : 'some transaction output' } ; const txdataTransactions = [ { transactionName : transactionOne . name , transactionLabel : transactionOne . name , txDataFile : '' , arguments : [ ] , transientData : { } } ] ; const associatedTxdata = { [ greenContract . name ] : { channelName : 'mychannel' , transactionDataPath : 'transactionDataPath' , transactions : txdataTransactions , } } ; beforeEach ( ( ) => { cy . visit ( 'build/index.html' ) . then ( ( window ) => { window . postMessage ( mockMessage , '*' ) ; } ) ; cy . get ( '.vscode-dark' ) . invoke ( 'attr' , 'class' , 'vscode-light' ) ; } ) ; describe ( 'Manual Input' , ( ) => { it ( 'generates appropriate arguments when a transaction is selected' , ( ) => { cy . get ( '#transaction-select' ) . contains ( 'Select the transaction name' ) ; cy . get ( '#transaction-select' ) . click ( ) ; cy . get ( '#transaction-select' ) . contains ( 'transactionOne' ) . click ( ) ; cy . get ( '#transaction-select' ) . contains ( 'transactionOne' ) ; cy . get ( '#arguments-text-area' ) . invoke ( 'val' ) . then ( ( text ) : void => { expect ( text ) . to . equal ( '{\n  "name": ""\n}' ) ; } ) ; } ) ; it ( 'replaces generated arguments when a new transaction is selected' , ( ) => { cy . get ( '#transaction-select' ) . contains ( 'Select the transaction name' ) ; cy . get ( '#transaction-select' ) . click ( ) ; cy . get ( '#transaction-select' ) . contains ( 'transactionOne' ) . click ( ) ; cy . get ( '#transaction-select' ) . contains ( 'transactionOne' ) ; cy . get ( '#arguments-text-area' ) . invoke ( 'val' ) . then ( ( text ) : void => { expect ( text ) . to . equal ( '{\n  "name": ""\n}' ) ; } ) ; cy . get ( '#transaction-select' ) . click ( ) ; cy . get ( '#transaction-select' ) . contains ( 'transactionTwo' ) . click ( ) ; cy . get ( '#transaction-select' ) . contains ( 'transactionTwo' ) ; cy . get ( '#arguments-text-area' ) . invoke ( 'val' ) . then ( ( text ) : void => { expect ( text ) . to . equal ( '{\n  "size": ""\n}' ) ; } ) ; } ) ; it ( `can submit a transaction with the user's input` , ( ) => { cy . get ( '#transaction-select' ) . contains ( 'Select the transaction name' ) ; cy . get ( '#transaction-select' ) . click ( ) ; cy . get ( '#transaction-select' ) . contains ( 'transactionOne' ) . click ( ) ; cy . get ( '#transaction-select' ) . contains ( 'transactionOne' ) ; cy . get ( '#arguments-text-area' ) . type ( '{leftarrow}{leftarrow}{leftarrow}penguin' ) ; cy . get ( '#submit-button' ) . click ( ) ; cy . window ( ) . then ( ( window ) => { window . postMessage ( mockOutput , '*' ) ; } ) ; cy . get ( '.output-body' ) . contains ( mockOutput . transactionOutput ) ; } ) ; it ( `can submit a transaction with transient data` , ( ) => { cy . get ( '#transaction-select' ) . contains ( 'Select the transaction name' ) ; cy . get ( '#transaction-select' ) . click ( ) ; cy . get ( '#transaction-select' ) . contains ( 'transactionOne' ) . click ( ) ; cy . get ( '#transaction-select' ) . contains ( 'transactionOne' ) ; cy . get ( '#arguments-text-area' ) . type ( '{leftarrow}{leftarrow}{leftarrow}penguin' ) ; cy . get ( '#transient-data-input' ) . type ( '{"some": "data"}' , { parseSpecialCharSequences : false } ) ; cy . get ( '#submit-button' ) . click ( ) ; cy . window ( ) . then ( ( window ) => { window . postMessage ( mockOutput , '*' ) ; } ) ; cy . get ( '.output-body' ) . contains ( mockOutput . transactionOutput ) ; } ) ; it ( `can submit a transaction with custom peer` , ( ) => { cy . get ( '#transaction-select' ) . contains ( 'Select the transaction name' ) ; cy . get ( '#transaction-select' ) . click ( ) ; cy . get ( '#transaction-select' ) . contains ( 'transactionOne' ) . click ( ) ; cy . get ( '#transaction-select' ) . contains ( 'transactionOne' ) ; cy . get ( '#peer-select' ) . contains ( 'Select peers' ) ; cy . get ( '#peer-select' ) . click ( ) ; cy . get ( '#peer-select' ) . contains ( 'peer1' ) . click ( ) ; cy . get ( '#peer-select' ) . contains ( 'peer1' ) ; cy . get ( '#peer-select' ) . click ( ) ; cy . get ( '#submit-button' ) . click ( ) ; cy . window ( ) . then ( ( window ) => { window . postMessage ( mockOutput , '*' ) ; } ) ; cy . get ( '.output-body' ) . contains ( mockOutput . transactionOutput ) ; } ) ; it ( `can evaluate a transaction with the user's input` , ( ) => { cy . get ( '#transaction-select' ) . contains ( 'Select the transaction name' ) ; cy . get ( '#transaction-select' ) . click ( ) ; cy . get ( '#transaction-select' ) . contains ( 'transactionTwo' ) . click ( ) ; cy . get ( '#transaction-select' ) . contains ( 'transactionTwo' ) ; cy . get ( '#arguments-text-area' ) . type ( '{leftarrow}{leftarrow}{leftarrow}big' ) ; cy . get ( '#evaluate-button' ) . click ( ) ; cy . window ( ) . then ( ( window ) => { window . postMessage ( mockOutput , '*' ) ; } ) ; cy . get ( '.output-body' ) . contains ( mockOutput . transactionOutput ) ; } ) ; it ( `can evaluate a transaction with transient data` , ( ) => { cy . get ( '#transaction-select' ) . contains ( 'Select the transaction name' ) ; cy . get ( '#transaction-select' ) . click ( ) ; cy . get ( '#transaction-select' ) . contains ( 'transactionTwo' ) . click ( ) ; cy . get ( '#transaction-select' ) . contains ( 'transactionTwo' ) ; cy . get ( '#arguments-text-area' ) . type ( '{leftarrow}{leftarrow}{leftarrow}big' ) ; cy . get ( '#transient-data-input' ) . type ( '{"some": "data"}' , { parseSpecialCharSequences : false } ) ; cy . get ( '#evaluate-button' ) . click ( ) ; cy . window ( ) . then ( ( window ) => { window . postMessage ( mockOutput , '*' ) ; } ) ; cy . get ( '.output-body' ) . contains ( mockOutput . transactionOutput ) ; } ) ; it ( `can submit a transaction with custom peer` , ( ) => { cy . get ( '#transaction-select' ) . contains ( 'Select the transaction name' ) ; cy . get ( '#transaction-select' ) . click ( ) ; cy . get ( '#transaction-select' ) . contains ( 'transactionOne' ) . click ( ) ; cy . get ( '#transaction-select' ) . contains ( 'transactionOne' ) ; cy . get ( '#peer-select' ) . contains ( 'Select peers' ) ; cy . get ( '#peer-select' ) . click ( ) ; cy . get ( '#peer-select' ) . contains ( 'peer1' ) . click ( ) ; cy . get ( '#peer-select' ) . contains ( 'peer1' ) ; cy . get ( '#peer-select' ) . click ( ) ; cy . get ( '#evaluate-button' ) . click ( ) ; cy . window ( ) . then ( ( window ) => { window . postMessage ( mockOutput , '*' ) ; } ) ; cy . get ( '.output-body' ) . contains ( mockOutput . transactionOutput ) ; } ) ; } ) ; describe ( 'Data file input' , ( ) => { beforeEach ( ( ) => { cy . get ( '[data-testid="content-switch-data"]' ) . click ( ) ; } ) ; it ( `can submit a transaction with custom peer when a data directory is associated` , ( ) => { const message = { path : mockMessage . path , transactionViewData : { ... mockMessage . transactionViewData , associatedTxdata , } } ; cy . window ( ) . then ( ( window ) => { window . postMessage ( message , '*' ) ; } ) ; cy . get ( '#transaction-data-select' ) . contains ( 'Select the transaction name' ) ; cy . get ( '#transaction-data-select' ) . click ( ) ; cy . get ( '#transaction-data-select' ) . contains ( 'transactionOne' ) . click ( ) ; cy . get ( '#transaction-data-select' ) . contains ( 'transactionOne' ) ; cy . get ( '#peer-select' ) . contains ( 'Select peers' ) ; cy . get ( '#peer-select' ) . click ( ) ; cy . get ( '#peer-select' ) . contains ( 'peer1' ) . click ( ) ; cy . get ( '#peer-select' ) . contains ( 'peer1' ) ; cy . get ( '#peer-select' ) . click ( ) ; cy . get ( '#submit-button' ) . click ( ) ; cy . window ( ) . then ( ( window ) => { window . postMessage ( mockOutput , '*' ) ; } ) ; cy . get ( '.output-body' ) . contains ( mockOutput . transactionOutput ) ; } ) ; it ( `can evaluate a transaction with custom peer when a data directory is associated` , ( ) => { const message = { path : mockMessage . path , transactionViewData : { ... mockMessage . transactionViewData , associatedTxdata , } } ; cy . window ( ) . then ( ( window ) => { window . postMessage ( message , '*' ) ; } ) ; cy . get ( '#transaction-data-select' ) . contains ( 'Select the transaction name' ) ; cy . get ( '#transaction-data-select' ) . click ( ) ; cy . get ( '#transaction-data-select' ) . contains ( 'transactionOne' ) . click ( ) ; cy . get ( '#transaction-data-select' ) . contains ( 'transactionOne' ) ; cy . get ( '#peer-select' ) . contains ( 'Select peers' ) ; cy . get ( '#peer-select' ) . click ( ) ; cy . get ( '#peer-select' ) . contains ( 'peer1' ) . click ( ) ; cy . get ( '#peer-select' ) . contains ( 'peer1' ) ; cy . get ( '#peer-select' ) . click ( ) ; cy . get ( '#evaluate-button' ) . click ( ) ; cy . window ( ) . then ( ( window ) => { window . postMessage ( mockOutput , '*' ) ; } ) ; cy . get ( '.output-body' ) . contains ( mockOutput . transactionOutput ) ; } ) ; } ) ; } ) ;