-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor/2318/migrate distribution metric chooser (#2824)
migrate distribution chooser and distributionMetric.service ref #2318
- Loading branch information
1 parent
5a8c623
commit 82209aa
Showing
53 changed files
with
886 additions
and
804 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
39 changes: 39 additions & 0 deletions
39
...ization/app/codeCharta/state/effects/resetChosenMetrics/resetChosenMetrics.effect.spec.ts
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,39 @@ | ||
import { ApplicationInitStatus } from "@angular/core" | ||
import { TestBed } from "@angular/core/testing" | ||
import { Subject } from "rxjs" | ||
import { EffectsModule } from "../../angular-redux/effects/effects.module" | ||
import { Store } from "../../angular-redux/store" | ||
import { setDistributionMetric } from "../../store/dynamicSettings/distributionMetric/distributionMetric.actions" | ||
import { ResetChosenMetricsEffect } from "./resetChosenMetrics.effect" | ||
|
||
describe("resetChosenMetricsEffect", () => { | ||
let mockedNodeMetricDataSelector = new Subject() | ||
const mockedStore = { | ||
select: () => mockedNodeMetricDataSelector, | ||
dispatch: jest.fn() | ||
} | ||
|
||
beforeEach(async () => { | ||
mockedStore.dispatch = jest.fn() | ||
mockedNodeMetricDataSelector = new Subject() | ||
TestBed.configureTestingModule({ | ||
imports: [EffectsModule.forRoot([ResetChosenMetricsEffect])], | ||
providers: [{ provide: Store, useValue: mockedStore }] | ||
}) | ||
await TestBed.inject(ApplicationInitStatus).donePromise | ||
}) | ||
|
||
afterEach(() => { | ||
mockedNodeMetricDataSelector.complete() | ||
}) | ||
|
||
it("should do nothing, when there are no metrics available", () => { | ||
mockedNodeMetricDataSelector.next([]) | ||
expect(mockedStore.dispatch).not.toHaveBeenCalled() | ||
}) | ||
|
||
it("should reset chosen distribution metric", () => { | ||
mockedNodeMetricDataSelector.next([{ name: "rloc", maxValue: 9001 }]) | ||
expect(mockedStore.dispatch).toHaveBeenCalledWith(setDistributionMetric("rloc")) | ||
}) | ||
}) |
24 changes: 24 additions & 0 deletions
24
visualization/app/codeCharta/state/effects/resetChosenMetrics/resetChosenMetrics.effect.ts
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,24 @@ | ||
import { Inject, Injectable } from "@angular/core" | ||
import { tap } from "rxjs" | ||
import { isAnyMetricAvailable } from "./utils/metricHelper" | ||
import { createEffect } from "../../angular-redux/effects/createEffect" | ||
import { Store } from "../../angular-redux/store" | ||
import { nodeMetricDataSelector } from "../../selectors/accumulatedData/metricData/nodeMetricData.selector" | ||
import { setDistributionMetric } from "../../store/dynamicSettings/distributionMetric/distributionMetric.actions" | ||
import { getDefaultDistribution } from "./utils/getDefaultDistributionMetric" | ||
|
||
@Injectable() | ||
export class ResetChosenMetricsEffect { | ||
constructor(@Inject(Store) private store: Store) {} | ||
|
||
resetChosenDistributionMetric$ = createEffect(() => | ||
this.store.select(nodeMetricDataSelector).pipe( | ||
tap(nodeMetricData => { | ||
if (isAnyMetricAvailable(nodeMetricData)) { | ||
// when migrating area, height and color service, their resetting will be added here as well | ||
this.store.dispatch(setDistributionMetric(getDefaultDistribution(nodeMetricData))) | ||
} | ||
}) | ||
) | ||
) | ||
} |
11 changes: 11 additions & 0 deletions
11
...tion/app/codeCharta/state/effects/resetChosenMetrics/utils/getDefaultDistribution.spec.ts
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,11 @@ | ||
import { getDefaultDistribution } from "./getDefaultDistributionMetric" | ||
|
||
describe("getDefaultDistribution", () => { | ||
it("should default to 'rloc' if 'rloc' is present", () => { | ||
expect(getDefaultDistribution([{ name: "rloc" }, { name: "unary" }])).toBe("rloc") | ||
}) | ||
|
||
it("should default to 'unary' if 'rloc' is not present", () => { | ||
expect(getDefaultDistribution([{ name: "unary" }])).toBe("unary") | ||
}) | ||
}) |
4 changes: 4 additions & 0 deletions
4
...ion/app/codeCharta/state/effects/resetChosenMetrics/utils/getDefaultDistributionMetric.ts
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,4 @@ | ||
import { NodeMetricData } from "../../../../codeCharta.model" | ||
|
||
export const getDefaultDistribution = (nodeMetricData: Pick<NodeMetricData, "name">[]) => | ||
nodeMetricData.some(element => element.name === "rloc") ? "rloc" : "unary" |
41 changes: 41 additions & 0 deletions
41
visualization/app/codeCharta/state/effects/resetChosenMetrics/utils/metricHelper.spec.ts
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,41 @@ | ||
import { getMetricNameFromIndexOrLast, isAnyMetricAvailable, isMetricUnavailable } from "./metricHelper" | ||
|
||
describe("metricHelper", () => { | ||
describe("isAnyMetricAvailable", () => { | ||
it("should return true when there is a metric with a maxValue", () => { | ||
expect(isAnyMetricAvailable([{ maxValue: 1 }])).toBe(true) | ||
}) | ||
|
||
it("should return false when there is no metric available", () => { | ||
expect(isAnyMetricAvailable([])).toBe(false) | ||
}) | ||
}) | ||
|
||
describe("isMetricUnavailable", () => { | ||
it("should return true, when given metric is not available", () => { | ||
expect(isMetricUnavailable([{ name: "a", maxValue: 1 }], "b")).toBe(true) | ||
}) | ||
|
||
it("should return false, when given metric is available", () => { | ||
expect(isMetricUnavailable([{ name: "a", maxValue: 1 }], "a")).toBe(false) | ||
}) | ||
}) | ||
|
||
describe("getMetricNameFromIndexOrLast", () => { | ||
it("should return metric at given index if it exists", () => { | ||
expect( | ||
getMetricNameFromIndexOrLast( | ||
[ | ||
{ name: "a", maxValue: 1 }, | ||
{ name: "b", maxValue: 2 } | ||
], | ||
0 | ||
) | ||
).toBe("a") | ||
}) | ||
|
||
it("should return metric at last index if given index is to large", () => { | ||
expect(getMetricNameFromIndexOrLast([{ name: "a", maxValue: 1 }], 1)).toBe("a") | ||
}) | ||
}) | ||
}) |
13 changes: 13 additions & 0 deletions
13
visualization/app/codeCharta/state/effects/resetChosenMetrics/utils/metricHelper.ts
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,13 @@ | ||
import { NodeMetricData } from "../../../../codeCharta.model" | ||
|
||
export function isAnyMetricAvailable(metricData: Pick<NodeMetricData, "maxValue">[]) { | ||
return metricData.some(x => x.maxValue > 0) | ||
} | ||
|
||
export function isMetricUnavailable(metricData: Pick<NodeMetricData, "maxValue" | "name">[], metricName: string) { | ||
return !metricData.some(x => x.maxValue > 0 && x.name === metricName) | ||
} | ||
|
||
export function getMetricNameFromIndexOrLast<T extends Pick<NodeMetricData, "maxValue" | "name">>(metricData: T[], index: number) { | ||
return metricData[index < metricData.length ? index : metricData.length - 1].name | ||
} |
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
4 changes: 4 additions & 0 deletions
4
.../codeCharta/state/store/dynamicSettings/distributionMetric/distributionMetric.selector.ts
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,4 @@ | ||
import { createSelector } from "../../../angular-redux/createSelector" | ||
import { dynamicSettingsSelector } from "../dynamicSettings.selector" | ||
|
||
export const distributionMetricSelector = createSelector([dynamicSettingsSelector], dynamicSettings => dynamicSettings.distributionMetric) |
136 changes: 0 additions & 136 deletions
136
...eCharta/state/store/dynamicSettings/distributionMetric/distributionMetric.service.spec.ts
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.