|
| 1 | +import { ReactNativePropsSwitch } from '../../helper-types'; |
1 | 2 | import HTMLModelRegistry from '../../model/HTMLModelRegistry'; |
2 | 3 | import { TStyles } from '../../styles/TStyles'; |
3 | 4 | import { TEmptyCtor } from '../../tree/TEmptyCtor'; |
@@ -107,6 +108,68 @@ describe('translateNode function', () => { |
107 | 108 | expect(child.nodeIndex).toBe(i); |
108 | 109 | }); |
109 | 110 | }); |
| 111 | + describe('regarding images accessiblity', () => { |
| 112 | + it('should not provide accessibility to images with role="presentation"', () => { |
| 113 | + const ttree = translateTreeTest( |
| 114 | + '<img role="presentation" alt="foo" src="https://" />' |
| 115 | + ); |
| 116 | + expect(ttree.getReactNativeProps()).toEqual<ReactNativePropsSwitch>({ |
| 117 | + text: { |
| 118 | + accessibilityRole: 'none' |
| 119 | + }, |
| 120 | + view: { |
| 121 | + accessibilityRole: 'none' |
| 122 | + } |
| 123 | + }); |
| 124 | + }); |
| 125 | + |
| 126 | + it('should provide accessibility to images with role="image" and non-empty alt', () => { |
| 127 | + const ttree = translateTreeTest( |
| 128 | + '<img role="image" alt="foo" src="https://" />' |
| 129 | + ); |
| 130 | + expect(ttree.getReactNativeProps()).toEqual<ReactNativePropsSwitch>({ |
| 131 | + text: { |
| 132 | + accessibilityLabel: 'foo', |
| 133 | + accessibilityRole: 'image' |
| 134 | + }, |
| 135 | + view: { |
| 136 | + accessibilityLabel: 'foo', |
| 137 | + accessibilityRole: 'image' |
| 138 | + } |
| 139 | + }); |
| 140 | + }); |
| 141 | + it('should provide accessibility to images with role="image" and non-empty aria-label', () => { |
| 142 | + const ttree = translateTreeTest( |
| 143 | + '<img role="image" aria-label="foo" src="https://" />' |
| 144 | + ); |
| 145 | + expect(ttree.getReactNativeProps()).toEqual<ReactNativePropsSwitch>({ |
| 146 | + text: { |
| 147 | + accessibilityLabel: 'foo', |
| 148 | + accessibilityRole: 'image' |
| 149 | + }, |
| 150 | + view: { |
| 151 | + accessibilityLabel: 'foo', |
| 152 | + accessibilityRole: 'image' |
| 153 | + } |
| 154 | + }); |
| 155 | + }); |
| 156 | + |
| 157 | + it('should prefer aria-label over alt to generate an accessibilityLabel prop', () => { |
| 158 | + const ttree = translateTreeTest( |
| 159 | + '<img role="image" aria-label="foo" alt="bar" src="https://" />' |
| 160 | + ); |
| 161 | + expect(ttree.getReactNativeProps()).toEqual<ReactNativePropsSwitch>({ |
| 162 | + text: { |
| 163 | + accessibilityLabel: 'foo', |
| 164 | + accessibilityRole: 'image' |
| 165 | + }, |
| 166 | + view: { |
| 167 | + accessibilityLabel: 'foo', |
| 168 | + accessibilityRole: 'image' |
| 169 | + } |
| 170 | + }); |
| 171 | + }); |
| 172 | + }); |
110 | 173 | describe('regarding markers', () => { |
111 | 174 | it('should set an anchor marker with <a> elements', () => { |
112 | 175 | const ttree = translateTreeTest('<a href="hello">Yo!</a>'); |
|
0 commit comments