Add test for material_state_property.0.dart
(#156719)
Contributes to https://github.com/flutter/flutter/issues/130459 It adds a test for - `examples/api/test/material/material_state/material_state_property.0_test.dart`
This commit is contained in:
parent
aaccfe6170
commit
5d06db6aad
@ -312,7 +312,6 @@ final Set<String> _knownMissingTests = <String>{
|
||||
'examples/api/test/material/bottom_app_bar/bottom_app_bar.2_test.dart',
|
||||
'examples/api/test/material/bottom_app_bar/bottom_app_bar.1_test.dart',
|
||||
'examples/api/test/material/material_state/material_state_outlined_border.0_test.dart',
|
||||
'examples/api/test/material/material_state/material_state_property.0_test.dart',
|
||||
'examples/api/test/material/selectable_region/selectable_region.0_test.dart',
|
||||
'examples/api/test/material/selection_container/selection_container_disabled.0_test.dart',
|
||||
'examples/api/test/material/selection_container/selection_container.0_test.dart',
|
||||
|
@ -0,0 +1,47 @@
|
||||
// Copyright 2014 The Flutter Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
import 'package:flutter/gestures.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_api_samples/material/material_state/material_state_property.0.dart'
|
||||
as example;
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
|
||||
void main() {
|
||||
Color getButtonForegroundColor(WidgetTester tester) {
|
||||
final Material widget = tester.widget(
|
||||
find.descendant(
|
||||
of: find.byType(example.MaterialStatePropertyExample),
|
||||
matching:find.widgetWithText(Material, 'TextButton'),
|
||||
),
|
||||
);
|
||||
return widget.textStyle!.color!;
|
||||
}
|
||||
|
||||
testWidgets(
|
||||
'The foreground color of the TextButton should be red by default',
|
||||
(WidgetTester tester) async {
|
||||
await tester.pumpWidget(
|
||||
const example.MaterialStatePropertyExampleApp(),
|
||||
);
|
||||
|
||||
expect(getButtonForegroundColor(tester), Colors.red);
|
||||
},
|
||||
);
|
||||
|
||||
testWidgets(
|
||||
'The foreground color of the TextButton should be blue when hovered',
|
||||
(WidgetTester tester) async {
|
||||
await tester.pumpWidget(
|
||||
const example.MaterialStatePropertyExampleApp(),
|
||||
);
|
||||
|
||||
final TestGesture gesture = await tester.createGesture(kind: PointerDeviceKind.mouse);
|
||||
await gesture.addPointer(location: tester.getCenter(find.byType(TextButton)));
|
||||
await tester.pump();
|
||||
|
||||
expect(getButtonForegroundColor(tester), Colors.blue);
|
||||
},
|
||||
);
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user