|
| 1 | +/** |
| 2 | + * Copyright (c) Meta Platforms, Inc. and affiliates. |
| 3 | + * |
| 4 | + * This source code is licensed under the MIT license found in the |
| 5 | + * LICENSE file in the root directory of this source tree. |
| 6 | + * |
| 7 | + * @flow strict-local |
| 8 | + * @format |
| 9 | + * @oncall react_native |
| 10 | + */ |
| 11 | + |
| 12 | +import '@react-native/fantom/src/setUpDefaultReactNativeEnvironment'; |
| 13 | + |
| 14 | +import * as Fantom from '@react-native/fantom'; |
| 15 | +import * as React from 'react'; |
| 16 | +import {Text, TouchableHighlight, View} from 'react-native'; |
| 17 | + |
| 18 | +describe('<TouchableHighlight>', () => { |
| 19 | + describe('rendering', () => { |
| 20 | + it('renders as a view with accessible="true"', () => { |
| 21 | + const root = Fantom.createRoot(); |
| 22 | + |
| 23 | + Fantom.runTask(() => { |
| 24 | + root.render( |
| 25 | + <TouchableHighlight> |
| 26 | + <View collapsable={false} /> |
| 27 | + </TouchableHighlight>, |
| 28 | + ); |
| 29 | + }); |
| 30 | + |
| 31 | + expect(root.getRenderedOutput({props: ['accessible']}).toJSX()).toEqual( |
| 32 | + <rn-view accessible="true"> |
| 33 | + <rn-view /> |
| 34 | + </rn-view>, |
| 35 | + ); |
| 36 | + }); |
| 37 | + |
| 38 | + it('renders children inside the touchable', () => { |
| 39 | + const root = Fantom.createRoot(); |
| 40 | + |
| 41 | + Fantom.runTask(() => { |
| 42 | + root.render( |
| 43 | + <TouchableHighlight> |
| 44 | + <Text>Touchable</Text> |
| 45 | + </TouchableHighlight>, |
| 46 | + ); |
| 47 | + }); |
| 48 | + |
| 49 | + expect(root.getRenderedOutput({props: ['accessible']}).toJSX()).toEqual( |
| 50 | + <rn-view accessible="true"> |
| 51 | + <rn-paragraph>Touchable</rn-paragraph> |
| 52 | + </rn-view>, |
| 53 | + ); |
| 54 | + }); |
| 55 | + }); |
| 56 | + |
| 57 | + describe('disabled', () => { |
| 58 | + it('sets accessibilityState disabled to true when disabled={true}', () => { |
| 59 | + const root = Fantom.createRoot(); |
| 60 | + |
| 61 | + Fantom.runTask(() => { |
| 62 | + root.render( |
| 63 | + <TouchableHighlight disabled={true}> |
| 64 | + <View collapsable={false} /> |
| 65 | + </TouchableHighlight>, |
| 66 | + ); |
| 67 | + }); |
| 68 | + |
| 69 | + expect( |
| 70 | + root.getRenderedOutput({props: ['accessibilityState']}).toJSX(), |
| 71 | + ).toEqual( |
| 72 | + <rn-view accessibilityState="{disabled:true,selected:false,checked:None,busy:false,expanded:null}"> |
| 73 | + <rn-view /> |
| 74 | + </rn-view>, |
| 75 | + ); |
| 76 | + }); |
| 77 | + |
| 78 | + it('sets accessibilityState disabled to true when disabled={true} and accessibilityState is empty', () => { |
| 79 | + const root = Fantom.createRoot(); |
| 80 | + |
| 81 | + Fantom.runTask(() => { |
| 82 | + root.render( |
| 83 | + <TouchableHighlight disabled={true} accessibilityState={{}}> |
| 84 | + <View collapsable={false} /> |
| 85 | + </TouchableHighlight>, |
| 86 | + ); |
| 87 | + }); |
| 88 | + |
| 89 | + expect( |
| 90 | + root.getRenderedOutput({props: ['accessibilityState']}).toJSX(), |
| 91 | + ).toEqual( |
| 92 | + <rn-view accessibilityState="{disabled:true,selected:false,checked:None,busy:false,expanded:null}"> |
| 93 | + <rn-view /> |
| 94 | + </rn-view>, |
| 95 | + ); |
| 96 | + }); |
| 97 | + |
| 98 | + it('keeps other accessibilityState fields when disabled={true}', () => { |
| 99 | + const root = Fantom.createRoot(); |
| 100 | + |
| 101 | + Fantom.runTask(() => { |
| 102 | + root.render( |
| 103 | + <TouchableHighlight |
| 104 | + disabled={true} |
| 105 | + accessibilityState={{checked: true}}> |
| 106 | + <View collapsable={false} /> |
| 107 | + </TouchableHighlight>, |
| 108 | + ); |
| 109 | + }); |
| 110 | + |
| 111 | + expect( |
| 112 | + root.getRenderedOutput({props: ['accessibilityState']}).toJSX(), |
| 113 | + ).toEqual( |
| 114 | + <rn-view accessibilityState="{disabled:true,selected:false,checked:Checked,busy:false,expanded:null}"> |
| 115 | + <rn-view /> |
| 116 | + </rn-view>, |
| 117 | + ); |
| 118 | + }); |
| 119 | + |
| 120 | + it('overrides accessibilityState disabled=false with disabled prop', () => { |
| 121 | + const root = Fantom.createRoot(); |
| 122 | + |
| 123 | + Fantom.runTask(() => { |
| 124 | + root.render( |
| 125 | + <TouchableHighlight |
| 126 | + disabled={true} |
| 127 | + accessibilityState={{disabled: false}}> |
| 128 | + <View collapsable={false} /> |
| 129 | + </TouchableHighlight>, |
| 130 | + ); |
| 131 | + }); |
| 132 | + |
| 133 | + expect( |
| 134 | + root.getRenderedOutput({props: ['accessibilityState']}).toJSX(), |
| 135 | + ).toEqual( |
| 136 | + <rn-view accessibilityState="{disabled:true,selected:false,checked:None,busy:false,expanded:null}"> |
| 137 | + <rn-view /> |
| 138 | + </rn-view>, |
| 139 | + ); |
| 140 | + }); |
| 141 | + |
| 142 | + it('sets accessibilityState disabled when only accessibilityState has disabled=true', () => { |
| 143 | + const root = Fantom.createRoot(); |
| 144 | + |
| 145 | + Fantom.runTask(() => { |
| 146 | + root.render( |
| 147 | + <TouchableHighlight accessibilityState={{disabled: true}}> |
| 148 | + <View collapsable={false} /> |
| 149 | + </TouchableHighlight>, |
| 150 | + ); |
| 151 | + }); |
| 152 | + |
| 153 | + expect( |
| 154 | + root.getRenderedOutput({props: ['accessibilityState']}).toJSX(), |
| 155 | + ).toEqual( |
| 156 | + <rn-view accessibilityState="{disabled:true,selected:false,checked:None,busy:false,expanded:null}"> |
| 157 | + <rn-view /> |
| 158 | + </rn-view>, |
| 159 | + ); |
| 160 | + }); |
| 161 | + }); |
| 162 | +}); |
0 commit comments