Skip to content

Commit

Permalink
Feature/2348 test cases definition report with grouping (#196)
Browse files Browse the repository at this point in the history
* testcases definition report with grouping

* add generation of testcaseDefinitionReport to cli
  • Loading branch information
georgi-logodazhki committed Nov 3, 2021
1 parent 435a689 commit 142ca8f
Show file tree
Hide file tree
Showing 12 changed files with 314 additions and 124 deletions.
2 changes: 1 addition & 1 deletion audit-resolve.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
},
"1002718|json-ref-lite>property-expr": {
"decision": "postpone",
"madeAt": 1634580037057
"madeAt": 1635515288777
}
},
"rules": {},
Expand Down
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "ml-testing-toolkit",
"description": "Testing Toolkit for Mojaloop implementations",
"version": "14.0.1",
"version": "14.0.2",
"license": "Apache-2.0",
"author": "Vijaya Kumar Guthi, ModusBox Inc. ",
"contributors": [
Expand Down
186 changes: 119 additions & 67 deletions spec_files/reports/templates/testcase_definition/table_view.html
Original file line number Diff line number Diff line change
@@ -1,81 +1,133 @@
<!DOCTYPE html>
<html>
<head>
<style>
#customers {
font-family: Arial, Helvetica, sans-serif;
border-collapse: collapse;
width: 100%;
box-shadow: 0 4px 8px 0 rgba(0, 0, 0, 0.2), 0 6px 20px 0 rgba(0, 0, 0, 0.19);
}
<head>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
<style>
#customers {
font-family: Arial, Helvetica, sans-serif;
border-collapse: collapse;
width: 100%;
box-shadow: 0 4px 8px 0 rgba(0, 0, 0, 0.2), 0 6px 20px 0 rgba(0, 0, 0, 0.19);
}

#customers td, #customers th {
border: 1px solid #ddd;
padding: 14px;
}
#customers .tableRow:nth-child(even){
background-color: #f9f9f9;
}

#customers tr:nth-child(even){background-color: #f9f9f9;}
#customers .tableRow:hover {
background-color: #eee;
}

#customers tr:hover {background-color: #eee;}
#customers .tableHeader {
padding: 16px;
text-align: left;
background-color: #EEE;
color: black;
}

#customers th {
padding-top: 16px;
padding-bottom: 16px;
text-align: left;
background-color: #EEE;
color: black;
}
#customers .tableHeaderBlue {
background-color: #E0EfFE;
color: black;
}
#customers .tableHeaderYellow {
background-color: #FFFDDD;
color: black;
}

#customers .headerBlue th {
background-color: #E0EfFE;
color: black;
/* padding-left: 25px; */
#customers .tableHeaderYellow .collapsed {
transform: rotate(90deg);
}

}
</style>
</head>
<body>

#customers .headerYellow th {
background-color: #FFFDDD;
color: black;
/* padding-left: 35px; */
}
<div id="customers" class="container-fluid border border-dark" >

</style>
</head>
<body>
<div class="row border border-white">
<div class="col border border-white">
<div class="btn-group float-right" role="group" aria-label="Button Group">
<button id="openAll" class="btn btn-outline-success btn-sm float-right">Expand Folders</button>
<button id="closeAll" class="btn btn-outline-success btn-sm float-right">Collapse Folders</button>
</div>
</div>
</div>

<div class="row border border-white">
<div class="col border border-white">
<div class="row tableRow border border-secondary">
<div class="col-2 tableHeader border border-secondary">Testcase</div>
<div class="col-2 tableHeader border border-secondary">Request Description</div>
<div class="col-3 tableHeader border border-secondary">Test Scenario</div>
<div class="col-5 tableHeader border border-secondary">Expected Result</div>
</div>
</div>
</div>
{{#each test_cases}}
<div class="row border border-white">
<div class="col border border-white">
<div class="row tableRow border border-secondary" >
<div class="col-sm tableHeaderBlue border border-secondary" >{{fileInfo.path}}
{{#if fileInfo.labels}}
- (Labels: {{fileInfo.labels}})
{{/if}}
</div>
</div>
<div class="row tableRow border border-secondary">
<div class="col tableHeaderYellow border border-secondary">
<a data-toggle="collapse" href="#" data-target="#folder-collapse-{{id}}" aria-expanded="false" aria-controls="collapse" id="folder-{{id}}" class="collapsed z-block">
{{name}}
</a>
</div>
</div>

<div id="folder-collapse-{{id}}" class="collapse row border border-secondary" aria-labelledby="folder-{{id}}">
<div class="col border border-secondary">
{{#each requests}}
<div class="row tableRow border border-secondary">
<div class="col-2 tableData border border-secondary">{{#if @first}}{{../meta.info}}{{/if}} </div>
<div class="col-2 tableData border border-secondary">{{meta.info}}</div>
<div class="col-3 tableData border border-secondary">{{description}} <br />({{method}} {{operationPath}})</div>
<div class="col-5 tableData border border-secondary">
{{#if tests.assertions}}
<ul>
{{#each tests.assertions}}
<li>{{description}}</li>
{{/each}}
</ul>
{{/if}}
</div>
</div>
{{/each}}
</div>
</div>
</div>
</div>
{{/each}}

<table id="customers">
<tr>
<th>Testcase</th>
<th>Request Description</th>
<th>Test Scenario</th>
<th>Expected Result</th>
</tr>
<tr class='headerBlue'>
<th colspan='100%'>Folder Name > File Name</th>
</tr>
{{#each test_cases}}
<tr class='headerYellow'>
<th colspan='100%'>{{name}}</th>
</tr>
{{#each requests}}
<tr>
<td>{{#if @first}}{{../meta.info}}{{/if}} </td>
<td>{{meta.info}}</td>
<td>{{description}} <br />({{method}} {{operationPath}})</td>
<td>
{{#if tests.assertions}}
<ul>
{{#each tests.assertions}}
<li>{{description}}</li>
{{/each}}
</ul>
{{/if}}
</td>
</tr>
{{/each}}
{{/each}}
</div>

</table>
<script src="https://code.jquery.com/jquery-3.2.1.slim.min.js" integrity="sha384-KJ3o2DKtIkvYIK3UENzmM7KCkRr/rE9/Qpg6aAZGJwFDMVNA/GpGFF93hXpG5KkN" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.9/umd/popper.min.js" integrity="sha384-ApNbgh9B+Y1QKtv3Rn7W3mgPxhU9K/ScQsAP7hUibX39j7fakFPskvXusvfa0b4Q" crossorigin="anonymous"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js" integrity="sha384-JZR6Spejh4U02d8jOt6vLEHfe/JQGiRRSQQxSfFWpi1MquVdAyjUar5+76PVCmYl" crossorigin="anonymous"></script>

</body>
</body>
</html>

<script>
$('#openAll').on('click', function(e) {
{{#each test_cases}}
$('#folder-{{id}}').removeClass('collapsed')
$('#folder-collapse-{{id}}').addClass('show')
{{/each}}
})
</script>

<script>
$('#closeAll').on('click', function(e) {
{{#each test_cases}}
$('#folder-{{id}}').addClass('collapsed')
$('#folder-collapse-{{id}}').removeClass('show')
{{/each}}
})
</script>
2 changes: 1 addition & 1 deletion src/cli_client/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ const router = require('./router')
commander
.version('1.0.0', '-v, --version')
.option('-c, --config <config>', 'default configuration: {"mode": "outbound", "reportFormat": "json"}')
.option('-m, --mode <mode>', 'default: "outbound" --- supported modes: "monitoring", "outbound"')
.option('-m, --mode <mode>', 'default: "outbound" --- supported modes: "monitoring", "outbound", "testcaseDefinitionReport"')
.option('-u, --base-url <baseUrl>', 'default: "http://localhost:5050"')
.option('-i, --input-files <inputFiles>', 'csv list of json files or directories; required when the mode is "outbound" --- supported formats: "json"')
.option('-e, --environment-file <environmentFile>', 'required when the mode is "outbound" --- supported formats: "json"')
Expand Down
53 changes: 53 additions & 0 deletions src/cli_client/modes/testcaseDefinitionReport.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/*****
License
--------------
Copyright © 2017 Bill & Melinda Gates Foundation
The Mojaloop files are made available by the Bill & Melinda Gates Foundation under the Apache License, Version 2.0 (the "License") and you may not use these files except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, the Mojaloop files are distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
Contributors
--------------
This is the official list of the Mojaloop project contributors for this file.
Names of the original copyright holders (individuals or organizations)
should be listed with a '*' in the first column. People who have
contributed from an organization can be listed under the organization
that actually holds the copyright for their contributions (see the
Gates Foundation organization for an example). Those individuals should have
their names indented and be marked with a '-'. Email address can be added
optionally within square brackets <email>.
* Gates Foundation
* ModusBox
* Georgi Logodazhki <georgi.logodazhki@modusbox.com> (Original Author)
--------------
******/

const report = require('../utils/report')
const fStr = require('node-strings')
const utils = require('../../lib/utils.js')
const objectStore = require('../objectStore')
const templateGenerator = require('../utils/templateGenerator')

const download = async () => {
const config = objectStore.get('config')
try {
const inputFiles = config.inputFiles.split(',')
const selectedLabels = config.labels ? config.labels.split(',') : null
const template = await templateGenerator.generateTemplate(inputFiles, selectedLabels)
if (config.environmentFile) {
const environmentFileContent = await utils.readFileAsync(config.environmentFile, 'utf8')
template.inputValues = JSON.parse(environmentFileContent).inputValues
}
await report.testcaseDefinition(template)
console.log(fStr.green('Terminate with exit code 0'))
process.exit(0)
} catch (err) {
console.log(err)
console.log(fStr.red('Terminate with exit code 1'))
process.exit(1)
}
}

module.exports = {
download
}
12 changes: 12 additions & 0 deletions src/cli_client/router.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,18 @@ const cli = (commander) => {
process.exit(1)
}
break
case 'testcaseDefinitionReport':
if (config.inputFiles) {
if (!commander.reportFormat) {
config.reportFormat = 'printhtml'
objectStore.set('config', config)
}
require('./modes/testcaseDefinitionReport').download()
} else {
console.log('error: required option \'-i, --input-files <inputFiles>\' not specified')
process.exit(1)
}
break
default:
console.log('Mode is not supported')
console.log('Terminate with exit code 1')
Expand Down
13 changes: 12 additions & 1 deletion src/cli_client/utils/report.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,16 @@ const objectStore = require('../objectStore')
const s3Upload = require('../extras/s3-upload')

const outbound = async (data) => {
const testcaseReport = await report(data, 'testcase')
return testcaseReport
}

const testcaseDefinition = async (template) => {
const testcaseDefinitionReport = await report(template, 'testcase_definition')
return testcaseDefinitionReport
}

const report = async (data, reportType) => {
const returnInfo = {}
const config = objectStore.get('config')
let reportData
Expand All @@ -50,7 +60,7 @@ const outbound = async (data) => {
}
})
}
const response = await axios.post(`${config.baseURL}/api/reports/testcase/${config.reportFormat}`, data, { headers: { 'Content-Type': 'application/json' } })
const response = await axios.post(`${config.baseURL}/api/reports/${reportType}/${config.reportFormat}`, data, { headers: { 'Content-Type': 'application/json' } })
reportData = response.data
const disposition = response.headers['content-disposition']
if (disposition && disposition.indexOf('attachment') !== -1) {
Expand Down Expand Up @@ -112,5 +122,6 @@ const replaceFileName = (fullPath, fileName) => {
}

module.exports = {
testcaseDefinition,
outbound
}
Loading

0 comments on commit 142ca8f

Please sign in to comment.