|
| 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 'package:flutter/cupertino.dart'; |
| 6 | +import 'package:flutter_api_samples/cupertino/dialog/cupertino_popup_surface.0.dart' |
| 7 | + as example; |
| 8 | +import 'package:flutter_test/flutter_test.dart'; |
| 9 | + |
| 10 | +void main() { |
| 11 | + testWidgets('CupertinoPopupSurface displays expected widgets in init state', |
| 12 | + (WidgetTester tester) async { |
| 13 | + await tester.pumpWidget(const example.PopupSurfaceApp()); |
| 14 | + |
| 15 | + final Finder cupertinoButton = find.byType(CupertinoButton); |
| 16 | + expect(cupertinoButton, findsOneWidget); |
| 17 | + |
| 18 | + final Finder cupertinoSwitch = find.byType(CupertinoSwitch); |
| 19 | + expect(cupertinoSwitch, findsOneWidget); |
| 20 | + }); |
| 21 | + |
| 22 | + testWidgets('CupertinoPopupSurface is displayed with painted surface', |
| 23 | + (WidgetTester tester) async { |
| 24 | + await tester.pumpWidget(const example.PopupSurfaceApp()); |
| 25 | + |
| 26 | + // CupertinoSwitch is toggled on by default. |
| 27 | + expect(tester.widget<CupertinoSwitch>(find.byType(CupertinoSwitch)).value, isTrue); |
| 28 | + |
| 29 | + // Tap on the CupertinoButton to show the CupertinoPopupSurface. |
| 30 | + await tester.tap(find.byType(CupertinoButton)); |
| 31 | + await tester.pumpAndSettle(); |
| 32 | + |
| 33 | + // Make sure CupertinoPopupSurface is showing. |
| 34 | + final Finder cupertinoPopupSurface = find.byType(CupertinoPopupSurface); |
| 35 | + expect(cupertinoPopupSurface, findsOneWidget); |
| 36 | + |
| 37 | + // Confirm that CupertinoPopupSurface is painted with a ColoredBox. |
| 38 | + final Finder coloredBox = find.descendant( |
| 39 | + of: cupertinoPopupSurface, |
| 40 | + matching: find.byType(ColoredBox), |
| 41 | + ); |
| 42 | + expect(coloredBox, findsOneWidget); |
| 43 | + }); |
| 44 | + |
| 45 | + testWidgets('CupertinoPopupSurface is displayed without painted surface', |
| 46 | + (WidgetTester tester) async { |
| 47 | + await tester.pumpWidget(const example.PopupSurfaceApp()); |
| 48 | + |
| 49 | + // Toggling off CupertinoSwitch and confirm its state. |
| 50 | + final Finder cupertinoSwitch = find.byType(CupertinoSwitch); |
| 51 | + await tester.tap(cupertinoSwitch); |
| 52 | + await tester.pumpAndSettle(); |
| 53 | + expect(tester.widget<CupertinoSwitch>(cupertinoSwitch).value, isFalse); |
| 54 | + |
| 55 | + // Tap on the CupertinoButton to show the CupertinoPopupSurface. |
| 56 | + await tester.tap(find.byType(CupertinoButton)); |
| 57 | + await tester.pumpAndSettle(); |
| 58 | + |
| 59 | + // Make sure CupertinoPopupSurface is showing. |
| 60 | + final Finder cupertinoPopupSurface = find.byType(CupertinoPopupSurface); |
| 61 | + expect(cupertinoPopupSurface, findsOneWidget); |
| 62 | + |
| 63 | + // Confirm that CupertinoPopupSurface is not painted with a ColoredBox. |
| 64 | + final Finder coloredBox = find.descendant( |
| 65 | + of: cupertinoPopupSurface, |
| 66 | + matching: find.byType(ColoredBox), |
| 67 | + ); |
| 68 | + expect(coloredBox, findsNothing); |
| 69 | + }); |
| 70 | +} |
0 commit comments