-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
4fc6e80
commit 8c6ab37
Showing
1 changed file
with
64 additions
and
0 deletions.
There are no files selected for viewing
64 changes: 64 additions & 0 deletions
64
...arta/state/selectors/accumulatedData/metricData/sortedNodeEdgeMetricsMap.selector.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,64 @@ | ||
import { STATE } from "../../../../util/dataMocks" | ||
import { calculateEdgeMetricData } from "./edgeMetricData.calculator" | ||
import { clone } from "../../../../util/clone" | ||
import { sortedNodeEdgeMetricsMapSelector } from "./sortedNodeEdgeMetricsMap.selector" | ||
|
||
jest.mock("./edgeMetricData.calculator", () => ({ | ||
calculateEdgeMetricData: jest.fn() | ||
})) | ||
|
||
describe("sortedNodeEdgeMetricsMapSelector", () => { | ||
const mockedCalculateEdgeMetricData = calculateEdgeMetricData as jest.Mock | ||
let state | ||
|
||
beforeEach(() => { | ||
state = clone(STATE) | ||
}) | ||
|
||
it("should return a sorted map of node edge metrics", () => { | ||
const nodeEdgeMetricsMap = new Map([ | ||
[ | ||
"metric1", | ||
new Map([ | ||
["node1", { incoming: 2, outgoing: 3 }], | ||
["node2", { incoming: 1, outgoing: 1 }], | ||
["node3", { incoming: 4, outgoing: 4 }] | ||
]) | ||
], | ||
[ | ||
"metric2", | ||
new Map([ | ||
["node3", { incoming: 5, outgoing: 5 }], | ||
["node0", { incoming: 0, outgoing: 0 }], | ||
["node4", { incoming: 2, outgoing: 2 }] | ||
]) | ||
] | ||
]) | ||
mockedCalculateEdgeMetricData.mockReturnValue({ nodeEdgeMetricsMap }) | ||
|
||
const result = sortedNodeEdgeMetricsMapSelector(state) | ||
|
||
expect(result.get("metric1")).toEqual( | ||
new Map([ | ||
["node1", { incoming: 2, outgoing: 3 }], | ||
["node3", { incoming: 4, outgoing: 4 }], | ||
["node2", { incoming: 1, outgoing: 1 }] | ||
]) | ||
) | ||
expect(result.get("metric2")).toEqual( | ||
new Map([ | ||
["node3", { incoming: 5, outgoing: 5 }], | ||
["node4", { incoming: 2, outgoing: 2 }], | ||
["node0", { incoming: 0, outgoing: 0 }] | ||
]) | ||
) | ||
}) | ||
|
||
it("should return an empty map if no metrics are available", () => { | ||
mockedCalculateEdgeMetricData.mockReturnValue({ nodeEdgeMetricsMap: new Map() }) | ||
|
||
const result = sortedNodeEdgeMetricsMapSelector(state) | ||
|
||
expect(result.size).toBe(0) | ||
}) | ||
}) |