刘光辉
9 小时以前 0dfe84494048ce27ba8449831782128412d3eb13
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
import { mount } from '@vue/test-utils';
 
import { TreeSelect as AntTreeSelect } from 'ant-design-vue';
import { describe, expect, it } from 'vitest';
 
import JnpfTreeSelect from './TreeSelect.vue';
import { TREE_PATH_LABEL_FIELD } from './utils';
 
const options = [
  {
    id: 'warehouse-1',
    fullName: '仓库1',
    children: [
      {
        id: 'area-101',
        fullName: '区域101',
        children: [{ id: 'layer-101', fullName: '层数 101' }],
      },
    ],
  },
];
 
describe('jnpfTreeSelect path display', () => {
  it('uses the full path only when showPath is enabled', async () => {
    const wrapper = mount(JnpfTreeSelect, {
      props: { options, showPath: true, value: 'layer-101' },
    });
    const treeSelect = wrapper.findComponent(AntTreeSelect);
 
    expect((treeSelect.props('treeData') as any[])[0].children[0].children[0][TREE_PATH_LABEL_FIELD]).toBe('仓库1/区域101/层数 101');
    expect(wrapper.classes()).toContain('jnpf-tree-select-show-path');
    expect(wrapper.find('.ant-select-selection-item .custom-tree-node-path-name').text()).toBe('仓库1/区域101/层数 101');
 
    await wrapper.setProps({ showPath: false });
 
    expect(wrapper.classes()).not.toContain('jnpf-tree-select-show-path');
    expect(wrapper.find('.ant-select-selection-item .custom-tree-node-path-name').exists()).toBe(false);
    expect(wrapper.find('.ant-select-selection-item').text()).toBe('层数 101');
  });
});