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,6 +87,7 @@ 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();
if (monaco.editor) {
this.indexingPolicyEditor = monaco.editor.create(this.indexingPolicyDiv.current, { this.indexingPolicyEditor = monaco.editor.create(this.indexingPolicyDiv.current, {
value: value, value: value,
language: "json", language: "json",
@@ -99,6 +100,7 @@ export class IndexingPolicyComponent extends React.Component<
this.props.logIndexingPolicySuccessMessage(); this.props.logIndexingPolicySuccessMessage();
} }
} }
}
private onEditorContentChange = (): void => { private onEditorContentChange = (): void => {
const indexingPolicyEditorModel = this.indexingPolicyEditor.getModel(); const indexingPolicyEditorModel = this.indexingPolicyEditor.getModel();
@@ -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,6 +138,7 @@ 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 = () => {
if (document) {
const mouseoverEvent = document.createEvent("Events"); const mouseoverEvent = document.createEvent("Events");
mouseoverEvent.initEvent("mouseover", true, false); mouseoverEvent.initEvent("mouseover", true, false);
$(rootNode).find(".node")[0].dispatchEvent(mouseoverEvent); // [0] is v1 vertex $(rootNode).find(".node")[0].dispatchEvent(mouseoverEvent); // [0] is v1 vertex
@@ -145,11 +146,12 @@ describe("D3ForceGraph", () => {
// 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)
.args[1][0] as D3GraphNodeData;
expect(onHighlightedNode).not.toBe(null); expect(onHighlightedNode).not.toBe(null);
expect(onHighlightedNode.id).toEqual(v1Id); 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,8 +651,9 @@ 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 const line = newLinks
.append("path") .append("path")
.attr("class", "link") .attr("class", "link")
@@ -673,13 +674,15 @@ export class D3ForceGraph implements GraphRenderer {
} }
this.linkSelection = newLinks.merge(this.linkSelection); 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 = {};
const newNodes = this.nodeSelection if (this.nodeSelection) {
newNodes = this.nodeSelection
.enter() .enter()
.append("g") .append("g")
.attr("class", (d: D3Node) => { .attr("class", (d: D3Node) => {
@@ -784,7 +787,7 @@ export class D3ForceGraph implements GraphRenderer {
}); });
this.nodeSelection = newNodes.merge(this.nodeSelection); this.nodeSelection = newNodes.merge(this.nodeSelection);
}
return newNodes; return newNodes;
} }
@@ -967,6 +970,7 @@ 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>) {
if (nodeSelection) {
const self = this; const self = this;
nodeSelection.selectAll(".loadmore").remove(); nodeSelection.selectAll(".loadmore").remove();
@@ -996,6 +1000,7 @@ export class D3ForceGraph implements GraphRenderer {
// 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());
} }
}
/** /**
* Load neighbors of this node * Load neighbors of this node
+9 -1
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) => {
try {
const queryStub = sinon.stub().returns(Q.reject("Error injected for testing purposes")); const queryStub = sinon.stub().returns(Q.reject("Error injected for testing purposes"));
QueryUtils.queryPagesUntilContentPresent(0, queryStub).finally(() => { QueryUtils.queryPagesUntilContentPresent(0, queryStub).finally(() => {
expect(queryStub.callCount).toBe(1); expect(queryStub.callCount).toBe(1);
expect(queryStub.getCall(0).args[0]).toBe(0); expect(queryStub.getCall(0).args[0]).toBe(0);
done(); 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) => {
try {
const queryStub = sinon.stub().returns(Q.reject("Error injected for testing purposes")); const queryStub = sinon.stub().returns(Q.reject("Error injected for testing purposes"));
QueryUtils.queryAllPages(queryStub).finally(() => { QueryUtils.queryAllPages(queryStub).finally(() => {
expect(queryStub.callCount).toBe(1); expect(queryStub.callCount).toBe(1);
expect(queryStub.getCall(0).args[0]).toBe(0); expect(queryStub.getCall(0).args[0]).toBe(0);
done(); 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";
}