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:
Valentin Vignal 2024-10-15 20:10:21 +08:00 committed by GitHub
parent aaccfe6170
commit 5d06db6aad
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 47 additions and 1 deletions

View File

@ -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',

View File

@ -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);
},
);
}