Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix/2393/risk-profile-total-sum-of-percentages #2516

Merged
merged 4 commits into from
Nov 19, 2021
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,19 +1,28 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`ArtificialIntelligenceController on files selection changed should calculate risk profile and should not exceed 100 percent 1`] = `
Object {
"highRisk": 37,
"lowRisk": 46,
"moderateRisk": 16,
"veryHighRisk": 0,
}
`;

exports[`ArtificialIntelligenceController on files selection changed should calculate risk profile for not excluded files only 1`] = `
Object {
"highRisk": 15,
"lowRisk": 85,
"moderateRisk": 0,
"highRisk": 50,
"lowRisk": 27,
"moderateRisk": 22,
"veryHighRisk": 0,
}
`;

exports[`ArtificialIntelligenceController on files selection changed should clear and calculate risk profile for Java map 1`] = `
Object {
"highRisk": 11,
"lowRisk": 88,
"moderateRisk": 0,
"highRisk": 37,
"lowRisk": 46,
"moderateRisk": 16,
"veryHighRisk": 0,
}
`;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,15 @@ describe("ArtificialIntelligenceController", () => {
expect(artificialIntelligenceController["createCustomConfigSuggestions"]).toHaveBeenCalled()
})

it("should calculate risk profile and should not exceed 100 percent", () => {
storeService.dispatch(setExperimentalFeaturesEnabled(true))
artificialIntelligenceController.onFilesSelectionChanged(FILE_STATES_JAVA)
const sumOfRiskPercentage = Object.values(artificialIntelligenceController["_viewModel"].riskProfile).reduce((a, b) => a + b)

expect(artificialIntelligenceController["_viewModel"].riskProfile).toMatchSnapshot()
expect(sumOfRiskPercentage).toEqual(99)
})

it("should create custom config suggestions sorted by outlierCustomConfigId", () => {
artificialIntelligenceController["clearRiskProfile"] = jest.fn()
artificialIntelligenceController["calculateRiskProfile"] = jest.fn()
Expand Down
8 changes: 4 additions & 4 deletions visualization/app/codeCharta/util/dataMocks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,19 +103,19 @@ export const VALID_NODE_JAVA: CodeMapNode = {
name: "file2.java",
path: "/root/src/main/file2.java",
type: NodeType.FILE,
attributes: { rloc: 30, functions: 100, mcc: 100, loc: 100 }
attributes: { rloc: 55, functions: 100, mcc: 40, loc: 100 }
},
{
name: "file3.java",
path: "/root/src/main/file3.java",
type: NodeType.FILE,
attributes: { rloc: 70, functions: 1, mcc: 1, loc: 1 }
attributes: { rloc: 45, functions: 1, mcc: 70, loc: 1 }
},
{
name: "readme",
path: "/root/src/main/readme",
type: NodeType.FILE,
attributes: { rloc: 200, functions: 1, mcc: 1, loc: 1 }
attributes: { rloc: 200, functions: 1, mcc: 70, loc: 1 }
}
]
},
Expand All @@ -129,7 +129,7 @@ export const VALID_NODE_JAVA: CodeMapNode = {
name: "otherFile.java",
path: "/root/src/test/otherFile.java",
type: NodeType.FILE,
attributes: { rloc: 100, functions: 10, mcc: 1 }
attributes: { rloc: 100, functions: 10, mcc: 100 }
}
]
}
Expand Down