# All files / src/queries hintText.ts

100% Statements 20/20
100% Branches 3/3
100% Functions 7/7
100% Lines 20/20

Press n or j to go to the next uncovered block, b, p or k for the previous block.

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113

    48x

    571x
    571x

    48x

    532x
    149x

    2186x

    48x
    22x
    48x
    85x

    48x

    48x

    386x
    386x
    386x
    386x
    386x
    386x

    386x

     import type { ReactTestInstance } from 'react-test-renderer';
    import { findAll } from '../helpers/findAll';
    import { matches, TextMatch, TextMatchOptions } from '../matches';
    import { makeQueries } from './makeQueries';
    import type {
      FindAllByQuery,
      FindByQuery,
      GetAllByQuery,
      GetByQuery,
      QueryAllByQuery,
      QueryByQuery,
    } from './makeQueries';
    import { CommonQueryOptions } from './options';

    type ByHintTextOptions = CommonQueryOptions & TextMatchOptions;

    const getNodeByHintText = (
      node: ReactTestInstance,
      text: TextMatch,
      options: TextMatchOptions = {}
    ) => {
      const { exact, normalizer } = options;
      return matches(text, node.props.accessibilityHint, normalizer, exact);
    };

    const queryAllByHintText = (
      instance: ReactTestInstance
    ): ((
      hint: TextMatch,
      queryOptions?: ByHintTextOptions
    ) => Array<ReactTestInstance>) =>
      function queryAllByA11yHintFn(hint, queryOptions) {
        return findAll(
          instance,
          (node) =>
            typeof node.type === 'string' &&
            getNodeByHintText(node, hint, queryOptions),
          queryOptions
        );
      };

    const getMultipleError = (hint: TextMatch) =>
      `Found multiple elements with accessibilityHint: ${String(hint)} `;
    const getMissingError = (hint: TextMatch) =>
      `Unable to find an element with accessibilityHint: ${String(hint)}`;

    const { getBy, getAllBy, queryBy, queryAllBy, findBy, findAllBy } = makeQueries(
      queryAllByHintText,
      getMissingError,
      getMultipleError
    );

    export type ByHintTextQueries = {
      getByHintText: GetByQuery<TextMatch, ByHintTextOptions>;
      getAllByHintText: GetAllByQuery<TextMatch, ByHintTextOptions>;
      queryByHintText: QueryByQuery<TextMatch, ByHintTextOptions>;
      queryAllByHintText: QueryAllByQuery<TextMatch, ByHintTextOptions>;
      findByHintText: FindByQuery<TextMatch, ByHintTextOptions>;
      findAllByHintText: FindAllByQuery<TextMatch, ByHintTextOptions>;

      // a11yHint aliases
      getByA11yHint: GetByQuery<TextMatch, ByHintTextOptions>;
      getAllByA11yHint: GetAllByQuery<TextMatch, ByHintTextOptions>;
      queryByA11yHint: QueryByQuery<TextMatch, ByHintTextOptions>;
      queryAllByA11yHint: QueryAllByQuery<TextMatch, ByHintTextOptions>;
      findByA11yHint: FindByQuery<TextMatch, ByHintTextOptions>;
      findAllByA11yHint: FindAllByQuery<TextMatch, ByHintTextOptions>;

      // accessibilityHint aliases
      getByAccessibilityHint: GetByQuery<TextMatch, ByHintTextOptions>;
      getAllByAccessibilityHint: GetAllByQuery<TextMatch, ByHintTextOptions>;
      queryByAccessibilityHint: QueryByQuery<TextMatch, ByHintTextOptions>;
      queryAllByAccessibilityHint: QueryAllByQuery<TextMatch, ByHintTextOptions>;
      findByAccessibilityHint: FindByQuery<TextMatch, ByHintTextOptions>;
      findAllByAccessibilityHint: FindAllByQuery<TextMatch, ByHintTextOptions>;
    };

    export const bindByHintTextQueries = (
      instance: ReactTestInstance
    ): ByHintTextQueries => {
      const getByHintText = getBy(instance);
      const getAllByHintText = getAllBy(instance);
      const queryByHintText = queryBy(instance);
      const queryAllByHintText = queryAllBy(instance);
      const findByHintText = findBy(instance);
      const findAllByHintText = findAllBy(instance);

      return {
        getByHintText,
        getAllByHintText,
        queryByHintText,
        queryAllByHintText,
        findByHintText,
        findAllByHintText,

        // a11yHint aliases
        getByA11yHint: getByHintText,
        getAllByA11yHint: getAllByHintText,
        queryByA11yHint: queryByHintText,
        queryAllByA11yHint: queryAllByHintText,
        findByA11yHint: findByHintText,
        findAllByA11yHint: findAllByHintText,

        // accessibilityHint aliases
        getByAccessibilityHint: getByHintText,
        getAllByAccessibilityHint: getAllByHintText,
        queryByAccessibilityHint: queryByHintText,
        queryAllByAccessibilityHint: queryAllByHintText,
        findByAccessibilityHint: findByHintText,
        findAllByAccessibilityHint: findAllByHintText,
      };
    };