@cainiaofe/cn-ui-m
Version:
87 lines (86 loc) • 2.77 kB
JavaScript
import { getNodeAndParentsByPos } from '../get-node-and-parents-by-pos';
describe('getNodeAndParentsByPos', 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',
},
];
it('should return the node and its parents for a valid position', function () {
var result = getNodeAndParentsByPos(dataSource, '1-1-1');
expect(result).toEqual({
node: {
label: 'Node 1-1-1',
value: 'Node 1-1-1',
pos: '1-1-1',
},
parents: [
{
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 1-1',
value: 'Node 1-1',
pos: '1-1',
children: [
{
label: 'Node 1-1-1',
value: 'Node 1-1-1',
pos: '1-1-1',
},
],
},
],
});
});
it('should return undefined for an invalid position', function () {
var result = getNodeAndParentsByPos(dataSource, '3');
expect(result).toBeUndefined();
});
});