Skip to content

Commit 9e82069

Browse files
author
Renzo Olivares
committed
Update test
1 parent b3e9931 commit 9e82069

File tree

1 file changed

+55
-3
lines changed

1 file changed

+55
-3
lines changed

packages/two_dimensional_scrollables/example/test/table_view/simple_table_test.dart

Lines changed: 55 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@
22
// Use of this source code is governed by a BSD-style license that can be
33
// found in the LICENSE file.
44

5+
import 'package:flutter/gestures.dart';
56
import 'package:flutter/material.dart';
7+
import 'package:flutter/rendering.dart';
68
import 'package:flutter_test/flutter_test.dart';
79
import 'package:two_dimensional_examples/table_view/simple_table.dart';
810

@@ -62,14 +64,64 @@ void main() {
6264

6365
// Enable multi-cell selection and verify.
6466
await tester.tap(find.textContaining('Multi-Cell'));
65-
await tester.pump();
67+
await tester.pumpAndSettle();
68+
69+
// Find two adjacent cells. Adjust these finders as needed for your specific layout.
70+
final Finder cell1 = find.text('Tile c: 0, r: 0');
71+
final Finder cell2 = find.text('Tile c: 1, r: 0');
72+
73+
final Offset cell1Center = tester.getCenter(cell1);
74+
final Offset cell2Center = tester.getCenter(cell2);
75+
76+
// Long press and drag to select multiple cells.
77+
final TestGesture gesture = await tester.startGesture(cell1Center);
78+
await tester.pump(kLongPressTimeout);
79+
await gesture.moveTo(cell2Center);
80+
await gesture.up();
81+
await tester.pumpAndSettle();
82+
83+
final RenderParagraph paragraph1 = tester.renderObject<RenderParagraph>(
84+
find.descendant(of: cell1, matching: find.byType(RichText)),
85+
);
86+
final RenderParagraph paragraph2 = tester.renderObject<RenderParagraph>(
87+
find.descendant(of: cell2, matching: find.byType(RichText)),
88+
);
89+
expect(paragraph1.selections.isEmpty, isFalse);
90+
expect(paragraph2.selections.isEmpty, isFalse);
6691

6792
// Enable single-cell selection and verify.
6893
await tester.tap(find.textContaining('Single-Cell'));
69-
await tester.pump();
94+
await tester.pumpAndSettle();
95+
96+
// Selection has been cleared.
97+
expect(paragraph1.selections.isEmpty, isTrue);
98+
expect(paragraph2.selections.isEmpty, isTrue);
99+
100+
// Selecting from cell1 to cell2 only selects cell1.
101+
await gesture.down(cell1Center);
102+
await tester.pump(kLongPressTimeout);
103+
await gesture.moveTo(cell2Center);
104+
await gesture.up();
105+
await tester.pumpAndSettle();
106+
107+
expect(paragraph1.selections.isEmpty, isFalse);
108+
expect(paragraph2.selections.isEmpty, isTrue);
70109

71110
// Disable selection and verify.
72111
await tester.tap(find.text('Disabled'));
73-
await tester.pump();
112+
await tester.pumpAndSettle();
113+
114+
// Selection has been cleared.
115+
expect(paragraph1.selections.isEmpty, isTrue);
116+
expect(paragraph2.selections.isEmpty, isTrue);
117+
118+
// Long pressing should not select anything.
119+
await gesture.down(cell1Center);
120+
await tester.pump(kLongPressTimeout);
121+
await gesture.up();
122+
await tester.pumpAndSettle();
123+
124+
expect(paragraph1.selections.isEmpty, isTrue);
125+
expect(paragraph2.selections.isEmpty, isTrue);
74126
});
75127
}

0 commit comments

Comments
 (0)