From 68e51822e83463d0c163ca9d9c205cef191cc95c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=8F=B6=E6=9E=AB?= <645381995@qq.com> Date: Tue, 3 Sep 2024 09:50:29 +0800 Subject: [PATCH] feat: test --- tests/index.spec.tsx | 81 +++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 80 insertions(+), 1 deletion(-) diff --git a/tests/index.spec.tsx b/tests/index.spec.tsx index 7c7c9ade..20e2d67a 100644 --- a/tests/index.spec.tsx +++ b/tests/index.spec.tsx @@ -6,7 +6,7 @@ import Cascader from '../src'; import { addressOptions, addressOptionsForUneven, optionsForActiveMenuItems } from './demoOptions'; import { mount } from './enzyme'; import { toRawValues } from '../src/utils/commonUtil'; -import { render } from '@testing-library/react'; +import { fireEvent, render } from '@testing-library/react'; describe('Cascader.Basic', () => { let selectedValue: any; @@ -1022,6 +1022,85 @@ describe('Cascader.Basic', () => { wrapper.find(`li[data-path-key]`).at(0).simulate('click'); wrapper.find(`li[data-path-key]`).at(1).simulate('click'); }); + it('hover + search', () => { + let getOffesetTopTimes = 0; + const spyElement = spyElementPrototypes(HTMLElement, { + offsetTop: { + get: () => (getOffesetTopTimes++ % 2 === 0 ? 100 : 0), + }, + scrollTop: { + get: () => 0, + }, + offsetHeight: { + get: () => 10, + }, + }); + + const wrapper = render( + , + ); + fireEvent.change(wrapper.container.querySelector('input') as HTMLElement, { + target: { value: 'w' }, + }); + const items = wrapper.container.querySelectorAll('.rc-cascader-menu-item'); + fireEvent.mouseEnter(items[9]); + expect(mockScrollTo).toHaveBeenCalledTimes(0); + + spyElement.mockRestore(); + }); }); it('not crash when value type is not array', () => {