|
1 | | -import { |
2 | | - MAX_COLUMN_WIDTH, |
3 | | - PADDING_NO_SORT_ICON, |
4 | | - PADDING_WITH_SORT_ICON, |
5 | | - getColumnWidth, |
6 | | -} from './getColumnWidth'; |
| 1 | +import {HEADER_PADDING, MAX_COLUMN_WIDTH, getColumnWidth} from './getColumnWidth'; |
7 | 2 |
|
8 | 3 | describe('getColumnWidth', () => { |
9 | 4 | it('returns minimum width for empty data', () => { |
10 | | - const result = getColumnWidth({data: [], name: 'test', columnType: 'string'}); |
11 | | - expect(result).toBe(PADDING_NO_SORT_ICON + 'test'.length * 10); |
| 5 | + const result = getColumnWidth({data: [], name: 'test'}); |
| 6 | + expect(result).toBe(HEADER_PADDING + 'test'.length * 10); |
12 | 7 | }); |
13 | 8 |
|
14 | 9 | it('calculates correct width for string columns', () => { |
15 | 10 | const data = [{test: 'short'}, {test: 'medium length'}, {test: 'this is a longer string'}]; |
16 | | - const result = getColumnWidth({data, name: 'test', columnType: 'string'}); |
17 | | - expect(result).toBe(PADDING_NO_SORT_ICON + 'this is a longer string'.length * 10); |
18 | | - }); |
19 | | - |
20 | | - it('calculates correct width for number columns', () => { |
21 | | - const data = [{test: 123}, {test: 456789}, {test: 0}]; |
22 | | - const result = getColumnWidth({data, name: 'test', columnType: 'number'}); |
23 | | - expect(result).toBe(PADDING_WITH_SORT_ICON + '456789'.length * 10); |
| 11 | + const result = getColumnWidth({data, name: 'test'}); |
| 12 | + expect(result).toBe(HEADER_PADDING + 'this is a longer string'.length * 10); |
24 | 13 | }); |
25 | 14 |
|
26 | 15 | it('returns MAX_COLUMN_WIDTH when calculated width exceeds it', () => { |
27 | 16 | const data = [{test: 'a'.repeat(100)}]; |
28 | | - const result = getColumnWidth({data, name: 'test', columnType: 'string'}); |
| 17 | + const result = getColumnWidth({data, name: 'test'}); |
29 | 18 | expect(result).toBe(MAX_COLUMN_WIDTH); |
30 | 19 | }); |
31 | 20 |
|
32 | 21 | it('handles undefined data correctly', () => { |
33 | | - const result = getColumnWidth({name: 'test', columnType: 'string'}); |
34 | | - expect(result).toBe(PADDING_NO_SORT_ICON + 'test'.length * 10); |
| 22 | + const result = getColumnWidth({name: 'test'}); |
| 23 | + expect(result).toBe(HEADER_PADDING + 'test'.length * 10); |
35 | 24 | }); |
36 | 25 |
|
37 | 26 | it('handles missing values in data correctly', () => { |
38 | 27 | const data = [{test: 'short'}, {}, {test: 'longer string'}]; |
39 | | - const result = getColumnWidth({data, name: 'test', columnType: 'string'}); |
40 | | - expect(result).toBe(PADDING_NO_SORT_ICON + 'longer string'.length * 10); |
| 28 | + const result = getColumnWidth({data, name: 'test'}); |
| 29 | + expect(result).toBe(HEADER_PADDING + 'longer string'.length * 10); |
41 | 30 | }); |
42 | 31 |
|
43 | 32 | it('uses column name length when all values are shorter', () => { |
44 | 33 | const data = [{longColumnName: 'a'}, {longColumnName: 'bb'}]; |
45 | | - const result = getColumnWidth({data, name: 'longColumnName', columnType: 'string'}); |
46 | | - expect(result).toBe(PADDING_NO_SORT_ICON + 'longColumnName'.length * 10); |
| 34 | + const result = getColumnWidth({data, name: 'longColumnName'}); |
| 35 | + expect(result).toBe(HEADER_PADDING + 'longColumnName'.length * 10); |
47 | 36 | }); |
48 | 37 | }); |
0 commit comments