|
2 | 2 | // Use of this source code is governed by a BSD-style license that can be |
3 | 3 | // found in the LICENSE file. |
4 | 4 |
|
| 5 | +import 'package:flutter/gestures.dart'; |
5 | 6 | import 'package:flutter/material.dart'; |
| 7 | +import 'package:flutter/rendering.dart'; |
6 | 8 | import 'package:flutter_test/flutter_test.dart'; |
7 | 9 | import 'package:two_dimensional_examples/table_view/simple_table.dart'; |
8 | 10 |
|
@@ -62,14 +64,64 @@ void main() { |
62 | 64 |
|
63 | 65 | // Enable multi-cell selection and verify. |
64 | 66 | 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); |
66 | 91 |
|
67 | 92 | // Enable single-cell selection and verify. |
68 | 93 | 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); |
70 | 109 |
|
71 | 110 | // Disable selection and verify. |
72 | 111 | 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); |
74 | 126 | }); |
75 | 127 | } |
0 commit comments