|
| 1 | +import 'package:ensemble/ensemble.dart'; |
| 2 | +import 'package:ensemble/widget/button.dart'; |
| 3 | +import 'package:flutter/material.dart'; |
| 4 | +import 'package:flutter_test/flutter_test.dart'; |
| 5 | + |
| 6 | +import '../framework/test_helper.dart'; |
| 7 | + |
| 8 | +void main() { |
| 9 | + late EnsembleConfig config; |
| 10 | + setUpAll(() async { |
| 11 | + config = await TestHelper.setupApp(appName: 'dialog'); |
| 12 | + }); |
| 13 | + |
| 14 | + group('Testing Toast', () { |
| 15 | + testWidgets("works in Action and JS", (tester) async { |
| 16 | + await TestHelper.loadScreen(tester, 'Toast', config); |
| 17 | + |
| 18 | + // toast by Action |
| 19 | + await tester.tap(find.descendant( |
| 20 | + of: find.byType(Button), matching: find.text('Show Toast Action'))); |
| 21 | + await tester.pumpAndSettle(); |
| 22 | + expect(find.text('success by Action'), findsOneWidget); |
| 23 | + await tester.tap(find.byType(CircleAvatar)); |
| 24 | + await tester.pumpAndSettle(); |
| 25 | + expect(find.text('success by Action'), findsNothing); |
| 26 | + |
| 27 | + // toast by JS |
| 28 | + await tester.tap(find.descendant( |
| 29 | + of: find.byType(Button), matching: find.text('Show Toast JS'))); |
| 30 | + await tester.pumpAndSettle(); |
| 31 | + expect(find.text('success by JS'), findsOneWidget); |
| 32 | + await tester.tap(find.byType(CircleAvatar)); |
| 33 | + await tester.pumpAndSettle(); |
| 34 | + expect(find.text('success by JS'), findsNothing); |
| 35 | + |
| 36 | + // use body widget |
| 37 | + await tester.tap(find.descendant( |
| 38 | + of: find.byType(Button), matching: find.text('Show Toast Widget'))); |
| 39 | + await tester.pumpAndSettle(); |
| 40 | + expect(find.text('success with body widget'), findsOneWidget); |
| 41 | + await tester.pumpAndSettle(const Duration(seconds: 2)); // auto dismiss |
| 42 | + expect(find.text('success with body widget'), findsNothing); |
| 43 | + |
| 44 | + // use body custom widget and JS |
| 45 | + await tester.tap(find.descendant( |
| 46 | + of: find.byType(Button), |
| 47 | + matching: find.text('Show Toast with custom widget'))); |
| 48 | + await tester.pumpAndSettle(); |
| 49 | + expect(find.text('custom body'), findsOneWidget); |
| 50 | + await tester.pumpAndSettle(const Duration(seconds: 2)); // auto dismiss |
| 51 | + expect(find.text('custom body'), findsNothing); |
| 52 | + }); |
| 53 | + }); |
| 54 | +} |
0 commit comments