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

Code before:
    await tree.findAll('.el-tree-node__content')[0].trigger('click')
    expect(
      tree.findAll('.el-tree-node__children')[0].attributes('style')
    ).not.toContain('display: none;')
  })

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

    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.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 () => {

Review comment (suggestion):
```suggestion
    await selectWrapper.find('input').trigger('keydown', { code: EVENT_CODE.down })
```

It might be best to save it consistently with other test files

Code after:
    await wrapper.setProps({ expandOnClickNode: true })
    await tree.findAll('.el-tree-node__content')[0].trigger('click')
    expect(
      tree.findAll('.el-tree-node__children')[0].attributes('style')
    ).not.toContain('display: none;')
  })

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

    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
      }
    }