observerActionExamples function
Builds ready-to-run YAML snippets for actions the Observer verified for an element. The action name appears only in the YAML key.
Implementation
List<String> observerActionExamples({
required List<String> actions,
required String? title,
required String? id,
required Map<String, dynamic>? locator,
required Map<String, dynamic>? bounds,
required String? warning,
String? value,
bool? checked,
List<String> options = const [],
}) {
final target = _targetLocator(
locator: locator,
bounds: bounds,
warning: warning,
id: id,
title: title,
);
const textActions = {
'waitForText',
'expectText',
'expectNoText',
'expectTextContains',
};
return [
for (final action in actions)
// Text assertions are screen-wide actions in the runner: they cannot
// use a locator to distinguish this node from another node with the
// same text. Do not attach a misleading example to an element when its
// locator could not be verified as unique. Other actions can still use
// the observed bounds fallback below.
if (target != null && !(warning != null && textActions.contains(action)))
_formatExample(
action,
target: target,
title: title,
id: id,
value: value,
checked: checked,
options: options,
),
];
}