@@ -33,12 +33,13 @@ import socketIOClient from "socket.io-client";
33
33
import Header from "../../components/Headers/Header.jsx" ;
34
34
35
35
36
- import { Input , Row , Col , Affix , Descriptions , Modal , Icon , message , Popover , Upload , Progress } from 'antd' ;
36
+ import { Input , Row , Col , Affix , Descriptions , Modal , Icon , message , Popover , Upload , Progress , Menu , Dropdown } from 'antd' ;
37
37
38
38
import axios from 'axios' ;
39
39
import TestCaseEditor from './TestCaseEditor'
40
40
import TestCaseViewer from './TestCaseViewer'
41
41
import getConfig from '../../utils/getConfig'
42
+ import FileDownload from 'js-file-download'
42
43
43
44
class InputValues extends React . Component {
44
45
@@ -170,7 +171,8 @@ class OutboundRequest extends React.Component {
170
171
showTestCaseIndex : null ,
171
172
renameTestCase : false ,
172
173
totalPassedCount : 0 ,
173
- totalAssertionsCount : 0
174
+ totalAssertionsCount : 0 ,
175
+ testReport : null
174
176
} ;
175
177
}
176
178
@@ -221,6 +223,7 @@ class OutboundRequest extends React.Component {
221
223
handleIncomingProgress = ( progress ) => {
222
224
if ( progress . status === 'FINISHED' ) {
223
225
message . success ( { content : 'Test case finished' , key : 'outboundSendProgress' , duration : 2 } ) ;
226
+ this . setState ( { testReport : progress . totalResult } )
224
227
} else {
225
228
let testCase = this . state . template . test_cases . find ( item => item . id === progress . testCaseId )
226
229
let request = testCase . requests . find ( item => item . id === progress . requestId )
@@ -267,13 +270,15 @@ class OutboundRequest extends React.Component {
267
270
// Initialize counts to zero
268
271
this . state . totalPassedCount = 0
269
272
this . state . totalAssertionsCount = 0
273
+ this . state . testReport = null
274
+
270
275
271
276
const outboundRequestID = Math . random ( ) . toString ( 36 ) . substring ( 7 ) ;
272
277
message . loading ( { content : 'Sending the outbound request...' , key : 'outboundSendProgress' } ) ;
273
278
const { apiBaseUrl } = getConfig ( )
274
279
this . state . template = this . convertTemplate ( this . state . template )
275
280
await axios . post ( apiBaseUrl + "/api/outbound/template/" + outboundRequestID , this . state . template , { headers : { 'Content-Type' : 'application/json' } } )
276
- message . success ( { content : 'Test case initiated ' , key : 'outboundSendProgress' , duration : 2 } ) ;
281
+ message . loading ( { content : 'Executing the test cases... ' , key : 'outboundSendProgress' , duration : 10 } ) ;
277
282
278
283
// Set the status to waiting for all the requests
279
284
for ( let i in this . state . template . test_cases ) {
@@ -418,7 +423,6 @@ class OutboundRequest extends React.Component {
418
423
var content = e . target . result ;
419
424
try {
420
425
var intern = JSON . parse ( content ) ;
421
- console . log ( file_to_read )
422
426
this . setState ( { template : intern , additionalData : { importedFilename : file_to_read . name } } )
423
427
this . autoSave = true
424
428
message . success ( { content : 'File Loaded' , key : 'importFileProgress' , duration : 2 } ) ;
@@ -427,6 +431,35 @@ class OutboundRequest extends React.Component {
427
431
}
428
432
} ;
429
433
fileRead . readAsText ( file_to_read ) ;
434
+ }
435
+
436
+ handleDownloadReport = async ( event ) => {
437
+ switch ( event . key ) {
438
+ case 'json' :
439
+ const jsonReportFileName = this . state . testReport . name + ( this . state . testReport . runtimeInformation ? '-' + this . state . testReport . runtimeInformation . completedTimeISO : '' ) + '.json'
440
+ FileDownload ( JSON . stringify ( this . state . testReport , null , 2 ) , jsonReportFileName )
441
+ break
442
+ case 'pdf' :
443
+ case 'html' :
444
+ default :
445
+ message . loading ( { content : 'Generating the report...' , key : 'downloadReportProgress' , duration : 10 } ) ;
446
+ const { apiBaseUrl } = getConfig ( )
447
+ const reportFormat = event . key
448
+ const response = await axios . post ( apiBaseUrl + "/api/reports/testcase/" + reportFormat , this . state . testReport , { headers : { 'Content-Type' : 'application/json' } , responseType : 'blob' } )
449
+ let downloadFilename = "test." + reportFormat
450
+ if ( response . headers [ 'content-disposition' ] ) {
451
+ const disposition = response . headers [ 'content-disposition' ]
452
+ if ( disposition && disposition . indexOf ( 'attachment' ) !== - 1 ) {
453
+ var filenameRegex = / f i l e n a m e [ ^ ; = \n ] * = ( ( [ ' " ] ) .* ?\2| [ ^ ; \n ] * ) / ;
454
+ var matches = filenameRegex . exec ( disposition ) ;
455
+ if ( matches != null && matches [ 1 ] ) {
456
+ downloadFilename = matches [ 1 ] . replace ( / [ ' " ] / g, '' ) ;
457
+ }
458
+ }
459
+ }
460
+ FileDownload ( response . data , downloadFilename )
461
+ message . success ( { content : 'Report Generated' , key : 'downloadReportProgress' , duration : 2 } ) ;
462
+ }
430
463
431
464
}
432
465
@@ -475,6 +508,16 @@ class OutboundRequest extends React.Component {
475
508
return null
476
509
}
477
510
511
+ downloadReportMenu = ( ) => {
512
+ return (
513
+ < Menu onClick = { this . handleDownloadReport } >
514
+ < Menu . Item key = 'json' > JSON format</ Menu . Item >
515
+ < Menu . Item key = 'pdf' > PDF report</ Menu . Item >
516
+ < Menu . Item key = 'html' > HTML report</ Menu . Item >
517
+ </ Menu >
518
+ )
519
+ }
520
+
478
521
render ( ) {
479
522
480
523
const createNewTestCaseDialogContent = (
@@ -695,6 +738,22 @@ class OutboundRequest extends React.Component {
695
738
New Template
696
739
</ Button >
697
740
</ Popover >
741
+ {
742
+ this . state . testReport
743
+ ? (
744
+ < Dropdown overlay = { this . downloadReportMenu ( ) } >
745
+ < Button
746
+ className = "float-right"
747
+ color = "danger"
748
+ size = "sm"
749
+ onClick = { e => e . preventDefault ( ) }
750
+ >
751
+ Download Report
752
+ </ Button >
753
+ </ Dropdown >
754
+ )
755
+ : null
756
+ }
698
757
</ Col >
699
758
</ Row >
700
759
</ CardBody >
0 commit comments