Skip to content

Commit e46b66c

Browse files
committed
test: refine shouldRepaint behavior and update connection endpoint visibility tests
1 parent e6b78e4 commit e46b66c

3 files changed

Lines changed: 61 additions & 15 deletions

File tree

packages/vyuh_node_flow/test/unit/editor/connections_layer_test.dart

Lines changed: 43 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ void main() {
182182
// ===========================================================================
183183

184184
group('ConnectionsCanvas shouldRepaint', () {
185-
test('shouldRepaint always returns true', () {
185+
test('shouldRepaint returns false when fingerprint and theme match', () {
186186
final controller = createTestController();
187187
final painter = createTestConnectionPainter(theme: NodeFlowTheme.light);
188188

@@ -198,11 +198,11 @@ void main() {
198198
connectionPainter: painter,
199199
);
200200

201-
// shouldRepaint should always return true for MobX reactivity
202-
expect(canvas1.shouldRepaint(canvas2), isTrue);
201+
// shouldRepaint returns false when fingerprint and theme are identical
202+
expect(canvas1.shouldRepaint(canvas2), isFalse);
203203
});
204204

205-
test('shouldRepaint returns true even with same references', () {
205+
test('shouldRepaint returns false with same canvas instance', () {
206206
final controller = createTestController();
207207
final painter = createTestConnectionPainter(theme: NodeFlowTheme.light);
208208

@@ -212,8 +212,8 @@ void main() {
212212
connectionPainter: painter,
213213
);
214214

215-
// Same canvas instance
216-
expect(canvas.shouldRepaint(canvas), isTrue);
215+
// Same canvas instance has same fingerprint and theme
216+
expect(canvas.shouldRepaint(canvas), isFalse);
217217
});
218218

219219
test('shouldRepaint returns true with different themes', () {
@@ -235,7 +235,7 @@ void main() {
235235
expect(canvas1.shouldRepaint(canvas2), isTrue);
236236
});
237237

238-
test('shouldRepaint returns true with different controllers', () {
238+
test('shouldRepaint returns false with different empty controllers', () {
239239
final controller1 = createTestController();
240240
final controller2 = createTestController();
241241
final painter = createTestConnectionPainter(theme: NodeFlowTheme.light);
@@ -252,6 +252,42 @@ void main() {
252252
connectionPainter: painter,
253253
);
254254

255+
// Empty controllers have the same fingerprint (no connections)
256+
expect(canvas1.shouldRepaint(canvas2), isFalse);
257+
});
258+
259+
test('shouldRepaint returns true when connections change', () {
260+
final controller = createTestController();
261+
final painter = createTestConnectionPainter(theme: NodeFlowTheme.light);
262+
263+
// Add nodes with ports for connections
264+
final node1 = createTestNodeWithPorts(id: 'n1');
265+
final node2 = createTestNodeWithPorts(id: 'n2');
266+
controller.addNode(node1);
267+
controller.addNode(node2);
268+
269+
final canvas1 = ConnectionsCanvas<String, dynamic>(
270+
store: controller,
271+
theme: NodeFlowTheme.light,
272+
connectionPainter: painter,
273+
);
274+
275+
// Add a connection to change the fingerprint
276+
controller.addConnection(Connection(
277+
id: 'c1',
278+
sourceNodeId: 'n1',
279+
sourcePortId: node1.outputPorts.first.id,
280+
targetNodeId: 'n2',
281+
targetPortId: node2.inputPorts.first.id,
282+
));
283+
284+
final canvas2 = ConnectionsCanvas<String, dynamic>(
285+
store: controller,
286+
theme: NodeFlowTheme.light,
287+
connectionPainter: painter,
288+
);
289+
290+
// Fingerprint changed due to new connection
255291
expect(canvas1.shouldRepaint(canvas2), isTrue);
256292
});
257293
});

packages/vyuh_node_flow/test/unit/lod/detail_visibility_test.dart

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,10 @@ void main() {
9595
expect(visibility.showPorts, isFalse);
9696
expect(visibility.showPortLabels, isFalse);
9797
expect(visibility.showConnectionLabels, isFalse);
98-
expect(visibility.showConnectionEndpoints, isFalse);
98+
expect(
99+
visibility.showConnectionEndpoints,
100+
isTrue,
101+
); // Kept for visibility
99102
expect(visibility.showResizeHandles, isFalse);
100103
});
101104

@@ -126,7 +129,10 @@ void main() {
126129
expect(visibility.showPorts, isFalse);
127130
expect(visibility.showPortLabels, isFalse);
128131
expect(visibility.showConnectionLabels, isFalse);
129-
expect(visibility.showConnectionEndpoints, isFalse);
132+
expect(
133+
visibility.showConnectionEndpoints,
134+
isTrue,
135+
); // Kept for visibility
130136
expect(visibility.showResizeHandles, isFalse);
131137
});
132138

@@ -371,7 +377,7 @@ void main() {
371377
expect(copy.showPortLabels, isFalse); // Unchanged from minimal
372378
expect(copy.showConnectionLines, isTrue); // Unchanged from minimal
373379
expect(copy.showConnectionLabels, isFalse); // Unchanged from minimal
374-
expect(copy.showConnectionEndpoints, isFalse); // Unchanged from minimal
380+
expect(copy.showConnectionEndpoints, isTrue); // Unchanged from minimal
375381
expect(copy.showResizeHandles, isTrue);
376382
});
377383

@@ -407,7 +413,8 @@ void main() {
407413
showPortLabels: false,
408414
showConnectionLines: true,
409415
showConnectionLabels: false,
410-
showConnectionEndpoints: false,
416+
showConnectionEndpoints: true,
417+
// minimal keeps endpoints visible
411418
showResizeHandles: false,
412419
);
413420

@@ -426,7 +433,7 @@ void main() {
426433
expect(result.showPortLabels, isFalse);
427434
expect(result.showConnectionLines, isTrue);
428435
expect(result.showConnectionLabels, isFalse);
429-
expect(result.showConnectionEndpoints, isFalse);
436+
expect(result.showConnectionEndpoints, isTrue); // minimal keeps endpoints
430437
expect(result.showResizeHandles, isTrue);
431438
});
432439
});
@@ -651,7 +658,10 @@ void main() {
651658
expect(string, contains('showPortLabels: false'));
652659
expect(string, contains('showConnectionLines: true'));
653660
expect(string, contains('showConnectionLabels: false'));
654-
expect(string, contains('showConnectionEndpoints: false'));
661+
expect(
662+
string,
663+
contains('showConnectionEndpoints: true'),
664+
); // minimal keeps endpoints
655665
expect(string, contains('showResizeHandles: false'));
656666
});
657667

packages/vyuh_node_flow/test/unit/lod/lod_state_test.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ void main() {
2828
isTrue,
2929
); // Kept for graph structure
3030
expect(visibility.showConnectionLabels, isFalse);
31-
expect(visibility.showConnectionEndpoints, isFalse);
31+
expect(visibility.showConnectionEndpoints, isTrue); // Kept for visibility
3232
expect(visibility.showResizeHandles, isFalse);
3333
});
3434

@@ -40,7 +40,7 @@ void main() {
4040
expect(visibility.showPortLabels, isFalse);
4141
expect(visibility.showConnectionLines, isTrue);
4242
expect(visibility.showConnectionLabels, isFalse);
43-
expect(visibility.showConnectionEndpoints, isFalse);
43+
expect(visibility.showConnectionEndpoints, isTrue); // Kept for visibility
4444
expect(visibility.showResizeHandles, isFalse);
4545
});
4646

0 commit comments

Comments
 (0)