Skip to content

Commit 47d69df

Browse files
committed
Fixed Toast and add integration tests
1 parent 6617385 commit 47d69df

File tree

5 files changed

+107
-7
lines changed

5 files changed

+107
-7
lines changed
+40
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
View:
2+
styles:
3+
useSafeArea: true
4+
body:
5+
Column:
6+
children:
7+
- Button:
8+
label: Show Toast Action
9+
onTap:
10+
showToast:
11+
message: success by Action
12+
- Button:
13+
label: Show Toast JS
14+
onTap: |-
15+
ensemble.showToast({message: "success by JS"});
16+
- Button:
17+
label: Show Toast Widget
18+
onTap:
19+
showToast:
20+
options:
21+
duration: 1
22+
body:
23+
Text:
24+
text: success with body widget
25+
- Button:
26+
label: Show Toast with custom widget
27+
onTap: |-
28+
ensemble.showToast({
29+
options: {
30+
duration: 1
31+
},
32+
body: "MyToastWidget"
33+
});
34+
35+
36+
37+
MyToastWidget:
38+
body:
39+
Text:
40+
text: custom body
+54
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
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+
}

lib/framework/action.dart

+12
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import 'package:ensemble/framework/keychain_manager.dart';
2323
import 'package:ensemble/framework/permissions_manager.dart';
2424
import 'package:ensemble/framework/scope.dart';
2525
import 'package:ensemble/framework/view/page_group.dart';
26+
import 'package:ensemble/framework/widget/toast.dart';
2627
import 'package:ensemble/framework/widget/view_util.dart';
2728
import 'package:ensemble/receive_intent_manager.dart';
2829
import 'package:ensemble/screen_controller.dart';
@@ -652,6 +653,17 @@ class ShowToastAction extends EnsembleAction {
652653

653654
factory ShowToastAction.fromMap(dynamic inputs) =>
654655
ShowToastAction.fromYaml(payload: Utils.getYamlMap(inputs));
656+
657+
@override
658+
Future execute(BuildContext context, ScopeManager scopeManager) {
659+
Widget? customToastBody;
660+
if (body != null) {
661+
customToastBody = scopeManager.buildWidgetFromDefinition(body);
662+
}
663+
ToastController().showToast(context, this, customToastBody,
664+
dataContext: scopeManager.dataContext);
665+
return Future.value(null);
666+
}
655667
}
656668

657669
class GetLocationAction extends EnsembleAction {

lib/screen_controller.dart

-7
Original file line numberDiff line numberDiff line change
@@ -449,13 +449,6 @@ class ScreenController {
449449
if (action.onComplete != null) {
450450
executeActionWithScope(context, scopeManager, action.onComplete!);
451451
}
452-
} else if (action is ShowToastAction) {
453-
Widget? customToastBody;
454-
if (action.body != null) {
455-
customToastBody = scopeManager.buildWidgetFromDefinition(action.body);
456-
}
457-
ToastController().showToast(context, action, customToastBody,
458-
dataContext: scopeManager.dataContext);
459452
} else if (action is OpenUrlAction) {
460453
dynamic value = scopeManager.dataContext.eval(action.url);
461454
value ??= '';

pubspec.yaml

+1
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,7 @@ flutter:
152152
# integration tests (TODO - exclude from build)
153153
- integration_test/local/defaultApp/
154154
- integration_test/local/themedApp/
155+
- integration_test/local/dialog/
155156

156157
fonts:
157158
# icon fonts

0 commit comments

Comments
 (0)