Skip to content

Commit 724e5db

Browse files
committed
Add more integration tests for Toast widget
1 parent 81a84c2 commit 724e5db

File tree

3 files changed

+43
-13
lines changed

3 files changed

+43
-13
lines changed

integration_test/local/dialog/Toast.yaml

+21-2
Original file line numberDiff line numberDiff line change
@@ -24,17 +24,36 @@ View:
2424
text: success with body widget
2525
- Button:
2626
label: Show Toast with custom widget
27+
onTap:
28+
showToast:
29+
options:
30+
duration: 1
31+
body: MyToastWidget
32+
- Button:
33+
label: Custom Widget with inputs
2734
onTap: |-
2835
ensemble.showToast({
2936
options: {
3037
duration: 1
3138
},
32-
body: "MyToastWidget"
39+
body: {
40+
MyToastWidgetWithInputs: {
41+
inputs: {
42+
name: "Peter Parker"
43+
}
44+
}
45+
}
3346
});
3447
3548
3649
3750
MyToastWidget:
3851
body:
3952
Text:
40-
text: custom body
53+
text: custom body
54+
55+
MyToastWidgetWithInputs:
56+
inputs: [name]
57+
body:
58+
Text:
59+
text: Hello ${name}

integration_test/local/dialog_test.dart

+10-1
Original file line numberDiff line numberDiff line change
@@ -41,14 +41,23 @@ void main() {
4141
await tester.pumpAndSettle(const Duration(seconds: 2)); // auto dismiss
4242
expect(find.text('success with body widget'), findsNothing);
4343

44-
// use body custom widget and JS
44+
// use body custom widget
4545
await tester.tap(find.descendant(
4646
of: find.byType(Button),
4747
matching: find.text('Show Toast with custom widget')));
4848
await tester.pumpAndSettle();
4949
expect(find.text('custom body'), findsOneWidget);
5050
await tester.pumpAndSettle(const Duration(seconds: 2)); // auto dismiss
5151
expect(find.text('custom body'), findsNothing);
52+
53+
// use JS with custom widget with inputs
54+
await tester.tap(find.descendant(
55+
of: find.byType(Button),
56+
matching: find.text('Custom Widget with inputs')));
57+
await tester.pumpAndSettle();
58+
expect(find.text('Hello Peter Parker'), findsOneWidget);
59+
await tester.pumpAndSettle(const Duration(seconds: 2)); // auto dismiss
60+
expect(find.text('Hello Peter Parker'), findsNothing);
5261
});
5362
});
5463
}

lib/framework/widget/view_util.dart

+12-10
Original file line numberDiff line numberDiff line change
@@ -64,18 +64,20 @@ class ViewUtil {
6464
static WidgetModel buildModel(
6565
dynamic item, Map<String, dynamic>? customWidgetMap) {
6666
String? widgetType;
67-
YamlMap? payload;
67+
Map? payload;
6868
SourceSpan def =
6969
SourceSpanBase(SourceLocationBase(0), SourceLocationBase(0), '');
7070
// name only e.g Spacer
7171
if (item is String) {
7272
widgetType = item;
73-
} else if (item is YamlMap) {
73+
} else if (item is Map) {
7474
widgetType = item.keys.first.toString();
75-
if (item[widgetType] is YamlMap) {
75+
if (item[widgetType] is Map) {
7676
payload = item[widgetType];
7777
}
78-
def = getDefinition(item);
78+
if (item is YamlMap) {
79+
def = getDefinition(item);
80+
}
7981
if (item.keys.length > 1) {
8082
//multiple widgets found, it is probably because user used wrong indentation
8183
//TODO: we'll send a warning back
@@ -151,7 +153,7 @@ class ViewUtil {
151153
}
152154

153155
static WidgetModel? buildCustomModel(
154-
YamlMap? callerPayload,
156+
Map? callerPayload,
155157
dynamic viewDefinition,
156158
String widgetType,
157159
Map<String, dynamic> customWidgetMap) {
@@ -166,13 +168,13 @@ class ViewUtil {
166168
}
167169

168170
Map<String, dynamic> inputPayload = {};
169-
if (callerPayload?['inputs'] is YamlMap) {
171+
if (callerPayload?['inputs'] is Map) {
170172
callerPayload!['inputs'].forEach((key, value) {
171173
inputPayload[key] = value;
172174
});
173175
}
174176
Map<String, EnsembleAction?> eventPayload = {};
175-
if (callerPayload?['events'] is YamlMap) {
177+
if (callerPayload?['events'] is Map) {
176178
callerPayload!['events'].forEach((key, value) {
177179
eventPayload[key] = EnsembleAction.fromYaml(value);
178180
});
@@ -191,7 +193,7 @@ class ViewUtil {
191193
inputParams.add(input.toString());
192194
}
193195
}
194-
if (entry.key == 'events' && entry.value is YamlMap) {
196+
if (entry.key == 'events' && entry.value is Map) {
195197
for (var event in entry.value.entries) {
196198
eventParams[event.key] =
197199
EnsembleEvent.fromYaml(event.key, event.value);
@@ -218,8 +220,8 @@ class ViewUtil {
218220

219221
// custom widgets can have styles too
220222
Map<String, dynamic> styles = {};
221-
if (callerPayload?["styles"] is YamlMap) {
222-
(callerPayload!["styles"] as YamlMap).forEach((styleKey, styleValue) {
223+
if (callerPayload?["styles"] is Map) {
224+
(callerPayload!["styles"] as Map).forEach((styleKey, styleValue) {
223225
styles[styleKey] = EnsembleThemeManager.yamlToDart(styleValue);
224226
});
225227
}

0 commit comments

Comments
 (0)