-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: Update metrics calculations and related UI components (#1172)
* Address missing db persisted calculation for exclusions (this wasn't impacting the frontend directly because the calls were being done again on the reports pages) * Revise aria-label with progress bar to avoid double speech * Update getMetrics to stop rounding up and use utilities * Remove Math.round usage on candidate test plans page * Update shared/calculations usage * Include migration and better handling of finalizedTestResultsResolver.js * Add tests for getMetrics * Add tests for getMetrics * Add tests for getMetrics * Reduce noisy aria-labels * Additional clarifying comments
- Loading branch information
Showing
11 changed files
with
3,552 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
'use strict'; | ||
|
||
const { getMetrics } = require('shared'); | ||
const populateData = require('../services/PopulatedData/populateData'); | ||
const runnableTestsResolver = require('../resolvers/TestPlanReport/runnableTestsResolver'); | ||
const finalizedTestResultsResolver = require('../resolvers/TestPlanReport/finalizedTestResultsResolver'); | ||
const { | ||
updateTestPlanReportById | ||
} = require('../models/services/TestPlanReportService'); | ||
const getGraphQLContext = require('../graphql-context'); | ||
|
||
/** @type {import('sequelize-cli').Migration} */ | ||
module.exports = { | ||
async up(queryInterface, Sequelize) { | ||
return queryInterface.sequelize.transaction(async transaction => { | ||
const context = getGraphQLContext({ req: { transaction } }); | ||
|
||
const testPlanReports = await queryInterface.sequelize.query( | ||
`select distinct on ("TestPlanReport".id) "TestPlanReport".id, metrics | ||
from "TestPlanReport" | ||
join public."TestPlanRun" testPlanRun on "TestPlanReport".id = testPlanRun."testPlanReportId" | ||
where jsonb_array_length(testPlanRun."testResults") > 0;`, | ||
{ | ||
type: Sequelize.QueryTypes.SELECT, | ||
transaction | ||
} | ||
); | ||
|
||
for (const testPlanReport of testPlanReports) { | ||
const { testPlanReport: testPlanReportPopulated } = await populateData( | ||
{ testPlanReportId: testPlanReport.id }, | ||
{ context } | ||
); | ||
const runnableTests = runnableTestsResolver( | ||
testPlanReportPopulated, | ||
null, | ||
context | ||
); | ||
const finalizedTestResults = await finalizedTestResultsResolver( | ||
testPlanReportPopulated, | ||
null, | ||
context | ||
); | ||
const metrics = getMetrics({ | ||
testPlanReport: { | ||
...testPlanReportPopulated, | ||
finalizedTestResults, | ||
runnableTests | ||
} | ||
}); | ||
await updateTestPlanReportById({ | ||
id: testPlanReportPopulated.id, | ||
values: { | ||
metrics: { | ||
...testPlanReportPopulated.metrics, | ||
...metrics | ||
} | ||
}, | ||
transaction | ||
}); | ||
} | ||
}); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
/** | ||
* @param {number} value | ||
* @param {number} total | ||
* @param {boolean} ignoreError - to account for cases where having a NaN is "expected" | ||
* @returns {number} | ||
*/ | ||
const calculatePercentage = (value, total, { ignoreError = true } = {}) => { | ||
if (!ignoreError && total === 0) { | ||
throw new Error("Unable to divide. 'total' cannot be 0."); | ||
} | ||
return (value / total) * 100; | ||
}; | ||
|
||
const trimDecimals = (number, decimals = 0) => { | ||
if (decimals === undefined || decimals <= 0) { | ||
return Math.floor(number); | ||
} else { | ||
let factor = Math.pow(10, decimals); | ||
return Math.floor(number * factor) / factor; | ||
} | ||
}; | ||
|
||
module.exports = { | ||
calculatePercentage, | ||
trimDecimals | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
const calculations = require('./calculations'); | ||
const convertAssertionPriority = require('./convertAssertionPriority'); | ||
const getMetrics = require('./getMetrics'); | ||
module.exports = { convertAssertionPriority, getMetrics }; | ||
|
||
module.exports = { calculations, convertAssertionPriority, getMetrics }; |
Oops, something went wrong.