Files
react-native/Libraries/Components/Touchable/__tests__/TouchableWithoutFeedback-test.js
T
Carlos Cuesta 697164077c Disable accessibilityState when TouchableWithoutFeedback is disabled (#31297)
Summary:
Disable `accessibilityState` when the `TouchableWithoutFeedback` is `disabled`. This fixes https://github.com/facebook/react-native/issues/30953

## Changelog

[General] [Changed] - Disable `accessibilityState` when the `TouchableWithoutFeedback` is `disabled`.

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

Test Plan: Tested the `TouchableWithoutFeedback` component on an Android device

Reviewed By: nadiia

Differential Revision: D27770689

Pulled By: kacieb

fbshipit-source-id: a317246021354ed288b093f8a5e6fbba43d3a04e
2021-04-16 14:37:38 -07:00

92 lines
2.4 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 TouchableWithoutFeedback from '../TouchableWithoutFeedback';
describe('TouchableWithoutFeedback', () => {
it('renders correctly', () => {
const instance = ReactTestRenderer.create(
<TouchableWithoutFeedback style={{}}>
<Text>Touchable</Text>
</TouchableWithoutFeedback>,
);
expect(instance.toJSON()).toMatchSnapshot();
});
it('has displayName', () => {
expect(TouchableWithoutFeedback.displayName).toEqual(
'TouchableWithoutFeedback',
);
});
});
describe('TouchableWithoutFeedback with disabled state', () => {
it('should be disabled when disabled is true', () => {
expect(
ReactTestRenderer.create(
<TouchableWithoutFeedback disabled={true}>
<View />
</TouchableWithoutFeedback>,
),
).toMatchSnapshot();
});
it('should be disabled when disabled is true and accessibilityState is empty', () => {
expect(
ReactTestRenderer.create(
<TouchableWithoutFeedback disabled={true} accessibilityState={{}}>
<View />
</TouchableWithoutFeedback>,
),
).toMatchSnapshot();
});
it('should keep accessibilityState when disabled is true', () => {
expect(
ReactTestRenderer.create(
<TouchableWithoutFeedback
disabled={true}
accessibilityState={{checked: true}}>
<View />
</TouchableWithoutFeedback>,
),
).toMatchSnapshot();
});
it('should overwrite accessibilityState with value of disabled prop', () => {
expect(
ReactTestRenderer.create(
<TouchableWithoutFeedback
disabled={true}
accessibilityState={{disabled: false}}>
<View />
</TouchableWithoutFeedback>,
),
).toMatchSnapshot();
});
it('should disable button when accessibilityState is disabled', () => {
expect(
ReactTestRenderer.create(
<TouchableWithoutFeedback accessibilityState={{disabled: true}}>
<View />
</TouchableWithoutFeedback>,
),
).toMatchSnapshot();
});
});