Skip to content

Commit 505e5cc

Browse files
authored
Merge pull request #1889 from EnsembleUI/unitTesting
[1874] Added key to widgets
2 parents 9c2e850 + 2556461 commit 505e5cc

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

modules/ensemble/lib/framework/ensemble_widget.dart

+9
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,15 @@ abstract class EnsembleWidgetState<W extends EnsembleWidget> extends State<W> {
5555

5656
Widget rtn = buildWidget(context);
5757

58+
// Add KeyedSubtree with ValueKey based on testId to make widget findable in tests using find.byKey()
59+
if (widgetController.testId != null &&
60+
widgetController.testId!.isNotEmpty) {
61+
rtn = KeyedSubtree(
62+
key: ValueKey(widgetController.testId!),
63+
child: rtn,
64+
);
65+
}
66+
5867
if (widgetController.textDirection != null) {
5968
rtn = Directionality(
6069
textDirection: widgetController.textDirection!, child: rtn);

modules/ensemble/lib/framework/widget/widget.dart

+9
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,15 @@ abstract class EWidgetState<W extends HasController>
6262
if (widget.controller is WidgetController) {
6363
WidgetController widgetController = widget.controller as WidgetController;
6464

65+
// Add KeyedSubtree with ValueKey based on testId to make widget findable in tests using find.byKey()
66+
if (widgetController.testId != null &&
67+
widgetController.testId!.isNotEmpty) {
68+
rtn = KeyedSubtree(
69+
key: ValueKey(widgetController.testId!),
70+
child: rtn,
71+
);
72+
}
73+
6574
if (widgetController.textDirection != null) {
6675
rtn = Directionality(
6776
textDirection: widgetController.textDirection!, child: rtn);

0 commit comments

Comments
 (0)