UNPKG

@cainiaofe/cn-ui-m

Version:
41 lines (40 loc) 1.48 kB
import { addPosToDataSource } from '../add-pos'; describe('addPosToDataSource', function () { it('should add pos to each node in the data source', function () { var dataSource = [ { label: 'Node 1', value: 'Node 1', children: [{ label: 'Node 1.1', value: 'Node 1.1' }], }, { label: 'Node 2', value: 'Node 2', children: [ { label: 'Node 2.1', value: 'Node 2.1' }, { label: 'Node 2.2', value: 'Node 2.2' }, ], }, ]; addPosToDataSource(dataSource, ''); expect(dataSource[0].pos).toBe('0'); expect(dataSource[0].children[0].pos).toBe('0-0'); expect(dataSource[1].pos).toBe('1'); expect(dataSource[1].children[0].pos).toBe('1-0'); expect(dataSource[1].children[1].pos).toBe('1-1'); }); it('should handle empty data source', function () { var dataSource = []; addPosToDataSource(dataSource, ''); expect(dataSource).toEqual([]); }); it('should handle data source with no children', function () { var dataSource = [ { label: 'Node 1', value: 'Node 1' }, { label: 'Node 2', value: 'Node 2' }, ]; addPosToDataSource(dataSource, ''); expect(dataSource[0].pos).toBe('0'); expect(dataSource[1].pos).toBe('1'); }); });