(instance: TestInstance)
| 150 | } |
| 151 | |
| 152 | export function computeAriaLabel(instance: TestInstance): string | undefined { |
| 153 | const labelElementIds = getAriaLabelledByIds(instance); |
| 154 | if (labelElementIds.length > 0) { |
| 155 | const container = getContainerInstance(instance); |
| 156 | const labelTexts = labelElementIds |
| 157 | .map((labelElementId) => { |
| 158 | const labelInstance = findAll( |
| 159 | container, |
| 160 | (node) => isTestInstance(node) && node.props.nativeID === labelElementId, |
| 161 | { includeHiddenElements: true }, |
| 162 | ); |
| 163 | |
| 164 | return labelInstance.length > 0 ? getTextContent(labelInstance[0]) : undefined; |
| 165 | }) |
| 166 | .filter((labelText): labelText is string => labelText !== undefined); |
| 167 | |
| 168 | if (labelTexts.length > 0) { |
| 169 | return labelTexts.join(' ').trim().replace(/\s+/g, ' '); |
| 170 | } |
| 171 | } |
| 172 | |
| 173 | const explicitLabel = instance.props['aria-label'] ?? instance.props.accessibilityLabel; |
| 174 | if (explicitLabel) { |
| 175 | return explicitLabel; |
| 176 | } |
| 177 | |
| 178 | //https://github.com/facebook/react-native/blob/8dabed60f456e76a9e53273b601446f34de41fb5/packages/react-native/Libraries/Image/Image.ios.js#L173 |
| 179 | if (isHostImage(instance) && instance.props.alt) { |
| 180 | return instance.props.alt; |
| 181 | } |
| 182 | |
| 183 | return undefined; |
| 184 | } |
| 185 | |
| 186 | function getAriaLabelledByIds(instance: TestInstance): string[] { |
| 187 | const ariaLabelledBy = instance.props['aria-labelledby']; |
no test coverage detected
searching dependent graphs…