|
6 | 6 |
|
7 | 7 | /* eslint-env jest */ |
8 | 8 |
|
9 | | -import loadAttributes from '../../src/loadAttributes'; |
| 9 | +import loadAttributes, { getItemOnPress } from '../../src/loadAttributes'; |
| 10 | + |
| 11 | +describe('getItemOnPress()', () => { |
| 12 | + test('returns the right function', () => { |
| 13 | + const navigate = jest.fn(); |
| 14 | + const resultFn = getItemOnPress( |
| 15 | + { key: 'test' }, |
| 16 | + { test: { data: { url: 'http://ok' } } }, |
| 17 | + navigate, |
| 18 | + ); |
| 19 | + resultFn(); |
| 20 | + expect(navigate.mock.calls.length).toBe(1); |
| 21 | + }); |
| 22 | + |
| 23 | + test('returns the right function', () => { |
| 24 | + expect(getItemOnPress({})).toBe(); |
| 25 | + }); |
| 26 | +}); |
10 | 27 |
|
11 | 28 | it('returns only text if other objects are empty', () => { |
12 | 29 | const params = { |
@@ -128,10 +145,40 @@ it('have correct length with multiple inlineStyles and text with substring witho |
128 | 145 | length: 3, |
129 | 146 | style: 'ITALIC', |
130 | 147 | }, |
| 148 | + { |
| 149 | + offset: 7, |
| 150 | + length: 3, |
| 151 | + style: 'LINK', |
| 152 | + }, |
131 | 153 | ], |
132 | | - entityMap: {}, |
| 154 | + entityMap: { |
| 155 | + 0: { |
| 156 | + type: 'LINK', |
| 157 | + mutability: 'MUTABLE', |
| 158 | + data: { |
| 159 | + url: 'https://github.com/globocom/react-native-draftjs-render', |
| 160 | + }, |
| 161 | + }, |
| 162 | + }, |
133 | 163 | entityRanges: [], |
134 | 164 | }; |
135 | 165 | const result = loadAttributes(params); |
136 | 166 | expect(result).toHaveLength(5); |
| 167 | + expect(result[4].props.children).toBe('d Hello World Hello World'); |
| 168 | +}); |
| 169 | + |
| 170 | +it('have correct length with multiple inlineStyles and text with substring without style', () => { |
| 171 | + const params = { |
| 172 | + text: 'Hello World Hello World Hello World', |
| 173 | + inlineStyles: [{ |
| 174 | + offset: 300, |
| 175 | + length: 2, |
| 176 | + style: 'BOLD', |
| 177 | + }], |
| 178 | + entityMap: {}, |
| 179 | + entityRanges: [], |
| 180 | + }; |
| 181 | + const result = loadAttributes(params); |
| 182 | + expect(result).toHaveLength(2); |
| 183 | + expect(result[0].props.children).toBe(params.text); |
137 | 184 | }); |
0 commit comments