-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathogma.test.tsx
79 lines (71 loc) · 2.09 KB
/
ogma.test.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
import React from "react";
import { render } from "./utils";
import OgmaLib, { RawGraph } from "@linkurious/ogma";
import { Ogma, useOgma } from "../src";
const graph: RawGraph = {
nodes: [
{ id: 0, attributes: { color: "red", x: 0, y: 0 } },
{ id: 1, attributes: { color: "green", x: 25, y: 0 } },
{ id: 2, attributes: { color: "green", x: 25, y: 0 } },
],
edges: [
{ source: 0, target: 1 },
{ source: 0, target: 2 },
],
};
describe("Ogma", () => {
let div: HTMLDivElement;
beforeEach(() => (div = document.createElement("div")));
it("Ogma container renders without crashing", () => {
render(<Ogma graph={graph} />, div);
});
it("Supports ref interface", () => {
const ref = React.createRef<OgmaLib>();
render(<Ogma ref={ref} graph={graph} />, div);
expect(ref.current).toBeDefined();
expect(ref.current).toBeInstanceOf(OgmaLib);
});
it("Ogma container renders with onReady callback", () => {
return new Promise((resolve) => {
render(<Ogma graph={graph} onReady={(ogma) => resolve(ogma)} />, div);
}).then((ogma) => {
expect(ogma).toBeInstanceOf(OgmaLib);
});
});
it("Ogma container renders and takes options", () => {
const backgroundColor = "red";
const minimumWidth = 500;
return new Promise((resolve) => {
const onReady = (ogma: OgmaLib) => {
const options = ogma.getOptions();
expect(options.backgroundColor).toBe(backgroundColor);
expect(options.minimumWidth).toBe(minimumWidth);
return resolve(null);
};
render(
<Ogma
graph={graph}
onReady={onReady}
options={{ backgroundColor, minimumWidth }}
/>,
div
);
});
});
it("Ogma container passes the ogma instance to children", () => {
return new Promise((resolve) => {
const Component = () => {
const ogma = useOgma();
expect(ogma).toBeInstanceOf(OgmaLib);
resolve(null);
return <></>;
};
render(
<Ogma graph={graph}>
<Component />
</Ogma>,
div
);
});
});
});