|
1 | 1 | import * as React from 'react';
|
2 |
| -import { TouchableOpacity, Text, View } from 'react-native'; |
| 2 | +import { |
| 3 | + TouchableOpacity, |
| 4 | + TouchableWithoutFeedback, |
| 5 | + Text, |
| 6 | + View, |
| 7 | + Pressable, |
| 8 | + Button as RNButton, |
| 9 | +} from 'react-native'; |
3 | 10 | import { render } from '../..';
|
4 | 11 |
|
5 | 12 | const TEXT_LABEL = 'cool text';
|
@@ -245,6 +252,39 @@ describe('supports accessibility states', () => {
|
245 | 252 |
|
246 | 253 | expect(queryByRole('button', { disabled: false })).toBe(null);
|
247 | 254 | });
|
| 255 | + |
| 256 | + test('returns elements using the built-in disabled prop', () => { |
| 257 | + const { debug, getByRole } = render( |
| 258 | + <> |
| 259 | + <Pressable disabled accessibilityRole="button"> |
| 260 | + <Text>Pressable</Text> |
| 261 | + </Pressable> |
| 262 | + |
| 263 | + <TouchableWithoutFeedback disabled accessibilityRole="button"> |
| 264 | + <View> |
| 265 | + <Text>TouchableWithoutFeedback</Text> |
| 266 | + </View> |
| 267 | + </TouchableWithoutFeedback> |
| 268 | + <RNButton disabled onPress={() => {}} title="RNButton" /> |
| 269 | + </> |
| 270 | + ); |
| 271 | + |
| 272 | + expect( |
| 273 | + getByRole('button', { name: 'Pressable', disabled: true }) |
| 274 | + ).toBeTruthy(); |
| 275 | + |
| 276 | + expect( |
| 277 | + getByRole('button', { |
| 278 | + name: 'TouchableWithoutFeedback', |
| 279 | + disabled: true, |
| 280 | + }) |
| 281 | + ).toBeTruthy(); |
| 282 | + debug(); |
| 283 | + |
| 284 | + expect( |
| 285 | + getByRole('button', { name: 'RNButton', disabled: true }) |
| 286 | + ).toBeTruthy(); |
| 287 | + }); |
248 | 288 | });
|
249 | 289 |
|
250 | 290 | describe('selected', () => {
|
@@ -525,6 +565,28 @@ describe('supports accessibility states', () => {
|
525 | 565 | });
|
526 | 566 | });
|
527 | 567 |
|
| 568 | + test('ignores non queried accessibilityState', () => { |
| 569 | + const { getByRole } = render( |
| 570 | + <TouchableOpacity |
| 571 | + accessibilityRole="button" |
| 572 | + accessibilityState={{ |
| 573 | + disabled: true, |
| 574 | + // set `selected`, but don't query it |
| 575 | + selected: true, |
| 576 | + }} |
| 577 | + > |
| 578 | + <Text>Save</Text> |
| 579 | + </TouchableOpacity> |
| 580 | + ); |
| 581 | + |
| 582 | + expect( |
| 583 | + getByRole('button', { |
| 584 | + name: 'Save', |
| 585 | + disabled: true, |
| 586 | + }) |
| 587 | + ).toBeTruthy(); |
| 588 | + }); |
| 589 | + |
528 | 590 | test('matches an element combining all the options', () => {
|
529 | 591 | const { getByRole } = render(
|
530 | 592 | <TouchableOpacity
|
|
0 commit comments