Skip to content

Commit 5644c03

Browse files
Add test for selection_container_disabled.0.dart (#156934)
Contributes to flutter/flutter#130459 It adds a test for - `examples/api/test/material/selection_container/selection_container_disabled.0_test.dart`
1 parent ae6d793 commit 5644c03

File tree

2 files changed

+76
-1
lines changed

2 files changed

+76
-1
lines changed

dev/bots/check_code_samples.dart

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -312,7 +312,6 @@ final Set<String> _knownMissingTests = <String>{
312312
'examples/api/test/material/bottom_app_bar/bottom_app_bar.2_test.dart',
313313
'examples/api/test/material/bottom_app_bar/bottom_app_bar.1_test.dart',
314314
'examples/api/test/material/selectable_region/selectable_region.0_test.dart',
315-
'examples/api/test/material/selection_container/selection_container_disabled.0_test.dart',
316315
'examples/api/test/material/selection_container/selection_container.0_test.dart',
317316
'examples/api/test/material/color_scheme/dynamic_content_color.0_test.dart',
318317
'examples/api/test/material/platform_menu_bar/platform_menu_bar.0_test.dart',
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
// Copyright 2014 The Flutter Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style license that can be
3+
// found in the LICENSE file.
4+
5+
import 'package:flutter/gestures.dart';
6+
import 'package:flutter/material.dart';
7+
import 'package:flutter/rendering.dart';
8+
import 'package:flutter_api_samples/material/selection_container/selection_container_disabled.0.dart' as example;
9+
import 'package:flutter_test/flutter_test.dart';
10+
11+
void main() {
12+
testWidgets('A SelectionContainer.disabled should disable selections', (WidgetTester tester) async {
13+
await tester.pumpWidget(
14+
const example.SelectionContainerDisabledExampleApp(),
15+
);
16+
17+
expect(find.widgetWithText(AppBar, 'SelectionContainer.disabled Sample'), findsOne);
18+
19+
final RenderParagraph paragraph1 = tester.renderObject<RenderParagraph>(
20+
find.descendant(
21+
of: find.text('Selectable text').first,
22+
matching: find.byType(RichText),
23+
),
24+
);
25+
final Rect paragraph1Rect = tester.getRect(find.text('Selectable text').first);
26+
final TestGesture gesture = await tester.startGesture(
27+
paragraph1Rect.centerLeft,
28+
kind: PointerDeviceKind.mouse,
29+
);
30+
addTearDown(gesture.removePointer);
31+
await tester.pump();
32+
33+
await gesture.moveTo(paragraph1Rect.center);
34+
await tester.pump();
35+
expect(
36+
paragraph1.selections.first,
37+
const TextSelection(baseOffset: 0, extentOffset: 7),
38+
);
39+
40+
final RenderParagraph paragraph2 = tester.renderObject<RenderParagraph>(
41+
find.descendant(
42+
of: find.text('Non-selectable text'),
43+
matching: find.byType(RichText),
44+
),
45+
);
46+
final Rect paragraph2Rect = tester.getRect(find.text('Non-selectable text'));
47+
await gesture.moveTo(paragraph2Rect.center);
48+
// Should select the rest of paragraph 1.
49+
expect(
50+
paragraph1.selections.first,
51+
const TextSelection(baseOffset: 0, extentOffset: 15),
52+
);
53+
// paragraph2 is in a disabled container.
54+
expect(paragraph2.selections, isEmpty);
55+
56+
final RenderParagraph paragraph3 = tester.renderObject<RenderParagraph>(
57+
find.descendant(
58+
of: find.text('Selectable text').last,
59+
matching: find.byType(RichText),
60+
),
61+
);
62+
final Rect paragraph3Rect = tester.getRect(find.text('Selectable text').last);
63+
await gesture.moveTo(paragraph3Rect.center);
64+
expect(
65+
paragraph1.selections.first,
66+
const TextSelection(baseOffset: 0, extentOffset: 15),
67+
);
68+
expect(paragraph2.selections, isEmpty);
69+
expect(
70+
paragraph3.selections.first,
71+
const TextSelection(baseOffset: 0, extentOffset: 7),
72+
);
73+
74+
await gesture.up();
75+
});
76+
}

0 commit comments

Comments
 (0)