-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathNodeData.fromjson.test.tsx
198 lines (184 loc) · 5.73 KB
/
NodeData.fromjson.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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
// NodeData.fromjson.test.tsx
import { describe, it, expect } from 'vitest';
import { JsonToReactNode, JsonNodeData } from './NodeData';
describe('JsonToReactNode', () => {
it('should convert JSON node data to React node props correctly', () => {
const jsonNodeData: JsonNodeData = {
uniq_id: '123',
name: 'Test Node',
description: 'This is a test node',
tool: 'testTool',
nexts: ['456'],
true_next: '789',
false_next: null,
type: 'STEP',
ext: {
pos_x: 100,
pos_y: 200,
width: 250,
height: 150,
info: 'Additional info'
}
};
const expectedReactNodeProps = {
id: '123',
width: 250,
height: 150,
position: { x: 100, y: 200 },
data: {
type: 'STEP',
name: 'Test Node',
description: 'This is a test node',
tool: 'testTool',
nexts: ['456'],
true_next: '789',
false_next: null,
info: 'Additional info',
prevs: [],
}
};
const reactNodeProps = JsonToReactNode(jsonNodeData);
expect(reactNodeProps).toEqual(expectedReactNodeProps);
});
it('should handle missing optional fields in JSON data', () => {
const jsonNodeData: JsonNodeData = {
uniq_id: '456',
name: 'Another Node',
description: '',
tool: 'anotherTool',
nexts: [],
true_next: null,
false_next: null,
ext: {}
};
const expectedReactNodeProps = {
id: '456',
width: 200,
height: 200,
position: { x: 0, y: 0 },
data: {
type: 'STEP',
name: 'Another Node',
description: '',
tool: 'anotherTool',
nexts: [],
true_next: null,
false_next: null,
info: null,
prevs: [],
}
};
const reactNodeProps = JsonToReactNode(jsonNodeData);
expect(reactNodeProps).toEqual(expectedReactNodeProps);
});
it('should use a default type if not provided', () => {
const jsonNodeData: JsonNodeData = {
uniq_id: '789',
name: 'Type Missing Node',
description: 'This node has no type',
tool: 'defaultTool',
nexts: [],
true_next: null,
false_next: null,
ext: {
pos_x: 50,
pos_y: 75,
width: 100,
height: 100,
info: null
}
};
const expectedReactNodeProps = {
id: '789',
width: 100,
height: 100,
position: { x: 50, y: 75 },
data: {
type: 'STEP',
name: 'Type Missing Node',
description: 'This node has no type',
tool: 'defaultTool',
nexts: [],
true_next: null,
false_next: null,
info: null,
prevs: [],
}
};
const reactNodeProps = JsonToReactNode(jsonNodeData);
expect(reactNodeProps).toEqual(expectedReactNodeProps);
});
it('should handle info as null correctly', () => {
const jsonNodeData: JsonNodeData = {
uniq_id: '999',
name: 'Info Null Node',
description: 'This node has null info',
tool: 'testTool',
nexts: [],
true_next: null,
false_next: null,
ext: {
pos_x: 100,
pos_y: 200,
width: 200,
height: 100,
info: null,
},
};
const expectedReactNodeProps = {
id: '999',
width: 200,
height: 100,
position: { x: 100, y: 200 },
data: {
type: 'STEP',
name: 'Info Null Node',
description: 'This node has null info',
tool: 'testTool',
nexts: [],
true_next: null,
false_next: null,
info: null,
prevs: [],
},
};
const reactNodeProps = JsonToReactNode(jsonNodeData);
expect(reactNodeProps).toEqual(expectedReactNodeProps);
});
it('should handle undefined info correctly', () => {
const jsonNodeData: JsonNodeData = {
uniq_id: '999',
name: 'Info Undefined Node',
description: 'This node has undefined info',
tool: 'testTool',
nexts: [],
true_next: null,
false_next: null,
ext: {
pos_x: 100,
pos_y: 200,
width: 200,
height: 100,
},
};
const expectedReactNodeProps = {
id: '999',
width: 200,
height: 100,
position: { x: 100, y: 200 },
data: {
type: 'STEP',
name: 'Info Undefined Node',
description: 'This node has undefined info',
tool: 'testTool',
nexts: [],
true_next: null,
false_next: null,
info: null,
prevs: [],
},
};
const reactNodeProps = JsonToReactNode(jsonNodeData);
expect(reactNodeProps).toEqual(expectedReactNodeProps);
});
});