Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -237,10 +237,10 @@ const AccessibilityInfo = {
* The result is `true` when dark system colors is enabled and `false` otherwise.
*/
isDarkerSystemColorsEnabled(): Promise<boolean> {
return new Promise((resolve, reject) => {
if (Platform.OS === 'android') {
return Promise.resolve(false);
} else {
if (Platform.OS === 'android') {
return Promise.resolve(false);
} else {
return new Promise((resolve, reject) => {
if (
NativeAccessibilityManagerIOS?.getCurrentDarkerSystemColorsState !=
null
Expand All @@ -256,8 +256,8 @@ const AccessibilityInfo = {
),
);
}
}
});
});
}
},

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ jest.unmock('../AccessibilityInfo');
const mockGetCurrentPrefersCrossFadeTransitionsState = jest.fn(
(onSuccess, onError) => onSuccess(true),
);
const mockGetCurrentDarkerSystemColorsState = jest.fn((onSuccess, onError) =>
onSuccess(true),
);
const mockNativeAccessibilityManagerDefault: {
getCurrentPrefersCrossFadeTransitionsState: JestMockFn<
[
Expand All @@ -21,9 +24,17 @@ const mockNativeAccessibilityManagerDefault: {
],
void,
> | null,
getCurrentDarkerSystemColorsState: JestMockFn<
[
onSuccess: (isDarkerSystemColorsEnabled: boolean) => void,
onError: (error: Error) => void,
],
void,
> | null,
} = {
getCurrentPrefersCrossFadeTransitionsState:
mockGetCurrentPrefersCrossFadeTransitionsState,
getCurrentDarkerSystemColorsState: mockGetCurrentDarkerSystemColorsState,
};

jest.mock('../NativeAccessibilityManager', () => ({
Expand All @@ -41,6 +52,7 @@ describe('AccessibilityInfo', () => {
beforeEach(() => {
originalPlatform = Platform.OS;
mockGetCurrentPrefersCrossFadeTransitionsState.mockClear();
mockGetCurrentDarkerSystemColorsState.mockClear();
});

describe('prefersCrossFadeTransitions', () => {
Expand Down Expand Up @@ -91,9 +103,57 @@ describe('AccessibilityInfo', () => {
});
});

describe('isDarkerSystemColorsEnabled', () => {
describe('Android', () => {
it('should return immediately', async () => {
/* $FlowFixMe[incompatible-type] */
Platform.OS = 'android';

const isDarkerSystemColorsEnabled =
await AccessibilityInfo.isDarkerSystemColorsEnabled();

expect(isDarkerSystemColorsEnabled).toBe(false);
});
});

describe('iOS', () => {
it('should call getCurrentDarkerSystemColorsState if available', async () => {
/* $FlowFixMe[incompatible-type] */
Platform.OS = 'ios';

const isDarkerSystemColorsEnabled =
await AccessibilityInfo.isDarkerSystemColorsEnabled();

expect(mockGetCurrentDarkerSystemColorsState).toHaveBeenCalled();
expect(isDarkerSystemColorsEnabled).toBe(true);
});

it('should throw error if getCurrentDarkerSystemColorsState is not available', async () => {
/* $FlowFixMe[incompatible-type] */
Platform.OS = 'ios';

mockNativeAccessibilityManagerDefault.getCurrentDarkerSystemColorsState =
null;

const result: mixed =
await AccessibilityInfo.isDarkerSystemColorsEnabled().catch(e => e);

invariant(
result instanceof Error,
'Expected isDarkerSystemColorsEnabled to reject',
);
expect(result.message).toEqual(
'NativeAccessibilityManagerIOS.getCurrentDarkerSystemColorsState is not available',
);
});
});
});

afterEach(() => {
mockNativeAccessibilityManagerDefault.getCurrentPrefersCrossFadeTransitionsState =
mockGetCurrentPrefersCrossFadeTransitionsState;
mockNativeAccessibilityManagerDefault.getCurrentDarkerSystemColorsState =
mockGetCurrentDarkerSystemColorsState;
/* $FlowFixMe[incompatible-type] */
Platform.OS = originalPlatform;
});
Expand Down
Loading