Skip to content

Commit 8fc503d

Browse files
chiciometa-codesync[bot]
authored andcommitted
AccessibilityInfo: added missing tests for Promise based methods, align null checks and error message code style (#56150)
Summary: This PR continue the work I'm doing to improve the `AccessibilityInfo` module (#56066 and connected PRs). In this new PR I added the missing tests for all the Promise based methods in the `AccessibilityInfo`, to prevent regressions similar to those fixed in the previous PRs. This PR also includes a couple of small code style consistency improvement: - aligned the null check in `getRecommendedTimeoutMillis` to the other ones already present in the file - aligned the error messages returned from `isGrayscaleEnabled`, `isInvertColorsEnabled` and `isReduceMotionEnabled` to the other ones - added the docs links where was missing (related to the PR I opened on the react-native doc repo) ## Changelog: [GENERAL] [ADDED] - AccessibilityInfo: added missing tests for Promise based methods, align null checks and error message code style Pull Request resolved: #56150 Test Plan: I run the tests that I added to verify their correctness. Some of them were failing because of the change of the error messages, and I made them green by changing the message in the production code. For this others, I verified their correctness by breaking the production code to see if they were failing. Reviewed By: cipolleschi Differential Revision: D102190403 Pulled By: cortinico fbshipit-source-id: f5fe5cacfe0136b25a93d05f3b136c2bc49bd0e2
1 parent 0518d72 commit 8fc503d

2 files changed

Lines changed: 625 additions & 20 deletions

File tree

packages/react-native/Libraries/Components/AccessibilityInfo/AccessibilityInfo.js

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ const AccessibilityInfo = {
136136
reject,
137137
);
138138
} else {
139-
reject(new Error('AccessibilityInfo native module is not available'));
139+
reject(new Error('NativeAccessibilityManagerIOS is not available'));
140140
}
141141
});
142142
}
@@ -171,7 +171,7 @@ const AccessibilityInfo = {
171171
reject,
172172
);
173173
} else {
174-
reject(new Error('AccessibilityInfo native module is not available'));
174+
reject(new Error('NativeAccessibilityManagerIOS is not available'));
175175
}
176176
});
177177
}
@@ -191,7 +191,7 @@ const AccessibilityInfo = {
191191
if (NativeAccessibilityInfoAndroid != null) {
192192
NativeAccessibilityInfoAndroid.isReduceMotionEnabled(resolve);
193193
} else {
194-
reject(new Error('AccessibilityInfo native module is not available'));
194+
reject(new Error('NativeAccessibilityInfoAndroid is not available'));
195195
}
196196
} else {
197197
if (NativeAccessibilityManagerIOS != null) {
@@ -211,6 +211,8 @@ const AccessibilityInfo = {
211211
*
212212
* Returns a promise which resolves to a boolean.
213213
* The result is `true` when high text contrast is enabled and `false` otherwise.
214+
*
215+
* See https://reactnative.dev/docs/accessibilityinfo#ishightextcontrastenabled-android
214216
*/
215217
isHighTextContrastEnabled(): Promise<boolean> {
216218
if (Platform.OS === 'android') {
@@ -235,6 +237,8 @@ const AccessibilityInfo = {
235237
*
236238
* Returns a promise which resolves to a boolean.
237239
* The result is `true` when dark system colors is enabled and `false` otherwise.
240+
*
241+
* See https://reactnative.dev/docs/accessibilityinfo#isdarkersystemcolorsenabled-ios
238242
*/
239243
isDarkerSystemColorsEnabled(): Promise<boolean> {
240244
if (Platform.OS === 'android') {
@@ -512,7 +516,9 @@ const AccessibilityInfo = {
512516
getRecommendedTimeoutMillis(originalTimeout: number): Promise<number> {
513517
if (Platform.OS === 'android') {
514518
return new Promise((resolve, reject) => {
515-
if (NativeAccessibilityInfoAndroid?.getRecommendedTimeoutMillis) {
519+
if (
520+
NativeAccessibilityInfoAndroid?.getRecommendedTimeoutMillis != null
521+
) {
516522
NativeAccessibilityInfoAndroid.getRecommendedTimeoutMillis(
517523
originalTimeout,
518524
resolve,

0 commit comments

Comments
 (0)