Skip to content

Commit

Permalink
Add Suspicious metrics to stable features set #2963
Browse files Browse the repository at this point in the history
  • Loading branch information
ValentinaA committed Feb 16, 2023
1 parent 3599b87 commit cad1075
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 34 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
<ng-container *ngIf="data.analyzedProgrammingLanguage !== undefined && data.analyzedProgrammingLanguage.length">
<div class="title">
<div>Risk Profile</div>
<div>Calculations are always based on mcc (cyclomatic complexity)</div>
</div>
<div>
The Risk Profile gives a quick overview about the complexity and risk structure of the code base. It tells you how much of the
Expand All @@ -15,6 +14,9 @@
More information can be found here:
<a href="https://maibornwolff.github.io/codecharta/docs/risk-profile/">link</a> to How-To article.
</div>
<div class="title">
<div>Calculations are always based on mcc (cyclomatic complexity)</div>
</div>
<div class="suspicious-metrics-summary">
<ul>
<li>{{ data.riskProfile.lowRisk }}% of overall code is in files with low complexity</li>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,8 @@ import { VALID_NODE_JAVA } from "../../../../util/dataMocks"
import { BlacklistItem, NodeType } from "../../../../codeCharta.model"

describe("ArtificialIntelligenceSelector", () => {
it("should return undefined when experimental features are disabled ", () => {
const actual = calculate(false, { unifiedMapNode: VALID_NODE_JAVA }, [])
expect(actual).toBeUndefined()
})

it("should calculate suspicious metrics and risk profile when experimental features are enabled ", () => {
const actual = calculate(true, { unifiedMapNode: VALID_NODE_JAVA }, [])
const actual = calculate({ unifiedMapNode: VALID_NODE_JAVA }, [])

expect(actual).toEqual({
analyzedProgrammingLanguage: "java",
Expand All @@ -24,11 +19,11 @@ describe("ArtificialIntelligenceSelector", () => {
})
})

it("should return untracked metrics when experimental features are enabled ", () => {
it("should return untracked metrics", () => {
VALID_NODE_JAVA.children[0].children.map(object => {
object.attributes.unknownMetric = 2569
})
const actual = calculate(true, { unifiedMapNode: VALID_NODE_JAVA }, [])
const actual = calculate({ unifiedMapNode: VALID_NODE_JAVA }, [])

expect(actual).toEqual({
analyzedProgrammingLanguage: "java",
Expand All @@ -43,7 +38,7 @@ describe("ArtificialIntelligenceSelector", () => {
})
})

it("should ignore excluded nodes when experimental features are enabled", () => {
it("should ignore excluded nodes", () => {
const blacklist: BlacklistItem[] = [{ path: "file1.java", type: "exclude" }]
const blacklistedNode = {
name: "file1.java",
Expand All @@ -52,7 +47,7 @@ describe("ArtificialIntelligenceSelector", () => {
attributes: { rloc: 70, mcc: 1000 }
}

const actual = calculate(true, { unifiedMapNode: blacklistedNode }, blacklist)
const actual = calculate({ unifiedMapNode: blacklistedNode }, blacklist)

expect(actual).toEqual({
riskProfile: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import { getMostFrequentLanguage } from "./util/mainProgrammingLanguageHelper"
import { isPathBlacklisted } from "../../../../util/codeMapHelper"
import { createSelector } from "../../../../state/angular-redux/createSelector"
import { blacklistSelector } from "../../../../state/store/fileSettings/blacklist/blacklist.selector"
import { experimentalFeaturesEnabledSelector } from "../../../../state/store/appSettings/enableExperimentalFeatures/experimentalFeaturesEnabled.selector"
import { CcState } from "../../../../state/store/store"
import { AccumulatedData, accumulatedDataSelector } from "../../../../state/selectors/accumulatedData/accumulatedData.selector"

Expand All @@ -32,14 +31,9 @@ export type ArtificialIntelligenceData = {
}

export const calculate = (
experimentalFeaturesEnabled: boolean,
accumulatedData: Pick<AccumulatedData, "unifiedMapNode">,
blacklist: BlacklistItem[]
): ArtificialIntelligenceData | undefined => {
if (!experimentalFeaturesEnabled) {
return
}

const artificialIntelligenceViewModel: ArtificialIntelligenceData = {
analyzedProgrammingLanguage: undefined,
suspiciousMetricSuggestionLinks: [],
Expand Down Expand Up @@ -97,6 +91,6 @@ function isFileValid(node: CodeMapNode, fileExtension: string) {
}

export const artificialIntelligenceSelector: (state: CcState) => ArtificialIntelligenceData = createSelector(
[experimentalFeaturesEnabledSelector, accumulatedDataSelector, blacklistSelector],
[accumulatedDataSelector, blacklistSelector],
calculate
)
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import userEvent from "@testing-library/user-event"
import { EdgeMetricData } from "../../codeCharta.model"
import { metricDataSelector } from "../../state/selectors/accumulatedData/metricData/metricData.selector"
import { isDeltaStateSelector } from "../../state/selectors/isDeltaState.selector"
import { setExperimentalFeaturesEnabled } from "../../state/store/appSettings/enableExperimentalFeatures/experimentalFeaturesEnabled.actions"
import { Store } from "../../state/store/store"
//import { setExperimentalFeaturesEnabled } from "../../state/store/appSettings/enableExperimentalFeatures/experimentalFeaturesEnabled.actions"
// import { Store } from "../../state/store/store"
import { ThreeCameraService } from "../codeMap/threeViewer/threeCamera.service"
import { ThreeOrbitControlsService } from "../codeMap/threeViewer/threeOrbitControls.service"
import { RibbonBarComponent } from "./ribbonBar.component"
Expand Down Expand Up @@ -65,20 +65,6 @@ describe("RibbonBarComponent", () => {
})
})

describe("experimental features", () => {
it("should hide experimental features when they are disabled", async () => {
Store.dispatch(setExperimentalFeaturesEnabled(false))
await render(RibbonBarComponent, { excludeComponentDeclaration: true })
expect(screen.queryByText("Suspicious Metrics")).toBe(null)
})

it("should show experimental features when they are enabled", async () => {
Store.dispatch(setExperimentalFeaturesEnabled(true))
await render(RibbonBarComponent, { excludeComponentDeclaration: true })
expect(screen.getByText("Suspicious Metrics")).toBeTruthy()
})
})

describe("delta state", () => {
it("should not show cc-color-metric-chooser and cc-link-color-metric-to-height-metric-button when in delta mode", async () => {
mockedIsDeltaStateSelector.mockImplementation(() => true)
Expand Down

0 comments on commit cad1075

Please sign in to comment.