Skip to content

Commit

Permalink
Merge pull request #274 from magjac/misc-test-clean-up
Browse files Browse the repository at this point in the history
Misc test clean up
  • Loading branch information
magjac committed Jan 22, 2023
2 parents 9529646 + 508d58f commit 83d7b0f
Show file tree
Hide file tree
Showing 62 changed files with 144 additions and 150 deletions.
3 changes: 1 addition & 2 deletions test/addImage-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,9 @@ import jsdom from "./jsdom.js";
import * as d3 from "d3-selection";
import * as d3_graphviz from "../index.js";


it("graphviz().addImage() adds images to use in graph.", async () => {
var window = global.window = jsdom('<div id="graph"></div>');
var document = global.document = window.document;
global.document = window.document;
var graphviz;
await new Promise((resolve) => {
graphviz = d3_graphviz.graphviz("#graph")
Expand Down
2 changes: 1 addition & 1 deletion test/attributer-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import * as d3_graphviz from "../index.js";

it("The attributer is called during rendering.", async () => {
var window = global.window = jsdom('<div id="graph"></div>');
var document = global.document = window.document;
global.document = window.document;

var graphviz = d3_graphviz.graphviz("#graph");
await new Promise(resolve => {
Expand Down
2 changes: 1 addition & 1 deletion test/data-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import * as d3_graphviz from "../index.js";

it("data() returns the data saved by dot().", async () => {
var window = global.window = jsdom('<div id="graph"></div>');
var document = global.document = window.document;
global.document = window.document;

var graphviz = d3_graphviz.graphviz("#graph");
await new Promise(resolve => {
Expand Down
2 changes: 1 addition & 1 deletion test/destroy-shared-worker-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ it(".destroy() deletes the Graphviz instance from the container element (shared
<div id="graph"></div>
`,
);
global.document = window.document;
global.document = window.document;
global.SharedWorker = SharedWorker;

var graphviz = d3_graphviz.graphviz("#graph", { useSharedWorker: true });
Expand Down
2 changes: 1 addition & 1 deletion test/destroy-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import * as d3_graphviz from "../index.js";

it(".destroy() deletes the Graphviz instance from the container element", async () => {
var window = global.window = jsdom('<div id="graph"></div>');
var document = global.document = window.document;
global.document = window.document;
var graphviz = d3_graphviz.graphviz("#graph", { useWorker: false });

await new Promise(resolve => {
Expand Down
8 changes: 4 additions & 4 deletions test/destroy-worker-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ it(".destroy() deletes the Graphviz instance from the container element (worker
<div id="graph"></div>
`,
);
var document = global.document = window.document;
global.document = window.document;
global.Blob = function (jsarray) {
return new Function(jsarray[0]);
}
Expand Down Expand Up @@ -44,11 +44,11 @@ it(".destroy() closes the worker", async () => {
<div id="graph"></div>
`,
);
var document = global.document = window.document;
var Blob = global.Blob = function (jsarray) {
global.document = window.document;
global.Blob = function (jsarray) {
return new Function(jsarray[0]);
}
var createObjectURL = window.URL.createObjectURL = function (js) {
window.URL.createObjectURL = function (js) {
return js;
}
global.Worker = Worker;
Expand Down
2 changes: 1 addition & 1 deletion test/dot-data-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import * as d3_graphviz from "../index.js";

it("data extraction", async () => {
var window = global.window = jsdom('<div id="graph"></div>');
var document = global.document = window.document;
global.document = window.document;

var graphviz = d3_graphviz.graphviz("#graph");
await new Promise(resolve => {
Expand Down
2 changes: 1 addition & 1 deletion test/dot-empty-node-id-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import * as d3_graphviz from "../index.js";

it("renderDot() renders a node with an empty string as node_id.", async () => {
var window = global.window = jsdom('<div id="graph"></div>');
var document = global.document = window.document;
global.document = window.document;

var graphviz = d3_graphviz.graphviz("#graph");

Expand Down
2 changes: 1 addition & 1 deletion test/dot-no-worker-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import Worker from "tiny-worker";

async function do_test(useWorker, html) {
var window = global.window = jsdom(html);
var document = global.document = window.document;
global.document = window.document;
global.Blob = function (jsarray) {
return new Function(jsarray[0]);
}
Expand Down
2 changes: 1 addition & 1 deletion test/dot-shared-worker-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ describe("dot()", () => {
`,
);

var document = global.document = window.document;
global.document = window.document;
global.SharedWorker = SharedWorker;
graphviz = d3_graphviz.graphviz("#graph", { useSharedWorker: true });

Expand Down
10 changes: 5 additions & 5 deletions test/dot-viewport-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ var bbHeight = simpleHeight - margin * 2;

it("DOT without viewport", async () => {
var window = global.window = jsdom('<div id="graph"></div>');
var document = global.document = window.document;
global.document = window.document;
var graphviz = d3_graphviz.graphviz("#graph");
await new Promise(resolve => {
graphviz
Expand Down Expand Up @@ -42,7 +42,7 @@ it("DOT without viewport", async () => {

it("DOT with viewport scale 2", async () => {
var window = global.window = jsdom('<div id="graph"></div>');
var document = global.document = window.document;
global.document = window.document;
var graphviz = d3_graphviz.graphviz("#graph");
await new Promise(resolve => {
graphviz
Expand Down Expand Up @@ -74,7 +74,7 @@ it("DOT with viewport scale 2", async () => {

it("DOT with viewport scale 0.5", async () => {
var window = global.window = jsdom('<div id="graph"></div>');
var document = global.document = window.document;
global.document = window.document;
var graphviz = d3_graphviz.graphviz("#graph");
await new Promise(resolve => {
graphviz
Expand Down Expand Up @@ -105,7 +105,7 @@ it("DOT with viewport scale 0.5", async () => {

it("DOT with viewport scale 1.5", async () => {
var window = global.window = jsdom('<div id="graph"></div>');
var document = global.document = window.document;
global.document = window.document;
var graphviz = d3_graphviz.graphviz("#graph");
await new Promise(resolve => {
graphviz
Expand Down Expand Up @@ -137,7 +137,7 @@ it("DOT with viewport scale 1.5", async () => {

it("DOT with viewport scale 2 and original size", async () => {
var window = global.window = jsdom('<div id="graph"></div>');
var document = global.document = window.document;
global.document = window.document;
var graphviz = d3_graphviz.graphviz("#graph");
await new Promise(resolve => {
graphviz
Expand Down
6 changes: 3 additions & 3 deletions test/dot-worker-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@ describe("dot()", () => {
`,
);

var document = global.document = window.document;
var Blob = global.Blob = function (jsarray) {
global.document = window.document;
global.Blob = function (jsarray) {
return new Function(jsarray[0]);
}
var createObjectURL = window.URL.createObjectURL = function (js) {
window.URL.createObjectURL = function (js) {
return js;
}
global.Worker = Worker;
Expand Down
6 changes: 3 additions & 3 deletions test/dot-worker-through-text-javascript-tag-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@ describe("dot()", () => {
<div id="graph"></div>
`,
);
var document = global.document = window.document;
var Blob = global.Blob = function (jsarray) {
global.document = window.document;
global.Blob = function (jsarray) {
return new Function(jsarray[0]);
}
var createObjectURL = window.URL.createObjectURL = function (js) {
window.URL.createObjectURL = function (js) {
return js;
}
global.Worker = Worker;
Expand Down
12 changes: 5 additions & 7 deletions test/drawEdge-style-invis-test.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
import assert from "assert";
import it from "./it.js";
import jsdom from "./jsdom.js";
import deepEqualData from "./deepEqualData.js";
import * as d3 from "d3-selection";
import * as d3_graphviz from "../index.js";
import {translatePointsAttribute} from "../src/svg.js"

it("No edge is drawn when style is invis.", async () => {
var window = global.window = jsdom('<div id="expected-graph"></div><div id="actual-graph"></div>');
var document = global.document = window.document;
global.document = window.document;
var expectedGraph = d3.select("#expected-graph");
var actualGraph = d3.select("#actual-graph");
var actualGraphviz;
Expand Down Expand Up @@ -54,7 +52,7 @@ it("No edge is drawn when style is invis.", async () => {

it("Updating of an edge with style invis is ignored.", async () => {
var window = global.window = jsdom('<div id="expected-graph"></div><div id="actual-graph"></div>');
var document = global.document = window.document;
global.document = window.document;
var expectedGraph = d3.select("#expected-graph");
var actualGraph = d3.select("#actual-graph");
var actualGraphviz;
Expand Down Expand Up @@ -101,7 +99,7 @@ it("Updating of an edge with style invis is ignored.", async () => {

it("Moving an edge with style invis is ignored.", async () => {
var window = global.window = jsdom('<div id="expected-graph"></div><div id="actual-graph"></div>');
var document = global.document = window.document;
global.document = window.document;
var expectedGraph = d3.select("#expected-graph");
var actualGraph = d3.select("#actual-graph");
var actualGraphviz;
Expand Down Expand Up @@ -147,7 +145,7 @@ it("Moving an edge with style invis is ignored.", async () => {

it("Removal of an edge with style invis is allowed.", async () => {
var window = global.window = jsdom('<div id="expected-graph"></div><div id="actual-graph"></div>');
var document = global.document = window.document;
global.document = window.document;
var expectedGraph = d3.select("#expected-graph");
var actualGraph = d3.select("#actual-graph");
var actualGraph = d3.select("#actual-graph");
Expand Down Expand Up @@ -193,7 +191,7 @@ it("Removal of an edge with style invis is allowed.", async () => {

it("Changing an edge with style invis to a visible edge is allowed.", async () => {
var window = global.window = jsdom('<div id="expected-graph"></div><div id="actual-graph"></div>');
var document = global.document = window.document;
global.document = window.document;
var expectedGraph = d3.select("#expected-graph");
var actualGraph = d3.select("#actual-graph");
var actualGraphviz;
Expand Down
22 changes: 11 additions & 11 deletions test/drawEdge-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import * as d3_graphviz from "../index.js";

it("Check our understanding of how Graphviz draws edges.", async () => {
var window = global.window = jsdom('<div id="graph"></div>');
var document = global.document = window.document;
global.document = window.document;
var graphviz = d3_graphviz.graphviz("#graph");

await new Promise(resolve => {
Expand Down Expand Up @@ -96,7 +96,7 @@ it("Check our understanding of how Graphviz draws edges.", async () => {

it("drawEdge() draws an edge in the same way as Graphviz does", async () => {
var window = global.window = jsdom('<div id="graph"></div>');
var document = global.document = window.document;
global.document = window.document;
var graphviz = d3_graphviz.graphviz("#graph");
await new Promise(resolve => {
graphviz
Expand Down Expand Up @@ -196,7 +196,7 @@ it("drawEdge() draws an edge in the same way as Graphviz does", async () => {

it("drawEdge() draws an edge even if the length is zero", async () => {
var window = global.window = jsdom('<div id="graph"></div>');
var document = global.document = window.document;
global.document = window.document;
var graphviz = d3_graphviz.graphviz("#graph");
await new Promise(resolve => {
graphviz
Expand Down Expand Up @@ -239,7 +239,7 @@ it("drawEdge() draws an edge even if the length is zero", async () => {

it("drawEdge() draws an edge with an URL attribute in the same way as Graphviz does", async () => {
var window = global.window = jsdom('<div id="graph"></div>');
var document = global.document = window.document;
global.document = window.document;
var graphviz = d3_graphviz.graphviz("#graph");
await new Promise(resolve => {
graphviz
Expand Down Expand Up @@ -338,7 +338,7 @@ it("drawEdge() draws an edge with an URL attribute in the same way as Graphviz d

it("drawEdge() draws an edge with an tooltip attribute in the same way as Graphviz does", async () => {
var window = global.window = jsdom('<div id="graph"></div>');
var document = global.document = window.document;
global.document = window.document;
var graphviz = d3_graphviz.graphviz("#graph");
await new Promise(resolve => {
graphviz
Expand Down Expand Up @@ -437,7 +437,7 @@ it("drawEdge() draws an edge with an tooltip attribute in the same way as Graphv

it("insertDrawnEdge() inserts the currently drawn edge into the joined data structure so that it can be animated when the graph is re-rendered", async () => {
var window = global.window = jsdom('<div id="graph"></div>');
var document = global.document = window.document;
global.document = window.document;
var graphviz = d3_graphviz.graphviz("#graph");
await new Promise(resolve => {
graphviz
Expand Down Expand Up @@ -495,7 +495,7 @@ it("insertDrawnEdge() inserts the currently drawn edge into the joined data stru

it("removeDrawnEdge() removes the edge currently being drawn", async () => {
var window = global.window = jsdom('<div id="graph"></div>');
var document = global.document = window.document;
global.document = window.document;
var graphviz = d3_graphviz.graphviz("#graph")
await new Promise(resolve => {
graphviz
Expand Down Expand Up @@ -558,7 +558,7 @@ it("removeDrawnEdge() removes the edge currently being drawn", async () => {

it("updateDrawnEdge modifies the start and end points and the attributes of an edge", async () => {
var window = global.window = jsdom('<div id="graph"></div>');
var document = global.document = window.document;
global.document = window.document;
var graphviz = d3_graphviz.graphviz("#graph");
await new Promise(resolve => {
graphviz
Expand Down Expand Up @@ -634,7 +634,7 @@ it("updateDrawnEdge modifies the start and end points and the attributes of an e

it("moveDrawnEdgeEndPoint modifies the end points of an edge", async () => {
var window = global.window = jsdom('<div id="graph"></div>');
var document = global.document = window.document;
global.document = window.document;
var graphviz = d3_graphviz.graphviz("#graph");
await new Promise(resolve => {
graphviz
Expand Down Expand Up @@ -692,7 +692,7 @@ it("moveDrawnEdgeEndPoint modifies the end points of an edge", async () => {

it("drawnEdgeSelection return a selection containing the edge currently being drawn", async () => {
var window = global.window = jsdom('<div id="graph"></div>');
var document = global.document = window.document;
global.document = window.document;
var graphviz = d3_graphviz.graphviz("#graph");
await new Promise(resolve => {
graphviz
Expand Down Expand Up @@ -747,7 +747,7 @@ it("drawnEdgeSelection return a selection containing the edge currently being dr

it("Attempts to operate on an edge without drawing one first is handled gracefully", async () => {
var window = global.window = jsdom('<div id="graph"></div>');
var document = global.document = window.document;
global.document = window.document;
var graphviz = d3_graphviz.graphviz("#graph");
await new Promise(resolve => {
graphviz
Expand Down
2 changes: 1 addition & 1 deletion test/drawNode-shape-box-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {translatePointsAttribute} from "../src/svg.js"

it("Verify that box shape is drawn exactly as Graphviz does.", async () => {
var window = global.window = jsdom('<div id="expected-graph"></div><div id="actual-graph"></div>');
var document = global.document = window.document;
global.document = window.document;
var expectedGraph = d3.select("#expected-graph");
var actualGraph = d3.select("#actual-graph");
var actualGraphviz;
Expand Down
2 changes: 1 addition & 1 deletion test/drawNode-shape-circle-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import * as d3_graphviz from "../index.js";

it("Verify that circle shape is drawn exactly as Graphviz does.", async () => {
var window = global.window = jsdom('<div id="expected-graph"></div><div id="actual-graph"></div>');
var document = global.document = window.document;
global.document = window.document;
var expectedGraph = d3.select("#expected-graph");
var actualGraph = d3.select("#actual-graph");
var actualGraphviz;
Expand Down
2 changes: 1 addition & 1 deletion test/drawNode-shape-cylinder-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {translateDAttribute} from "../src/svg.js"

it("Verify that cylinder shape is drawn exactly as Graphviz does.", async () => {
var window = global.window = jsdom('<div id="expected-graph"></div><div id="actual-graph"></div>');
var document = global.document = window.document;
global.document = window.document;
var expectedGraph = d3.select("#expected-graph");
var actualGraph = d3.select("#actual-graph");
var actualGraphviz;
Expand Down
8 changes: 4 additions & 4 deletions test/drawNode-shape-default-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import * as d3_graphviz from "../index.js";

it("Verify that default shape is drawn exactly as Graphviz does.", async () => {
var window = global.window = jsdom('<div id="expected-graph"></div><div id="actual-graph"></div>');
var document = global.document = window.document;
global.document = window.document;

var expectedGraph = d3.select("#expected-graph");
var actualGraph = d3.select("#actual-graph");
Expand Down Expand Up @@ -85,7 +85,7 @@ it("Verify that default shape is drawn exactly as Graphviz does.", async () => {

it("Verify that default shape with style filled is drawn exactly as Graphviz does.", async () => {
var window = global.window = jsdom('<div id="expected-graph"></div><div id="actual-graph"></div>');
var document = global.document = window.document;
global.document = window.document;
var expectedGraph = d3.select("#expected-graph");
var actualGraph = d3.select("#actual-graph");
var actualGraphviz;
Expand Down Expand Up @@ -162,7 +162,7 @@ it("Verify that default shape with style filled is drawn exactly as Graphviz doe

it("Default shape with style filled without fillcolor, but with color, uses color as fillcolor.", async () => {
var window = global.window = jsdom('<div id="expected-graph"></div><div id="actual-graph"></div>');
var document = global.document = window.document;
global.document = window.document;
var expectedGraph = d3.select("#expected-graph");
var actualGraph = d3.select("#actual-graph");
var actualGraphviz;
Expand Down Expand Up @@ -241,7 +241,7 @@ it("Default shape with style filled without fillcolor, but with color, uses colo

it("Verify that default shape with label is drawn exactly as Graphviz does.", async () => {
var window = global.window = jsdom('<div id="expected-graph"></div><div id="actual-graph"></div>');
var document = global.document = window.document;
global.document = window.document;
var expectedGraph = d3.select("#expected-graph");
var actualGraph = d3.select("#actual-graph");
var actualGraphviz;
Expand Down
Loading

0 comments on commit 83d7b0f

Please sign in to comment.