UNPKG

@cainiaofe/cn-ui-m

Version:
58 lines (57 loc) 1.7 kB
import { getNodeByPos } from '../get-node-by-pos'; describe('getNodeByPos', function () { var dataSource = [ { label: 'Node 1', value: 'Node 1', pos: '1', children: [ { label: 'Node 1-1', value: 'Node 1-1', pos: '1-1', children: [ { label: 'Node 1-1-1', value: 'Node 1-1-1', pos: '1-1-1', }, ], }, { label: 'Node 1-2', value: 'Node 1-2', pos: '1-2', }, ], }, { label: 'Node 2', value: 'Node 2', pos: '2', children: [ { label: 'Node 2-1', value: 'Node 2-1', pos: '2-1', }, ], }, ]; it('should return the node with the given pos', function () { var result = getNodeByPos(dataSource, '1-1-1'); expect(result).toEqual({ label: 'Node 1-1-1', value: 'Node 1-1-1', pos: '1-1-1', }); }); it('should return null if the node with the given pos is not found', function () { var result = getNodeByPos(dataSource, '3'); expect(result).toBeNull(); }); it('should return null if the dataSource is empty', function () { var result = getNodeByPos([], '1'); expect(result).toBeNull(); }); });