jsonSchema property

Map<String, dynamic> get jsonSchema

JSON Schema for this step's YAML argument object.

Implementation

Map<String, dynamic> get jsonSchema {
  switch (this) {
    case TestStepArgKind.empty:
      return _object();
    case TestStepArgKind.openScreen:
      return _object(properties: {'screen': _string, 'name': _string});
    case TestStepArgKind.trigger:
      return _object(
        properties: {
          'action': {
            'type': 'string',
            'enum': ['onLoad', 'onTap', 'onLongPress'],
          },
          'id': _string,
        },
        required: ['action'],
      );
    case TestStepArgKind.idRequired:
      return _targetable(
        properties: {'timeoutMs': _integer},
      );
    case TestStepArgKind.idRequiredNoTimeout:
      return _targetable();
    case TestStepArgKind.idOptional:
      return _targetable(targetRequired: false);
    case TestStepArgKind.enterText:
      return _targetable(
        properties: {'value': _any, 'submit': _boolean},
        required: ['value'],
      );
    case TestStepArgKind.select:
      return _targetable(
        properties: {'value': _string},
        required: ['value'],
      );
    case TestStepArgKind.selectIndex:
      return _targetable(
        properties: {'index': _integer},
        required: ['index'],
      );
    case TestStepArgKind.setSlider:
      return _targetable(
        properties: {
          'value': {'type': 'number'}
        },
        required: ['value'],
      );
    case TestStepArgKind.chooseValue:
      return _targetable(
        properties: {'value': _string},
        required: ['value'],
      );
    case TestStepArgKind.scroll:
      return _targetable(
        properties: {
          'delta': _integer,
          'direction': _string,
          'distance': {'type': 'number'},
        },
        targetRequired: false,
      );
    case TestStepArgKind.swipe:
      return _targetable(
        properties: {
          'direction': {
            'type': 'string',
            'enum': ['left', 'right', 'up', 'down'],
          },
        },
        targetRequired: false,
      );
    case TestStepArgKind.drag:
      return _targetable(
        properties: {
          'dx': {'type': 'number'},
          'dy': {'type': 'number'},
        },
      );
    case TestStepArgKind.pump:
      return _object(properties: {'durationMs': _integer});
    case TestStepArgKind.timeoutOptional:
      return _object(properties: {'timeoutMs': _integer});
    case TestStepArgKind.httpRequest:
      return _object(
        properties: {
          'url': _string,
          'method': {
            'type': 'string',
            'enum': [
              'GET',
              'POST',
              'PUT',
              'PATCH',
              'DELETE',
              'HEAD',
              'OPTIONS',
            ],
          },
          'headers': {
            'type': 'object',
            'additionalProperties': true,
          },
          'body': _any,
          'timeoutMs': _integer,
          'expectStatus': _integer,
          'expectBodyContains': _string,
        },
        required: ['url'],
      );
    case TestStepArgKind.waitFor:
      return {
        'type': 'object',
        'additionalProperties': false,
        'properties': {
          'id': _string,
          'target': _ref('elementLocator'),
          'text': _string,
          'anyOf': {
            'type': 'array',
            'items': _string,
            'minItems': 1,
          },
          'timeoutMs': _integer,
        },
        'anyOf': const [
          {
            'required': ['id']
          },
          {
            'required': ['target']
          },
          {
            'required': ['text']
          },
          {
            'required': ['anyOf']
          },
        ],
      };
    case TestStepArgKind.waitForGone:
      return _targetable(
        properties: {'timeoutMs': _integer},
      );
    case TestStepArgKind.waitForNavigation:
      return _object(
        properties: {'screen': _string, 'timeoutMs': _integer},
        required: ['screen'],
      );
    case TestStepArgKind.textRequired:
      return _object(properties: {'text': _string}, required: ['text']);
    case TestStepArgKind.textOrAnyOf:
      return {
        'type': 'object',
        'additionalProperties': false,
        'properties': {
          'text': _string,
          'anyOf': {
            'type': 'array',
            'items': _string,
            'minItems': 1,
          },
        },
        'anyOf': [
          {
            'required': ['text'],
          },
          {
            'required': ['anyOf'],
          },
        ],
      };
    case TestStepArgKind.textOrAnyOfWithTimeout:
      return {
        'type': 'object',
        'additionalProperties': false,
        'properties': {
          'text': _string,
          'anyOf': {
            'type': 'array',
            'items': _string,
            'minItems': 1,
          },
          'timeoutMs': _integer,
        },
        'anyOf': [
          {
            'required': ['text'],
          },
          {
            'required': ['anyOf'],
          },
        ],
      };
    case TestStepArgKind.textContains:
      return {
        'type': 'object',
        'additionalProperties': false,
        'properties': {
          'text': _string,
          'anyOf': {
            'type': 'array',
            'items': _string,
            'minItems': 1,
          },
          'timeoutMs': _integer,
        },
        'anyOf': [
          {
            'required': ['text'],
          },
          {
            'required': ['anyOf'],
          },
        ],
      };
    case TestStepArgKind.expectEquals:
      return _targetable(
        properties: {'equals': _any},
        required: ['equals'],
      );
    case TestStepArgKind.expectChecked:
      return _targetable(
        properties: {'equals': _boolean},
      );
    case TestStepArgKind.expectProperty:
      return _targetable(
        properties: {'property': _string, 'equals': _any},
        required: ['equals'],
      );
    case TestStepArgKind.expectCount:
      return _targetable(
        properties: {'equals': _integer},
        required: ['equals'],
      );
    case TestStepArgKind.expectListCount:
      return _targetable(
        properties: {'itemId': _string, 'equals': _integer},
        required: ['equals'],
      );
    case TestStepArgKind.expectListContains:
      return _targetable(
        properties: {'text': _string},
        required: ['text'],
      );
    case TestStepArgKind.expectListItem:
      return {
        'type': 'object',
        'properties': {
          'itemId': _string,
          'target': _ref('elementLocator'),
        },
        'anyOf': const [
          {
            'required': ['itemId']
          },
          {
            'required': ['target']
          },
        ],
        'additionalProperties': false,
      };
    case TestStepArgKind.screenRequired:
      return _object(
        properties: {'screen': _string, 'name': _string},
        required: ['screen'],
      );
    case TestStepArgKind.expectVisited:
      return _object(
        properties: {'screen': _string},
        required: ['screen'],
      );
    case TestStepArgKind.apiName:
      return _object(
        properties: {
          'name': _string,
          'times': _integer,
          'timeoutMs': _integer,
        },
        required: ['name'],
      );
    case TestStepArgKind.apiWait:
      return _object(
        properties: {
          'name': {
            'oneOf': [
              _string,
              {
                'type': 'array',
                'items': _string,
                'minItems': 1,
              },
            ],
          },
          'times': _integer,
          'timeoutMs': _integer,
        },
        required: ['name'],
      );
    case TestStepArgKind.storageKey:
      return _object(
        properties: {'key': _string, 'equals': _any, 'value': _any},
        required: ['key'],
      );
    case TestStepArgKind.group:
      return _object(
        properties: {
          'name': _string,
          'steps': {'type': 'array', 'items': _ref('step'), 'minItems': 1},
        },
        required: ['steps'],
      );
    case TestStepArgKind.repeat:
      return _object(
        properties: {
          'times': _integer,
          'steps': {'type': 'array', 'items': _ref('step'), 'minItems': 1},
        },
        required: ['times', 'steps'],
      );
    case TestStepArgKind.optional:
      return _object(
        properties: {
          'step': _ref('step'),
          'steps': {'type': 'array', 'items': _ref('step'), 'minItems': 1},
        },
      );
    case TestStepArgKind.ifVisible:
      return _targetable(
        properties: {
          'step': _ref('step'),
          'steps': {'type': 'array', 'items': _ref('step'), 'minItems': 1},
        },
      );
    case TestStepArgKind.setPermission:
      return _object(
        properties: {'name': _string, 'value': _string},
        required: ['name'],
      );
    case TestStepArgKind.setDevice:
      return _object(
        properties: {
          'width': {'type': 'number'},
          'height': {'type': 'number'},
        },
      );
    case TestStepArgKind.setLocale:
      return _object(properties: {'locale': _string});
    case TestStepArgKind.setTheme:
      return _object(properties: {'mode': _string, 'theme': _string});
    case TestStepArgKind.expectConsoleLog:
      return _object(
        properties: {'contains': _string},
        required: ['contains'],
      );
    case TestStepArgKind.expectErrorContains:
      return _object(properties: {'contains': _string});
    case TestStepArgKind.expectApiCallOrder:
      return _object(
        properties: {
          'names': {
            'type': 'array',
            'items': _string,
            'minItems': 1,
          },
        },
        required: ['names'],
      );
    case TestStepArgKind.expectBackStack:
      return _object(
        properties: {
          'screens': {
            'type': 'array',
            'items': _string,
            'minItems': 1,
          },
        },
        required: ['screens'],
      );
    case TestStepArgKind.expectCanGoBack:
      return _object(properties: {'equals': _boolean});
    case TestStepArgKind.expectSemanticsLabel:
      return _targetable(
        properties: {'label': _string},
        required: ['label'],
      );
  }
}