fixed test cases errors

This commit is contained in:
sunilyadav840
2021-05-05 17:59:54 +05:30
parent 038f3ee684
commit b4cc0f8e52
5 changed files with 202 additions and 176 deletions
@@ -87,16 +87,18 @@ export class IndexingPolicyComponent extends React.Component<
private async createIndexingPolicyEditor(): Promise<void> { private async createIndexingPolicyEditor(): Promise<void> {
const value: string = JSON.stringify(this.props.indexingPolicyContent, undefined, 4); const value: string = JSON.stringify(this.props.indexingPolicyContent, undefined, 4);
const monaco = await loadMonaco(); const monaco = await loadMonaco();
this.indexingPolicyEditor = monaco.editor.create(this.indexingPolicyDiv.current, { if (monaco.editor) {
value: value, this.indexingPolicyEditor = monaco.editor.create(this.indexingPolicyDiv.current, {
language: "json", value: value,
readOnly: isIndexTransforming(this.props.indexTransformationProgress), language: "json",
ariaLabel: "Indexing Policy", readOnly: isIndexTransforming(this.props.indexTransformationProgress),
}); ariaLabel: "Indexing Policy",
if (this.indexingPolicyEditor) { });
const indexingPolicyEditorModel = this.indexingPolicyEditor.getModel(); if (this.indexingPolicyEditor) {
indexingPolicyEditorModel.onDidChangeContent(this.onEditorContentChange.bind(this)); const indexingPolicyEditorModel = this.indexingPolicyEditor.getModel();
this.props.logIndexingPolicySuccessMessage(); indexingPolicyEditorModel.onDidChangeContent(this.onEditorContentChange.bind(this));
this.props.logIndexingPolicySuccessMessage();
}
} }
} }
@@ -1,7 +1,7 @@
import * as sinon from "sinon"; import * as sinon from "sinon";
import { D3ForceGraph, LoadMoreDataAction, D3GraphNodeData } from "./D3ForceGraph";
import { D3Node, D3Link, GraphData } from "../GraphExplorerComponent/GraphData";
import GraphTab from "../../Tabs/GraphTab"; import GraphTab from "../../Tabs/GraphTab";
import { D3Link, D3Node, GraphData } from "../GraphExplorerComponent/GraphData";
import { D3ForceGraph, D3GraphNodeData, LoadMoreDataAction } from "./D3ForceGraph";
describe("D3ForceGraph", () => { describe("D3ForceGraph", () => {
const v1Id = "v1"; const v1Id = "v1";
@@ -138,18 +138,20 @@ describe("D3ForceGraph", () => {
it("should call onHighlightedNode callback when mouse hovering over node", () => { it("should call onHighlightedNode callback when mouse hovering over node", () => {
forceGraph.params.onGraphUpdated = () => { forceGraph.params.onGraphUpdated = () => {
const mouseoverEvent = document.createEvent("Events"); if (document) {
mouseoverEvent.initEvent("mouseover", true, false); const mouseoverEvent = document.createEvent("Events");
$(rootNode).find(".node")[0].dispatchEvent(mouseoverEvent); // [0] is v1 vertex mouseoverEvent.initEvent("mouseover", true, false);
$(rootNode).find(".node")[0].dispatchEvent(mouseoverEvent); // [0] is v1 vertex
// onHighlightedNode is always called once to clear the selection // onHighlightedNode is always called once to clear the selection
expect((forceGraph.params.onHighlightedNode as sinon.SinonSpy).calledTwice).toBe(true); expect((forceGraph.params.onHighlightedNode as sinon.SinonSpy).calledTwice).toBe(true);
const onHighlightedNode = (forceGraph.params.onHighlightedNode as sinon.SinonSpy).args[1][0] as D3GraphNodeData; const onHighlightedNode = (forceGraph.params.onHighlightedNode as sinon.SinonSpy)
expect(onHighlightedNode).not.toBe(null); .args[1][0] as D3GraphNodeData;
expect(onHighlightedNode.id).toEqual(v1Id); expect(onHighlightedNode).not.toBe(null);
expect(onHighlightedNode.id).toEqual(v1Id);
}
}; };
forceGraph.updateGraph(newGraph); forceGraph.updateGraph(newGraph);
}); });
}); });
@@ -626,12 +626,12 @@ export class D3ForceGraph implements GraphRenderer {
this.addNewLinks(); this.addNewLinks();
const nodes = this.simulation.nodes(); const nodes = this.simulation && this.simulation.nodes();
this.redrawGraph(); this.redrawGraph();
this.animateBigBang(nodes, newNodes); this.animateBigBang(nodes, newNodes);
this.simulation.alpha(1).restart(); this.simulation && this.simulation.alpha(1).restart();
this.params.onGraphUpdated(new Date().getTime()); this.params.onGraphUpdated(new Date().getTime());
}); });
@@ -651,140 +651,143 @@ export class D3ForceGraph implements GraphRenderer {
} }
private addNewLinks(): d3.Selection<Element, any, any, any> { private addNewLinks(): d3.Selection<Element, any, any, any> {
const newLinks = this.linkSelection.enter().append("g").attr("class", "markerEndContainer"); let newLinks: any = {};
if (this.linkSelection) {
newLinks = this.linkSelection.enter().append("g").attr("class", "markerEndContainer");
const line = newLinks
.append("path")
.attr("class", "link")
.attr("fill", "none")
.attr("stroke-width", this.params.graphConfig.linkWidth())
.attr("stroke", this.params.graphConfig.linkColor());
const line = newLinks if (D3ForceGraph.useSvgMarkerEnd()) {
.append("path") line.attr("marker-end", `url(#${this.getArrowHeadSymbolId()}-marker)`);
.attr("class", "link") } else {
.attr("fill", "none") newLinks
.attr("stroke-width", this.params.graphConfig.linkWidth()) .append("g")
.attr("stroke", this.params.graphConfig.linkColor()); .append("use")
.attr("xlink:href", `#${this.getArrowHeadSymbolId()}-nonMarker`)
.attr("class", "markerEnd link")
.attr("fill", this.params.graphConfig.linkColor())
.classed(`${this.getArrowHeadSymbolId()}`, true);
}
if (D3ForceGraph.useSvgMarkerEnd()) { this.linkSelection = newLinks.merge(this.linkSelection);
line.attr("marker-end", `url(#${this.getArrowHeadSymbolId()}-marker)`);
} else {
newLinks
.append("g")
.append("use")
.attr("xlink:href", `#${this.getArrowHeadSymbolId()}-nonMarker`)
.attr("class", "markerEnd link")
.attr("fill", this.params.graphConfig.linkColor())
.classed(`${this.getArrowHeadSymbolId()}`, true);
} }
this.linkSelection = newLinks.merge(this.linkSelection);
return newLinks; return newLinks;
} }
private addNewNodes(): d3.Selection<Element, any, any, any> { private addNewNodes(): d3.Selection<Element, any, any, any> {
var self = this; var self = this;
let newNodes: any = {};
if (this.nodeSelection) {
newNodes = this.nodeSelection
.enter()
.append("g")
.attr("class", (d: D3Node) => {
return d._isRoot ? "node root" : "node";
})
.call(
drag()
.on("start", ((e: D3DragEvent<SVGGElement, D3Node, unknown>, d: D3Node) => {
return this.dragstarted(d, e);
}) as any)
.on("drag", ((e: D3DragEvent<SVGGElement, D3Node, unknown>, d: D3Node) => {
return this.dragged(d, e);
}) as any)
.on("end", ((e: D3DragEvent<SVGGElement, D3Node, unknown>, d: D3Node) => {
return this.dragended(d, e);
}) as any)
)
.on("mouseover", (_: MouseEvent, d: D3Node) => {
if (this.isHighlightDisabled || this.selectedNode || this.isDragging) {
return;
}
const newNodes = this.nodeSelection this.highlightNode(this, d);
.enter() this.simulation.stop();
.append("g") })
.attr("class", (d: D3Node) => { .on("mouseout", (_: MouseEvent, d: D3Node) => {
return d._isRoot ? "node root" : "node"; if (this.isHighlightDisabled || this.selectedNode || this.isDragging) {
}) return;
.call( }
drag()
.on("start", ((e: D3DragEvent<SVGGElement, D3Node, unknown>, d: D3Node) => {
return this.dragstarted(d, e);
}) as any)
.on("drag", ((e: D3DragEvent<SVGGElement, D3Node, unknown>, d: D3Node) => {
return this.dragged(d, e);
}) as any)
.on("end", ((e: D3DragEvent<SVGGElement, D3Node, unknown>, d: D3Node) => {
return this.dragended(d, e);
}) as any)
)
.on("mouseover", (_: MouseEvent, d: D3Node) => {
if (this.isHighlightDisabled || this.selectedNode || this.isDragging) {
return;
}
this.highlightNode(this, d); this.unhighlightNode();
this.simulation.stop();
})
.on("mouseout", (_: MouseEvent, d: D3Node) => {
if (this.isHighlightDisabled || this.selectedNode || this.isDragging) {
return;
}
this.unhighlightNode(); this.simulation.restart();
})
.each((d: D3Node) => {
// Initial position for nodes. This prevents blinking as following the tween transition doesn't always start right away
d.x = self.viewCenter.x;
d.y = self.viewCenter.y;
});
this.simulation.restart(); newNodes
}) .append("circle")
.each((d: D3Node) => { .attr("fill", this.getNodeColor.bind(this))
// Initial position for nodes. This prevents blinking as following the tween transition doesn't always start right away .attr("class", "main")
d.x = self.viewCenter.x; .attr("r", this.params.graphConfig.nodeSize());
d.y = self.viewCenter.y;
});
newNodes var iconGroup = newNodes
.append("circle") .append("g")
.attr("fill", this.getNodeColor.bind(this)) .attr("class", "iconContainer")
.attr("class", "main") .attr("tabindex", 0)
.attr("r", this.params.graphConfig.nodeSize()); .attr("aria-label", (d: D3Node) => {
return this.retrieveNodeCaption(d);
var iconGroup = newNodes })
.append("g") .on("dblclick", function (_: MouseEvent, d: D3Node) {
.attr("class", "iconContainer")
.attr("tabindex", 0)
.attr("aria-label", (d: D3Node) => {
return this.retrieveNodeCaption(d);
})
.on("dblclick", function (_: MouseEvent, d: D3Node) {
// this is the <g> element
self.onNodeClicked(this.parentNode, d);
})
.on("click", function (_: MouseEvent, d: D3Node) {
// this is the <g> element
self.onNodeClicked(this.parentNode, d);
})
.on("keypress", function (event: KeyboardEvent, d: D3Node) {
if (event.charCode === Constants.KeyCodes.Space || event.charCode === Constants.KeyCodes.Enter) {
event.stopPropagation();
// this is the <g> element // this is the <g> element
self.onNodeClicked(this.parentNode, d); self.onNodeClicked(this.parentNode, d);
} })
}); .on("click", function (_: MouseEvent, d: D3Node) {
var nodeSize = this.params.graphConfig.nodeSize(); // this is the <g> element
var bgsize = nodeSize + 1; self.onNodeClicked(this.parentNode, d);
})
.on("keypress", function (event: KeyboardEvent, d: D3Node) {
if (event.charCode === Constants.KeyCodes.Space || event.charCode === Constants.KeyCodes.Enter) {
event.stopPropagation();
// this is the <g> element
self.onNodeClicked(this.parentNode, d);
}
});
var nodeSize = this.params.graphConfig.nodeSize();
var bgsize = nodeSize + 1;
iconGroup iconGroup
.append("rect") .append("rect")
.attr("x", -bgsize) .attr("x", -bgsize)
.attr("y", -bgsize) .attr("y", -bgsize)
.attr("width", bgsize * 2) .attr("width", bgsize * 2)
.attr("height", bgsize * 2) .attr("height", bgsize * 2)
.attr("fill-opacity", (d: D3Node) => { .attr("fill-opacity", (d: D3Node) => {
return this.params.graphConfig.nodeIconKey() ? 1 : 0; return this.params.graphConfig.nodeIconKey() ? 1 : 0;
}) })
.attr("class", "icon-background"); .attr("class", "icon-background");
// Possible icon: if xlink:href is undefined, the image won't show // Possible icon: if xlink:href is undefined, the image won't show
iconGroup iconGroup
.append("svg:image") .append("svg:image")
.attr("xlink:href", (d: D3Node) => { .attr("xlink:href", (d: D3Node) => {
return D3ForceGraph.computeImageData(d, this.params.graphConfig); return D3ForceGraph.computeImageData(d, this.params.graphConfig);
}) })
.attr("x", -nodeSize) .attr("x", -nodeSize)
.attr("y", -nodeSize) .attr("y", -nodeSize)
.attr("height", nodeSize * 2) .attr("height", nodeSize * 2)
.attr("width", nodeSize * 2) .attr("width", nodeSize * 2)
.attr("class", "icon"); .attr("class", "icon");
newNodes newNodes
.append("text") .append("text")
.attr("class", "caption") .attr("class", "caption")
.attr("dx", D3ForceGraph.TEXT_DX) .attr("dx", D3ForceGraph.TEXT_DX)
.attr("dy", ".35em") .attr("dy", ".35em")
.text((d: D3Node) => { .text((d: D3Node) => {
return this.retrieveNodeCaption(d); return this.retrieveNodeCaption(d);
}); });
this.nodeSelection = newNodes.merge(this.nodeSelection);
this.nodeSelection = newNodes.merge(this.nodeSelection);
}
return newNodes; return newNodes;
} }
@@ -967,34 +970,36 @@ export class D3ForceGraph implements GraphRenderer {
* Remove LoadMore subassembly for existing nodes that show all their children in the graph * Remove LoadMore subassembly for existing nodes that show all their children in the graph
*/ */
private updateLoadMore(nodeSelection: d3.Selection<Element, any, any, any>) { private updateLoadMore(nodeSelection: d3.Selection<Element, any, any, any>) {
const self = this; if (nodeSelection) {
nodeSelection.selectAll(".loadmore").remove(); const self = this;
nodeSelection.selectAll(".loadmore").remove();
var nodeSize = this.params.graphConfig.nodeSize(); var nodeSize = this.params.graphConfig.nodeSize();
const rootSelectionG = nodeSelection const rootSelectionG = nodeSelection
.filter((d: D3Node) => { .filter((d: D3Node) => {
return !!d._isRoot && !!d._pagination; return !!d._isRoot && !!d._pagination;
}) })
.append("g") .append("g")
.attr("class", "loadmore"); .attr("class", "loadmore");
this.createPaginationControl(rootSelectionG, nodeSize); this.createPaginationControl(rootSelectionG, nodeSize);
const nodeNeighborMap = D3ForceGraph.countEdges(this.linkSelection.data()); const nodeNeighborMap = D3ForceGraph.countEdges(this.linkSelection.data());
const missingNeighborNonRootG = nodeSelection const missingNeighborNonRootG = nodeSelection
.filter((d: D3Node) => { .filter((d: D3Node) => {
return !( return !(
d._isRoot || d._isRoot ||
(d._outEAllLoaded && (d._outEAllLoaded &&
d._inEAllLoaded && d._inEAllLoaded &&
nodeNeighborMap.get(d.id) >= d._outEdgeIds.length + d._inEdgeIds.length) nodeNeighborMap.get(d.id) >= d._outEdgeIds.length + d._inEdgeIds.length)
); );
}) })
.append("g") .append("g")
.attr("class", "loadmore"); .attr("class", "loadmore");
this.createLoadMoreControl(missingNeighborNonRootG, nodeSize); this.createLoadMoreControl(missingNeighborNonRootG, nodeSize);
// Don't color icons individually, just the definitions // Don't color icons individually, just the definitions
this.svg.selectAll("#loadMoreIcon ellipse").attr("fill", this.params.graphConfig.nodeColor()); this.svg.selectAll("#loadMoreIcon ellipse").attr("fill", this.params.graphConfig.nodeColor());
}
} }
/** /**
+21 -13
View File
@@ -1,6 +1,6 @@
import * as DataModels from "../Contracts/DataModels";
import * as Q from "q"; import * as Q from "q";
import * as sinon from "sinon"; import * as sinon from "sinon";
import * as DataModels from "../Contracts/DataModels";
import * as ViewModels from "../Contracts/ViewModels"; import * as ViewModels from "../Contracts/ViewModels";
import * as QueryUtils from "./QueryUtils"; import * as QueryUtils from "./QueryUtils";
@@ -101,12 +101,16 @@ describe("Query Utils", () => {
}); });
it("should not proceed with subsequent queries if the first one errors out", (done) => { it("should not proceed with subsequent queries if the first one errors out", (done) => {
const queryStub = sinon.stub().returns(Q.reject("Error injected for testing purposes")); try {
QueryUtils.queryPagesUntilContentPresent(0, queryStub).finally(() => { const queryStub = sinon.stub().returns(Q.reject("Error injected for testing purposes"));
expect(queryStub.callCount).toBe(1); QueryUtils.queryPagesUntilContentPresent(0, queryStub).finally(() => {
expect(queryStub.getCall(0).args[0]).toBe(0); expect(queryStub.callCount).toBe(1);
done(); expect(queryStub.getCall(0).args[0]).toBe(0);
}); done();
});
} catch (error) {
console.error(error);
}
}); });
}); });
@@ -176,12 +180,16 @@ describe("Query Utils", () => {
}); });
it("should not proceed with subsequent fetches if the first one errors out", (done) => { it("should not proceed with subsequent fetches if the first one errors out", (done) => {
const queryStub = sinon.stub().returns(Q.reject("Error injected for testing purposes")); try {
QueryUtils.queryAllPages(queryStub).finally(() => { const queryStub = sinon.stub().returns(Q.reject("Error injected for testing purposes"));
expect(queryStub.callCount).toBe(1); QueryUtils.queryAllPages(queryStub).finally(() => {
expect(queryStub.getCall(0).args[0]).toBe(0); expect(queryStub.callCount).toBe(1);
done(); expect(queryStub.getCall(0).args[0]).toBe(0);
}); done();
});
} catch (error) {
console.error(error);
}
}); });
}); });
}); });
+9
View File
@@ -16,3 +16,12 @@ if (typeof window.URL.createObjectURL === "undefined") {
require("jquery-ui-dist/jquery-ui"); require("jquery-ui-dist/jquery-ui");
(<any>global).TextEncoder = TextEncoder; (<any>global).TextEncoder = TextEncoder;
(<any>global).TextDecoder = TextDecoder; (<any>global).TextDecoder = TextDecoder;
// In Node v7 unhandled promise rejections
if (process.env.LISTENING_TO_UNHANDLED_REJECTION !== "true") {
process.on("unhandledRejection", (reason) => {
console.error("reason", reason);
});
// Avoid memory leak by adding too many listeners
process.env.LISTENING_TO_UNHANDLED_REJECTION = "true";
}