Repository: element-plus/element-plus
File: packages/components/tree-select/__tests__/tree-select.test.tsx (TypeScript)

Code before:

    let flag = false
    function handleFocus() {
      return () => (flag = true)
    }
    vi.useFakeTimers()
    const selectWrapper = wrapper.find('.el-select__wrapper')
    await selectWrapper.trigger('click')
    await selectWrapper.trigger('focus')
    const focused = wrapper.find('.is-focused')
    expect(focused.exists()).toBe(true)
    await selectWrapper.find('input').trigger('keydown.ArrowDown')
    vi.runAllTimers()

    expect((document.activeElement as HTMLElement).dataset.key).toBe('1')

    const treeWrapper = wrapper.findComponent(Tree)
    const allNodes = treeWrapper.findAll('.el-tree-node')
    const len = allNodes.length
    for (let i = 0; i < len; i++) {
      if (allNodes[i + 1]) {
        defineGetter(allNodes[i + 1].element, 'focus', handleFocus)
        // 模拟按下下箭头键
        allNodes[i].element.dispatchEvent(
          new KeyboardEvent('keydown', {
            code: 'ArrowDown',
            bubbles: true,
            cancelable: false,
          })
        )
        expect(flag).toBe(true)
        flag = false
      }
    }
  })

  test('navigate up', async () => {
    const { wrapper } = createComponent({
      props: {
        defaultExpandAll: true,
      },
    })

    await nextTick()
    vi.useFakeTimers()
    const selectWrapper = wrapper.find('.el-select__wrapper')
    await selectWrapper.trigger('click')
    await selectWrapper.trigger('focus')
    const focused = wrapper.find('.is-focused')
    expect(focused.exists()).toBe(true)
    await selectWrapper.find('input').trigger('keydown.ArrowUp')

Review comment (suggestion):
```suggestion
            code: EVENT_CODE.down,
```

Code after:
    await nextTick()

    let flag = false
    function handleFocus() {
      return () => (flag = true)
    }
    vi.useFakeTimers()
    const selectWrapper = wrapper.find('.el-select__wrapper')
    await selectWrapper.trigger('click')
    await selectWrapper.trigger('focus')
    const focused = wrapper.find('.is-focused')
    expect(focused.exists()).toBe(true)
    await selectWrapper
      .find('input')
      .trigger('keydown', { key: EVENT_CODE.down })
    vi.runAllTimers()

    expect((document.activeElement as HTMLElement).dataset.key).toBe('1')

    const treeWrapper = wrapper.findComponent(Tree)
    const allNodes = treeWrapper.findAll('.el-tree-node')
    const len = allNodes.length
    for (let i = 0; i < len; i++) {
      if (allNodes[i + 1]) {
        defineGetter(allNodes[i + 1].element, 'focus', handleFocus)
        // 模拟按下下箭头键
        allNodes[i].element.dispatchEvent(
          new KeyboardEvent('keydown', {
            code: EVENT_CODE.down,
            bubbles: true,
            cancelable: false,
          })
        )
        expect(flag).toBe(true)
        flag = false
      }
    }
  })

  test('navigate up', async () => {
    const { wrapper } = createComponent({
      props: {
        defaultExpandAll: true,
      },
    })

    await nextTick()
    vi.useFakeTimers()
    const selectWrapper = wrapper.find('.el-select__wrapper')
    await selectWrapper.trigger('click')
    await selectWrapper.trigger('focus')