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');
|
});
|
});
|