|
| 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 'dart:ui'; |
| 6 | + |
| 7 | +import 'package:flutter/material.dart'; |
| 8 | +import 'package:flutter_api_samples/widgets/widget_state/widget_state_border_side.0.dart' |
| 9 | + as example; |
| 10 | +import 'package:flutter_test/flutter_test.dart'; |
| 11 | + |
| 12 | +void main() { |
| 13 | + Finder findByBorderColor(Color color) { |
| 14 | + return find.byWidgetPredicate((Widget widget) { |
| 15 | + if (widget is! Material) { |
| 16 | + return false; |
| 17 | + } |
| 18 | + |
| 19 | + final ShapeBorder? shape = widget.shape; |
| 20 | + return shape is OutlinedBorder && shape.side.color == color; |
| 21 | + }); |
| 22 | + } |
| 23 | + |
| 24 | + testWidgets('FilterChip displays the blue colored border when hovered', (WidgetTester tester) async { |
| 25 | + await tester.pumpWidget( |
| 26 | + const example.WidgetStateBorderSideExampleApp(), |
| 27 | + ); |
| 28 | + |
| 29 | + // Hover over the FilterChip. |
| 30 | + final TestGesture gesture = await tester.createGesture(kind: PointerDeviceKind.mouse); |
| 31 | + await gesture.moveTo(tester.getCenter(find.byType(FilterChip))); |
| 32 | + |
| 33 | + await tester.pumpAndSettle(); |
| 34 | + |
| 35 | + expect(findByBorderColor(Colors.blue), findsOneWidget); |
| 36 | + }); |
| 37 | + |
| 38 | + testWidgets('FilterChip displays the green colored border when pressed', (WidgetTester tester) async { |
| 39 | + await tester.pumpWidget( |
| 40 | + const example.WidgetStateBorderSideExampleApp(), |
| 41 | + ); |
| 42 | + |
| 43 | + // Press on the FilterChip. |
| 44 | + final TestGesture gesture = await tester.createGesture(); |
| 45 | + await gesture.down(tester.getCenter(find.byType(FilterChip))); |
| 46 | + |
| 47 | + await tester.pumpAndSettle(); |
| 48 | + |
| 49 | + expect(findByBorderColor(Colors.green), findsOneWidget); |
| 50 | + }); |
| 51 | + |
| 52 | + testWidgets('FilterChip displays the red colored border when selected', (WidgetTester tester) async { |
| 53 | + await tester.pumpWidget( |
| 54 | + const example.WidgetStateBorderSideExampleApp(), |
| 55 | + ); |
| 56 | + |
| 57 | + expect(findByBorderColor(Colors.red), findsOneWidget); |
| 58 | + }); |
| 59 | + |
| 60 | + testWidgets('FilterChip displays the correct border color when not selected', (WidgetTester tester) async { |
| 61 | + await tester.pumpWidget( |
| 62 | + const example.WidgetStateBorderSideExampleApp(), |
| 63 | + ); |
| 64 | + |
| 65 | + await tester.tap(find.byType(FilterChip)); |
| 66 | + await tester.pumpAndSettle(); |
| 67 | + |
| 68 | + final ThemeData theme = Theme.of(tester.element(find.byType(FilterChip))); |
| 69 | + |
| 70 | + // FilterChip's border color defaults to ColorScheme.outlineVariant. |
| 71 | + expect( |
| 72 | + findByBorderColor(theme.colorScheme.outlineVariant), |
| 73 | + findsOneWidget, |
| 74 | + ); |
| 75 | + }); |
| 76 | +} |
0 commit comments