Files
react-native/Libraries/Components/Touchable/__tests__/TouchableHighlight-test.js
T
Jesse KatsumataandFacebook GitHub Bot f69e096bb4 feat: set disabled accessibilityState when TouchableHighlight is disabled (#31135)
Summary:
https://github.com/facebook/react-native/issues/30950

automatically set `disabled` to accessibilityState when TouchableHighlight is disabled

## Changelog

<!-- Help reviewers and the release process by writing your own changelog entry. For an example, see:
https://github.com/facebook/react-native/wiki/Changelog
-->

[General] [Changed] - Set disabled accessibilityState when TouchableHighlight is disabled

Pull Request resolved: https://github.com/facebook/react-native/pull/31135

Test Plan: Tested on physical android device that pressing disabled TouchableHighlight announces "dim" when talkback is on

Reviewed By: yungsters, nadiia

Differential Revision: D27157207

Pulled By: kacieb

fbshipit-source-id: b8e24aad699c43cf02401b3ba39726a06b751995
2021-03-22 14:04:16 -07:00

86 lines
2.2 KiB
JavaScript

/**
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @format
* @emails oncall+react_native
*/
'use strict';
import * as React from 'react';
import ReactTestRenderer from 'react-test-renderer';
import Text from '../../../Text/Text';
import View from '../../View/View';
import TouchableHighlight from '../TouchableHighlight';
describe('TouchableHighlight', () => {
it('renders correctly', () => {
const instance = ReactTestRenderer.create(
<TouchableHighlight style={{}}>
<Text>Touchable</Text>
</TouchableHighlight>,
);
expect(instance.toJSON()).toMatchSnapshot();
});
});
describe('TouchableHighlight with disabled state', () => {
it('should be disabled when disabled is true', () => {
expect(
ReactTestRenderer.create(
<TouchableHighlight disabled={true}>
<View />
</TouchableHighlight>,
),
).toMatchSnapshot();
});
it('should be disabled when disabled is true and accessibilityState is empty', () => {
expect(
ReactTestRenderer.create(
<TouchableHighlight disabled={true} accessibilityState={{}}>
<View />
</TouchableHighlight>,
),
).toMatchSnapshot();
});
it('should keep accessibilityState when disabled is true', () => {
expect(
ReactTestRenderer.create(
<TouchableHighlight
disabled={true}
accessibilityState={{checked: true}}>
<View />
</TouchableHighlight>,
),
).toMatchSnapshot();
});
it('should overwrite accessibilityState with value of disabled prop', () => {
expect(
ReactTestRenderer.create(
<TouchableHighlight
disabled={true}
accessibilityState={{disabled: false}}>
<View />
</TouchableHighlight>,
),
).toMatchSnapshot();
});
it('should disable button when accessibilityState is disabled', () => {
expect(
ReactTestRenderer.create(
<TouchableHighlight accessibilityState={{disabled: true}}>
<View />
</TouchableHighlight>,
),
).toMatchSnapshot();
});
});