2024-04-08 14:04:08 +08:00
|
|
|
import React from 'react';
|
2023-07-18 12:18:51 +08:00
|
|
|
import type { TriggerProps, TriggerRef } from '@rc-component/trigger';
|
2023-04-04 17:17:36 +08:00
|
|
|
import dayjs from 'dayjs';
|
|
|
|
import customParseFormat from 'dayjs/plugin/customParseFormat';
|
2024-04-08 14:04:08 +08:00
|
|
|
|
2023-04-04 17:17:36 +08:00
|
|
|
import ConfigProvider from '..';
|
2023-04-07 10:17:00 +08:00
|
|
|
import { render } from '../../../tests/utils';
|
2023-04-04 17:17:36 +08:00
|
|
|
import Cascader from '../../cascader';
|
|
|
|
import Select from '../../select';
|
|
|
|
import TreeSelect from '../../tree-select';
|
|
|
|
|
|
|
|
dayjs.extend(customParseFormat);
|
2023-06-07 21:59:21 +08:00
|
|
|
jest.mock('rc-util/lib/Portal');
|
2023-04-04 17:17:36 +08:00
|
|
|
|
2023-04-07 10:17:00 +08:00
|
|
|
function triggerProps(): TriggerProps {
|
2023-06-07 21:59:21 +08:00
|
|
|
return (global as any).triggerProps;
|
2023-04-07 10:17:00 +08:00
|
|
|
}
|
|
|
|
|
2023-06-07 21:59:21 +08:00
|
|
|
jest.mock('@rc-component/trigger', () => {
|
2023-07-18 12:18:51 +08:00
|
|
|
const R: typeof React = jest.requireActual('react');
|
2023-06-07 21:59:21 +08:00
|
|
|
const Trigger = jest.requireActual('@rc-component/trigger').default;
|
2023-07-18 12:18:51 +08:00
|
|
|
return R.forwardRef<TriggerRef, TriggerProps>((props, ref) => {
|
2023-06-07 21:59:21 +08:00
|
|
|
(global as any).triggerProps = props;
|
|
|
|
return <Trigger {...props} ref={ref} />;
|
|
|
|
});
|
2023-04-07 10:17:00 +08:00
|
|
|
});
|
|
|
|
|
2023-04-04 17:17:36 +08:00
|
|
|
describe('ConfigProvider.Popup', () => {
|
2023-04-07 10:17:00 +08:00
|
|
|
beforeEach(() => {
|
|
|
|
(global as any).triggerProps = null;
|
|
|
|
});
|
|
|
|
|
2023-04-04 17:17:36 +08:00
|
|
|
const selectLikeNodes = (
|
|
|
|
<>
|
|
|
|
<Select
|
|
|
|
open
|
|
|
|
options={new Array(20).fill(null).map((_, index) => ({ value: index, label: index }))}
|
|
|
|
/>
|
|
|
|
<TreeSelect
|
|
|
|
open
|
|
|
|
treeData={new Array(20).fill(null).map((_, index) => ({ value: index, title: index }))}
|
|
|
|
/>
|
|
|
|
<Cascader
|
|
|
|
open
|
|
|
|
options={new Array(20).fill(null).map((_, index) => ({ value: index, label: index }))}
|
|
|
|
/>
|
|
|
|
</>
|
|
|
|
);
|
|
|
|
|
|
|
|
it('disable virtual if is false', () => {
|
|
|
|
const { container } = render(
|
|
|
|
<ConfigProvider virtual={false}>{selectLikeNodes}</ConfigProvider>,
|
|
|
|
);
|
|
|
|
|
|
|
|
expect(container).toMatchSnapshot();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('disable virtual if dropdownMatchSelectWidth is false', () => {
|
2023-06-07 21:59:21 +08:00
|
|
|
const errSpy = jest.spyOn(console, 'error').mockImplementation(() => {});
|
2023-04-04 17:17:36 +08:00
|
|
|
|
|
|
|
const { container } = render(
|
|
|
|
<ConfigProvider dropdownMatchSelectWidth={false}>{selectLikeNodes}</ConfigProvider>,
|
|
|
|
);
|
|
|
|
|
|
|
|
expect(container).toMatchSnapshot();
|
|
|
|
|
|
|
|
expect(errSpy).toHaveBeenCalledWith(
|
|
|
|
'Warning: [antd: ConfigProvider] `dropdownMatchSelectWidth` is deprecated. Please use `popupMatchSelectWidth` instead.',
|
|
|
|
);
|
|
|
|
errSpy.mockRestore();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('disable virtual if popupMatchSelectWidth is false', () => {
|
|
|
|
const { container } = render(
|
|
|
|
<ConfigProvider popupMatchSelectWidth={false}>{selectLikeNodes}</ConfigProvider>,
|
|
|
|
);
|
|
|
|
|
|
|
|
expect(container).toMatchSnapshot();
|
|
|
|
});
|
2023-04-07 10:17:00 +08:00
|
|
|
|
|
|
|
describe('config popupOverflow', () => {
|
|
|
|
it('Select', () => {
|
|
|
|
render(
|
|
|
|
<ConfigProvider popupOverflow="scroll">
|
|
|
|
<Select open />
|
|
|
|
</ConfigProvider>,
|
|
|
|
);
|
|
|
|
|
|
|
|
expect(triggerProps().builtinPlacements!.topLeft!.htmlRegion).toBe('scroll');
|
|
|
|
});
|
|
|
|
|
|
|
|
it('TreeSelect', () => {
|
|
|
|
render(
|
|
|
|
<ConfigProvider popupOverflow="scroll">
|
|
|
|
<TreeSelect open />
|
|
|
|
</ConfigProvider>,
|
|
|
|
);
|
|
|
|
|
|
|
|
expect(triggerProps().builtinPlacements!.topLeft!.htmlRegion).toBe('scroll');
|
|
|
|
});
|
|
|
|
|
|
|
|
it('Cascader', () => {
|
|
|
|
render(
|
|
|
|
<ConfigProvider popupOverflow="scroll">
|
|
|
|
<Cascader open />
|
|
|
|
</ConfigProvider>,
|
|
|
|
);
|
|
|
|
|
|
|
|
expect(triggerProps().builtinPlacements!.topLeft!.htmlRegion).toBe('scroll');
|
|
|
|
});
|
|
|
|
});
|
2023-04-04 17:17:36 +08:00
|
|
|
});
|