CockpitTestActionTemplate.fromJson constructor
Decodes a CockpitTestActionTemplate from a JSON object.
Implementation
factory CockpitTestActionTemplate.fromJson(
Object? value, {
required String path,
}) {
final json = CockpitTestValueReader.object(value, path);
final kind = CockpitTestValueReader.enumeration(
json['type'],
CockpitTestActionKind.values,
'$path.type',
);
final spec = cockpitTestActionSpecs[kind]!;
final allowed = <String>{
'type',
'locator',
'condition',
...spec.allowedFields.map((field) => field.wireName),
};
CockpitTestValueReader.keys(
json,
allowed,
path,
required: const <String>{'type'},
allowExtensions: true,
);
final values = <CockpitTestActionField, CockpitTestTemplateValue>{};
for (final field in spec.allowedFields) {
if (json.containsKey(field.wireName)) {
values[field] = CockpitTestTemplateValue.fromJson(
json[field.wireName],
expectedType: field.valueType,
path: '$path.${field.wireName}',
);
}
}
return CockpitTestActionTemplate(
kind: kind,
locator: json['locator'] == null
? null
: CockpitTestLocatorTemplate.fromJson(
json['locator'],
path: '$path.locator',
),
condition: json['condition'] == null
? null
: CockpitTestConditionTemplate.fromJson(
json['condition'],
path: '$path.condition',
),
values: values,
extensions: <String, Object?>{
for (final entry in json.entries)
if (entry.key.startsWith('x-'))
entry.key: CockpitTestValueReader.jsonValue(
entry.value,
'$path.${entry.key}',
),
},
);
}