Skip to content

Commit 3b4db5c

Browse files
committed
add unit tests
1 parent ebb6187 commit 3b4db5c

1 file changed

Lines changed: 33 additions & 1 deletion

File tree

packages/grid/src/key-handlers/PasteKeyHandler.test.tsx

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { render } from '@testing-library/react';
2-
import { parseValueFromElement } from './PasteKeyHandler';
2+
import { parseValueFromElement, parseValueFromText } from './PasteKeyHandler';
33

44
function makeElementFromJsx(jsx: JSX.Element): HTMLElement {
55
return render(jsx).container;
@@ -130,3 +130,35 @@ describe('text parsing', () => {
130130
testHtml(<div>foo</div>, 'foo');
131131
});
132132
});
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

Comments
 (0)