Skip to content

Commit

Permalink
[tests] Improve tests
Browse files Browse the repository at this point in the history
  • Loading branch information
totallynotvaishnav committed Jul 18, 2022
1 parent cc6efa6 commit 9e9756c
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 13 deletions.
18 changes: 13 additions & 5 deletions test/netjsongraph.calc.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@ describe("Test netjsongraph function utils", () => {
properties: {
name: "Node",
color: "red",
location: {
lng: 0,
lat: 0,
},
},
linkCount: 1,
local_addresses: ["192.168.0.01", "192.168.0.02", "192.168.0.03"],
Expand All @@ -57,6 +61,10 @@ describe("Test netjsongraph function utils", () => {
color: "red",
id: 0,
label: "test",
location: {
lng: 0,
lat: 0,
},
links: 1,
localAddresses: ["192.168.0.01", "192.168.0.02", "192.168.0.03"],
name: "Node",
Expand All @@ -69,13 +77,13 @@ describe("Test netjsongraph function utils", () => {
{
id: 0,
label: "test",
name: "Node",
location: {
lng: 0,
lat: 0,
},
properties: {
name: "Node",
color: "red",
location: {
lng: 0,
lat: 0,
},
time: "2019-04-03T05:06:54.000Z",
},
linkCount: 1,
Expand Down
34 changes: 26 additions & 8 deletions test/netjsongraph.render.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,18 +68,36 @@ describe("Test netjsongraph setConfig", () => {
});
test("Modify el config", () => {
const obj1 = new NetJSONGraph([JSONFILE, JSONFILE]);
// unused variables is required in this test
// eslint-disable-next-line no-unused-vars
const obj2 = new NetJSONGraph([JSONFILE, JSONFILE], {
el: document.getElementsByTagName("body")[0],
expect(obj1.config.el).toBeUndefined();
obj1.setConfig({});
expect(obj1.el).toBe(document.body);

const container = document.createElement("div");
document.body.appendChild(container);
const obj2 = new NetJSONGraph([JSONFILE, JSONFILE]);
obj2.setConfig({
el: container,
});
// eslint-disable-next-line no-unused-vars
const obj3 = new NetJSONGraph([JSONFILE, JSONFILE], {
el: "error",
expect(obj2.config.el).toBe(container);
obj2.setConfig({});
expect(obj2.el).toBe(container);

const obj3 = new NetJSONGraph([JSONFILE, JSONFILE]);
obj3.setConfig();
expect(obj3.el).toBe(document.body);

container.setAttribute("id", "container");
const obj4 = new NetJSONGraph([JSONFILE, JSONFILE]);
obj4.setConfig({
el: "container",
});
expect(obj4.el).toBe(container);
document.body.removeChild(container);

obj1.setConfig({
el: "error",
el: "container",
});
expect(obj1.el).toBe(document.body);
});
});

Expand Down

0 comments on commit 9e9756c

Please sign in to comment.