Skip to content

Commit 46221dc

Browse files
committed
test(tree-select): fold the switch-parent cases into index.test.js
Review feedback: keep one unit test file per component instead of adding a new file per scenario. The two switch-parent cases now live in index.test.js under their own describe block, and switch-parent.test.js is gone. No behaviour change.
1 parent 67874c1 commit 46221dc

2 files changed

Lines changed: 58 additions & 71 deletions

File tree

‎packages/components/tree-select/__test__/index.test.js‎

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,4 +113,62 @@ describe('tree-select', () => {
113113
expect(component.dom.textContent).not.toContain('First leaf');
114114
});
115115
});
116+
117+
describe('switch parent', () => {
118+
// 三层:父级 -> 中间层 -> 叶子层
119+
const deepOptions = [
120+
{
121+
label: 'A',
122+
value: 'a',
123+
children: [
124+
{ label: 'A1', value: 'a1', children: [{ label: 'A1x', value: 'a1x' }] },
125+
{ label: 'A2', value: 'a2', children: [{ label: 'A2x', value: 'a2x' }] },
126+
],
127+
},
128+
{
129+
label: 'B',
130+
value: 'b',
131+
children: [
132+
{ label: 'B1', value: 'b1', children: [{ label: 'B1x', value: 'b1x' }] },
133+
{ label: 'B2', value: 'b2', children: [{ label: 'B2x', value: 'b2x' }] },
134+
],
135+
},
136+
];
137+
138+
it('rebuilds the child columns when switching parent (issue #4664)', async () => {
139+
render({ options: deepOptions, value: ['a', 'a2', 'a2x'] });
140+
await simulate.sleep(10);
141+
142+
const inst = component.instance;
143+
// 初始:A 下面是 A1/A2
144+
let level1 = inst.data.treeOptions[1].map((item) => item.value);
145+
expect(level1).toEqual(['a1', 'a2']);
146+
expect(inst.data.innerValue[1]).toBe('a2');
147+
148+
// 切到父级 B
149+
inst.onRootChange({ detail: { value: 'b' } });
150+
await simulate.sleep(10);
151+
152+
// 切父级后,第二列必须换成 B 的子级
153+
level1 = inst.data.treeOptions[1].map((item) => item.value);
154+
expect(level1).toEqual(['b1', 'b2']);
155+
});
156+
157+
it('keeps intermediate highlight valid after switching parent (issue #4664)', async () => {
158+
render({ options: deepOptions, value: ['a', 'a2', 'a2x'] });
159+
await simulate.sleep(10);
160+
161+
const inst = component.instance;
162+
inst.onRootChange({ detail: { value: 'b' } });
163+
await simulate.sleep(10);
164+
165+
// 中间层高亮取决于 item.value === innerValue[level]。
166+
// 切到 B 之后,innerValue[1] 必须落在 B 的子级里,
167+
// 仍是旧父级的 'a2' 就意味着高亮对不上任何一项。
168+
const level1Values = inst.data.treeOptions[1].map((item) => item.value);
169+
expect(level1Values).toEqual(['b1', 'b2']);
170+
expect(inst.data.innerValue[1]).toBe('b1');
171+
expect(inst.data.innerValue[0]).toBe('b');
172+
});
173+
});
116174
});

‎packages/components/tree-select/__test__/switch-parent.test.js‎

Lines changed: 0 additions & 71 deletions
This file was deleted.

0 commit comments

Comments
 (0)