Skip to content
32 changes: 32 additions & 0 deletions packages/flutter/test/material/back_button_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
// found in the LICENSE file.

import 'package:flutter/material.dart';
import 'package:flutter/rendering.dart';
import 'package:flutter_test/flutter_test.dart';

void main() {
Expand Down Expand Up @@ -59,4 +60,35 @@ void main() {
final Icon androidIcon = tester.widget(find.descendant(of: find.byKey(androidKey), matching: find.byType(Icon)));
expect(iOSIcon == androidIcon, false);
});

testWidgets('BackButton semantics', (WidgetTester tester) async {
final SemanticsHandle handle = tester.ensureSemantics();
await tester.pumpWidget(
new MaterialApp(
home: const Material(child: const Text('Home')),
routes: <String, WidgetBuilder>{
'/next': (BuildContext context) {
return const Material(
child: const Center(
child: const BackButton(),
),
);
},
},
),
);

tester.state<NavigatorState>(find.byType(Navigator)).pushNamed('/next');

await tester.pumpAndSettle();

expect(tester.getSemanticsData(find.byType(BackButton)), matchesSemanticsData(
label: 'Back',
isButton: true,
hasEnabledState: true,
isEnabled: true,
hasTapAction: true,
));
handle.dispose();
});
}
111 changes: 34 additions & 77 deletions packages/flutter/test/material/checkbox_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ void main() {
});

testWidgets('CheckBox semantics', (WidgetTester tester) async {
final SemanticsTester semantics = new SemanticsTester(tester);
final SemanticsHandle handle = tester.ensureSemantics();

await tester.pumpWidget(new Material(
child: new Checkbox(
Expand All @@ -41,21 +41,12 @@ void main() {
),
));

expect(semantics, hasSemantics(new TestSemantics.root(
children: <TestSemantics>[
new TestSemantics.rootChild(
id: 1,
flags: <SemanticsFlag>[
SemanticsFlag.hasCheckedState,
SemanticsFlag.hasEnabledState,
SemanticsFlag.isEnabled,
],
actions: <SemanticsAction>[
SemanticsAction.tap,
],
),
],
), ignoreRect: true, ignoreTransform: true));
expect(tester.getSemanticsData(find.byType(Checkbox)), matchesSemanticsData(
hasCheckedState: true,
hasEnabledState: true,
isEnabled: true,
hasTapAction: true,
));

await tester.pumpWidget(new Material(
child: new Checkbox(
Expand All @@ -64,22 +55,13 @@ void main() {
),
));

expect(semantics, hasSemantics(new TestSemantics.root(
children: <TestSemantics>[
new TestSemantics.rootChild(
id: 1,
flags: <SemanticsFlag>[
SemanticsFlag.hasCheckedState,
SemanticsFlag.isChecked,
SemanticsFlag.hasEnabledState,
SemanticsFlag.isEnabled,
],
actions: <SemanticsAction>[
SemanticsAction.tap,
],
),
],
), ignoreRect: true, ignoreTransform: true));
expect(tester.getSemanticsData(find.byType(Checkbox)), matchesSemanticsData(
hasCheckedState: true,
hasEnabledState: true,
isChecked: true,
isEnabled: true,
hasTapAction: true,
));

await tester.pumpWidget(const Material(
child: const Checkbox(
Expand All @@ -88,17 +70,10 @@ void main() {
),
));

expect(semantics, hasSemantics(new TestSemantics.root(
children: <TestSemantics>[
new TestSemantics.rootChild(
id: 1,
flags: <SemanticsFlag>[
SemanticsFlag.hasCheckedState,
SemanticsFlag.hasEnabledState,
],
),
],
), ignoreRect: true, ignoreTransform: true));
expect(tester.getSemanticsData(find.byType(Checkbox)), matchesSemanticsData(
hasCheckedState: true,
hasEnabledState: true,
));

await tester.pumpWidget(const Material(
child: const Checkbox(
Expand All @@ -107,24 +82,16 @@ void main() {
),
));

expect(semantics, hasSemantics(new TestSemantics.root(
children: <TestSemantics>[
new TestSemantics.rootChild(
id: 1,
flags: <SemanticsFlag>[
SemanticsFlag.hasCheckedState,
SemanticsFlag.isChecked,
SemanticsFlag.hasEnabledState,
],
),
],
), ignoreRect: true, ignoreTransform: true));

semantics.dispose();
expect(tester.getSemanticsData(find.byType(Checkbox)), matchesSemanticsData(
hasCheckedState: true,
hasEnabledState: true,
isChecked: true,
));
handle.dispose();
});

testWidgets('Can wrap CheckBox with Semantics', (WidgetTester tester) async {
final SemanticsTester semantics = new SemanticsTester(tester);
final SemanticsHandle handle = tester.ensureSemantics();

await tester.pumpWidget(new Material(
child: new Semantics(
Expand All @@ -137,25 +104,15 @@ void main() {
),
));

expect(semantics, hasSemantics(new TestSemantics.root(
children: <TestSemantics>[
new TestSemantics.rootChild(
id: 1,
label: 'foo',
textDirection: TextDirection.ltr,
flags: <SemanticsFlag>[
SemanticsFlag.hasCheckedState,
SemanticsFlag.hasEnabledState,
SemanticsFlag.isEnabled,
],
actions: <SemanticsAction>[
SemanticsAction.tap,
],
),
],
), ignoreRect: true, ignoreTransform: true));

semantics.dispose();
expect(tester.getSemanticsData(find.byType(Checkbox)), matchesSemanticsData(
label: 'foo',
textDirection: TextDirection.ltr,
hasCheckedState: true,
hasEnabledState: true,
isEnabled: true,
hasTapAction: true,
));
handle.dispose();
});

testWidgets('CheckBox tristate: true', (WidgetTester tester) async {
Expand Down
Loading