|
| 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/services.dart'; |
| 6 | +import 'package:flutter_api_samples/widgets/shortcuts/callback_shortcuts.0.dart' |
| 7 | + as example; |
| 8 | +import 'package:flutter_test/flutter_test.dart'; |
| 9 | + |
| 10 | +void main() { |
| 11 | + testWidgets('Verify correct labels are displayed', (WidgetTester tester) async { |
| 12 | + await tester.pumpWidget( |
| 13 | + const example.CallbackShortcutsApp(), |
| 14 | + ); |
| 15 | + |
| 16 | + expect(find.text('CallbackShortcuts Sample'), findsOneWidget); |
| 17 | + expect( |
| 18 | + find.text('Press the up arrow key to add to the counter'), |
| 19 | + findsOneWidget, |
| 20 | + ); |
| 21 | + expect( |
| 22 | + find.text('Press the down arrow key to subtract from the counter'), |
| 23 | + findsOneWidget, |
| 24 | + ); |
| 25 | + expect(find.text('count: 0'), findsOneWidget); |
| 26 | + }); |
| 27 | + |
| 28 | + testWidgets('Up and down arrow press updates counter', (WidgetTester tester) async { |
| 29 | + await tester.pumpWidget( |
| 30 | + const example.CallbackShortcutsApp(), |
| 31 | + ); |
| 32 | + |
| 33 | + int counter = 0; |
| 34 | + |
| 35 | + while (counter < 10) { |
| 36 | + expect(find.text('count: $counter'), findsOneWidget); |
| 37 | + |
| 38 | + // Increment the counter. |
| 39 | + await tester.sendKeyEvent(LogicalKeyboardKey.arrowUp); |
| 40 | + await tester.pump(); |
| 41 | + |
| 42 | + counter++; |
| 43 | + } |
| 44 | + |
| 45 | + while (counter >= 0) { |
| 46 | + expect(find.text('count: $counter'), findsOneWidget); |
| 47 | + |
| 48 | + // Decrement the counter. |
| 49 | + await tester.sendKeyEvent(LogicalKeyboardKey.arrowDown); |
| 50 | + await tester.pump(); |
| 51 | + |
| 52 | + counter--; |
| 53 | + } |
| 54 | + }); |
| 55 | +} |
0 commit comments