|
1 | 1 | import { render } from '@testing-library/react'; |
2 | | -import { parseValueFromElement } from './PasteKeyHandler'; |
| 2 | +import { parseValueFromElement, parseValueFromText } from './PasteKeyHandler'; |
3 | 3 |
|
4 | 4 | function makeElementFromJsx(jsx: JSX.Element): HTMLElement { |
5 | 5 | return render(jsx).container; |
@@ -130,3 +130,35 @@ describe('text parsing', () => { |
130 | 130 | testHtml(<div>foo</div>, 'foo'); |
131 | 131 | }); |
132 | 132 | }); |
| 133 | + |
| 134 | +describe('parseValueFromText', () => { |
| 135 | + it('parses a single numeric value', () => { |
| 136 | + expect(parseValueFromText('12345')).toBe('12345'); |
| 137 | + }); |
| 138 | + |
| 139 | + it('trims whitespace for single value', () => { |
| 140 | + expect(parseValueFromText(' 3.14 \n')).toBe('3.14'); |
| 141 | + }); |
| 142 | + |
| 143 | + it('parses a table with multiple rows and columns', () => { |
| 144 | + expect( |
| 145 | + parseValueFromText('12345\t3.14\thello\n67890\t2.71\tworld\n') |
| 146 | + ).toEqual([ |
| 147 | + ['12345', '3.14', 'hello'], |
| 148 | + ['67890', '2.71', 'world'], |
| 149 | + ]); |
| 150 | + }); |
| 151 | + |
| 152 | + it('parses a single row from text', () => { |
| 153 | + expect(parseValueFromText('12345\t67890\t99999')).toEqual([ |
| 154 | + ['12345', '67890', '99999'], |
| 155 | + ]); |
| 156 | + }); |
| 157 | + |
| 158 | + it('trims trailing newline without creating an empty row', () => { |
| 159 | + expect(parseValueFromText('A\tB\n1\t2\n')).toEqual([ |
| 160 | + ['A', 'B'], |
| 161 | + ['1', '2'], |
| 162 | + ]); |
| 163 | + }); |
| 164 | +}); |
0 commit comments