@neo4j-nvl/react 2.0.0 → 2.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (31) hide show
  1. package/CHANGELOG.md +25 -1
  2. package/README.md +8 -0
  3. package/lib/basic-wrapper/BasicNvlWrapper.d.ts +58 -32
  4. package/lib/basic-wrapper/BasicNvlWrapper.js +129 -143
  5. package/lib/index.d.ts +5 -8
  6. package/lib/index.js +3 -3
  7. package/lib/interactive-nvl-wrapper/InteractionHandlers.d.ts +8 -8
  8. package/lib/interactive-nvl-wrapper/InteractionHandlers.js +62 -59
  9. package/lib/interactive-nvl-wrapper/InteractiveNvlWrapper.d.ts +5 -4
  10. package/lib/interactive-nvl-wrapper/InteractiveNvlWrapper.js +55 -42
  11. package/lib/interactive-nvl-wrapper/hooks.d.ts +4 -4
  12. package/lib/interactive-nvl-wrapper/hooks.js +24 -27
  13. package/lib/interactive-nvl-wrapper/types.d.ts +24 -9
  14. package/lib/interactive-nvl-wrapper/types.js +0 -1
  15. package/lib/static-picture-wrapper/StaticPictureWrapper.d.ts +21 -15
  16. package/lib/static-picture-wrapper/StaticPictureWrapper.js +77 -55
  17. package/lib/utils/constants.d.ts +1 -1
  18. package/lib/utils/constants.js +4 -2
  19. package/lib/utils/graph-comparison.d.ts +5 -5
  20. package/lib/utils/graph-comparison.js +53 -68
  21. package/lib/utils/hooks.d.ts +2 -2
  22. package/lib/utils/hooks.js +10 -11
  23. package/package.json +24 -10
  24. package/lib/__tests__/BasicNvlWrapper.test.d.ts +0 -1
  25. package/lib/__tests__/BasicNvlWrapper.test.js +0 -159
  26. package/lib/__tests__/InteractiveNvlWrapper.test.d.ts +0 -1
  27. package/lib/__tests__/InteractiveNvlWrapper.test.js +0 -396
  28. package/lib/__tests__/StaticPictureWrapper.test.d.ts +0 -1
  29. package/lib/__tests__/StaticPictureWrapper.test.js +0 -85
  30. package/lib/__tests__/index.test.d.ts +0 -1
  31. package/lib/__tests__/index.test.js +0 -8
@@ -1,85 +0,0 @@
1
- import { jsx as _jsx } from "react/jsx-runtime";
2
- import '@testing-library/jest-dom';
3
- import { render, waitFor } from '@testing-library/react';
4
- import { StaticPictureWrapper } from '../static-picture-wrapper/StaticPictureWrapper';
5
- jest.mock('@neo4j-nvl/base', () => {
6
- const mockNVL = jest
7
- .fn()
8
- .mockImplementation((_element, _nodes, _rels, _nvlOptions, callbacks) => {
9
- setTimeout(() => {
10
- callbacks.onLayoutDone?.();
11
- callbacks.onZoomTransitionDone?.();
12
- }, 0);
13
- return {
14
- getNodes: jest.fn().mockReturnValue([
15
- { id: '0', x: 0, y: 0 },
16
- { id: '1', x: 100, y: 100 }
17
- ]),
18
- fit: jest.fn(),
19
- getImageDataUrl: jest.fn().mockReturnValue('data:image/png;base64,...mock-png...'),
20
- getSvgDataUrl: jest.fn().mockResolvedValue('data:image/svg+xml;charset=utf-8,...mock-svg...'),
21
- destroy: jest.fn()
22
- };
23
- });
24
- return mockNVL;
25
- });
26
- const NVLMock = jest.requireMock('@neo4j-nvl/base');
27
- describe('StaticPictureWrapper - format prop support', () => {
28
- const mockNodes = [
29
- { id: '0', caption: 'Node 0' },
30
- { id: '1', caption: 'Node 1' }
31
- ];
32
- const mockRels = [{ id: '01', from: '0', to: '1', caption: 'KNOWS' }];
33
- beforeEach(() => {
34
- NVLMock.mockClear();
35
- });
36
- const getMockNVLInstance = (index = 0) => {
37
- return NVLMock.mock.results[index]?.value;
38
- };
39
- it('Should pass nodes, relationships and options to NVL constructor', () => {
40
- const mockOptions = {
41
- layout: 'hierarchical',
42
- styling: {
43
- defaultNodeColor: 'red'
44
- }
45
- };
46
- render(_jsx(StaticPictureWrapper, { nodes: mockNodes, rels: mockRels, format: "png", nvlOptions: mockOptions, width: 250, height: 250 }));
47
- expect(NVLMock).toHaveBeenCalledWith(expect.any(HTMLDivElement), mockNodes, mockRels, mockOptions, expect.any(Object));
48
- });
49
- it('Should use getSvgDataUrl for SVG format', async () => {
50
- render(_jsx(StaticPictureWrapper, { nodes: mockNodes, rels: mockRels, format: "svg" }));
51
- await waitFor(() => {
52
- const mockInstance = getMockNVLInstance();
53
- expect(mockInstance.getSvgDataUrl).toHaveBeenCalled();
54
- expect(mockInstance.getImageDataUrl).not.toHaveBeenCalled();
55
- });
56
- });
57
- it('Should use getImageDataUrl for PNG format', async () => {
58
- render(_jsx(StaticPictureWrapper, { nodes: mockNodes, rels: mockRels, format: "png" }));
59
- await waitFor(() => {
60
- const mockInstance = getMockNVLInstance();
61
- expect(mockInstance.getSvgDataUrl).not.toHaveBeenCalled();
62
- expect(mockInstance.getImageDataUrl).toHaveBeenCalled();
63
- });
64
- });
65
- it('Should triggerer re-render when format prop changes', async () => {
66
- const { rerender } = render(_jsx(StaticPictureWrapper, { nodes: mockNodes, rels: mockRels, format: "png" }));
67
- await waitFor(() => {
68
- const mockInstance = getMockNVLInstance(0);
69
- expect(mockInstance.getSvgDataUrl).not.toHaveBeenCalled();
70
- expect(mockInstance.getImageDataUrl).toHaveBeenCalledTimes(1);
71
- });
72
- rerender(_jsx(StaticPictureWrapper, { nodes: mockNodes, rels: mockRels, format: "svg" }));
73
- await waitFor(() => {
74
- const mockInstance = getMockNVLInstance(1);
75
- expect(mockInstance.getSvgDataUrl).toHaveBeenCalledTimes(1);
76
- expect(mockInstance.getImageDataUrl).not.toHaveBeenCalled();
77
- });
78
- });
79
- it('Should clean up NVL instance on unmount', () => {
80
- const { unmount } = render(_jsx(StaticPictureWrapper, { nodes: mockNodes, rels: mockRels, format: "png" }));
81
- unmount();
82
- const mockInstance = getMockNVLInstance();
83
- expect(mockInstance.destroy).toHaveBeenCalled();
84
- });
85
- });
@@ -1 +0,0 @@
1
- export {};
@@ -1,8 +0,0 @@
1
- import * as exportedModules from '../index';
2
- jest.mock('@neo4j-nvl/layout-workers');
3
- describe('index', () => {
4
- test('provides the expected components', () => {
5
- const modules = Object.keys(exportedModules);
6
- expect(modules).toContain('BasicNvlWrapper');
7
- });
8
- });