From 5d06db6aad33836435b7143872d0cc175c3fc206 Mon Sep 17 00:00:00 2001 From: Valentin Vignal <32538273+ValentinVignal@users.noreply.github.com> Date: Tue, 15 Oct 2024 20:10:21 +0800 Subject: [PATCH] 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` --- dev/bots/check_code_samples.dart | 1 - .../material_state_property.0_test.dart | 47 +++++++++++++++++++ 2 files changed, 47 insertions(+), 1 deletion(-) create mode 100644 examples/api/test/material/material_state/material_state_property.0_test.dart diff --git a/dev/bots/check_code_samples.dart b/dev/bots/check_code_samples.dart index 1ea32a71a1..924b543571 100644 --- a/dev/bots/check_code_samples.dart +++ b/dev/bots/check_code_samples.dart @@ -312,7 +312,6 @@ final Set _knownMissingTests = { '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', diff --git a/examples/api/test/material/material_state/material_state_property.0_test.dart b/examples/api/test/material/material_state/material_state_property.0_test.dart new file mode 100644 index 0000000000..c92a11e2c6 --- /dev/null +++ b/examples/api/test/material/material_state/material_state_property.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); + }, + ); +}