forked from antonioru/beautiful-react-diagrams
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDiagramNode.spec.js
49 lines (40 loc) · 1.53 KB
/
DiagramNode.spec.js
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
import React from 'react';
import { render, cleanup } from '@testing-library/react';
import DiagramContext from '../dist/Context/DiagramContext';
import DiagramNode from '../dist/Diagram/DiagramNode/DiagramNode';
describe('DiagramNode component', () => {
afterEach(cleanup);
const contextMock = {
canvas: {},
ports: { 'port-foo': document.createElement('div') },
nodes: { 'node-foo': document.createElement('div') },
};
it('should render without explode', () => {
const { container } = render(
<DiagramContext.Provider value={contextMock}>
<DiagramNode id="port-foo" content="Foo" coordinates={[10, 10]} />
</DiagramContext.Provider>,
);
should.exist(container);
expect(container.querySelector('div')).to.exist;
});
it('should have default classes', () => {
const { container } = render(
<DiagramContext.Provider value={contextMock}>
<DiagramNode id="port-foo" content="Foo" coordinates={[10, 10]} />
</DiagramContext.Provider>,
);
const wrapper = container.querySelector('div');
expect(wrapper.getAttribute('class').split(' ')).to.include.members(['bi', 'bi-diagram-node']);
});
it('should call onRemoveNode callback on onmount', () => {
const spy = sinon.spy();
const { rerender } = render(
<DiagramContext.Provider value={contextMock}>
<DiagramNode id="port-foo" content="Foo" coordinates={[10, 10]} onNodeRemove={spy} />
</DiagramContext.Provider>,
);
rerender(null);
expect(spy.called).to.be.true;
});
});