2017-03-02 00:16:37 +08:00
|
|
|
import React from 'react';
|
|
|
|
import Tabs from '..';
|
2019-08-26 22:53:20 +08:00
|
|
|
import mountTest from '../../../tests/shared/mountTest';
|
2020-01-02 19:10:16 +08:00
|
|
|
import rtlTest from '../../../tests/shared/rtlTest';
|
2022-06-22 14:57:09 +08:00
|
|
|
import { fireEvent, render } from '../../../tests/utils';
|
2022-08-05 10:49:08 +08:00
|
|
|
import { resetWarned } from '../../_util/warning';
|
2023-08-30 21:28:45 +08:00
|
|
|
import ConfigProvider from '../../config-provider';
|
2017-03-02 00:16:37 +08:00
|
|
|
|
|
|
|
const { TabPane } = Tabs;
|
|
|
|
|
|
|
|
describe('Tabs', () => {
|
2019-08-29 23:41:46 +08:00
|
|
|
mountTest(() => (
|
|
|
|
<Tabs>
|
|
|
|
<TabPane tab="xx" key="xx" />
|
|
|
|
</Tabs>
|
|
|
|
));
|
2020-01-02 19:10:16 +08:00
|
|
|
rtlTest(() => (
|
|
|
|
<Tabs>
|
|
|
|
<TabPane tab="xx" key="xx" />
|
|
|
|
</Tabs>
|
|
|
|
));
|
2019-08-26 22:53:20 +08:00
|
|
|
|
2017-03-02 00:16:37 +08:00
|
|
|
describe('editable-card', () => {
|
2023-06-07 21:59:21 +08:00
|
|
|
let handleEdit: jest.Mock;
|
2022-09-05 19:41:32 +08:00
|
|
|
let wrapper: ReturnType<typeof render>['container'];
|
2017-03-02 00:16:37 +08:00
|
|
|
|
|
|
|
beforeEach(() => {
|
2023-06-07 21:59:21 +08:00
|
|
|
handleEdit = jest.fn();
|
2022-05-29 22:50:31 +08:00
|
|
|
const { container } = render(
|
2017-03-02 00:16:37 +08:00
|
|
|
<Tabs type="editable-card" onEdit={handleEdit}>
|
2018-12-07 16:17:45 +08:00
|
|
|
<TabPane tab="foo" key="1">
|
|
|
|
foo
|
|
|
|
</TabPane>
|
2019-07-30 16:10:14 +08:00
|
|
|
{undefined}
|
|
|
|
{null}
|
|
|
|
{false}
|
2018-12-07 16:17:45 +08:00
|
|
|
</Tabs>,
|
2017-03-02 00:16:37 +08:00
|
|
|
);
|
2022-05-29 22:50:31 +08:00
|
|
|
wrapper = container;
|
2017-03-02 00:16:37 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
it('add card', () => {
|
2022-09-05 19:41:32 +08:00
|
|
|
fireEvent.click(wrapper.querySelector('.ant-tabs-nav-add')!);
|
2017-03-02 00:16:37 +08:00
|
|
|
expect(handleEdit.mock.calls[0][1]).toBe('add');
|
|
|
|
});
|
|
|
|
|
|
|
|
it('remove card', () => {
|
2022-09-05 19:41:32 +08:00
|
|
|
fireEvent.click(wrapper.querySelector('.anticon-close')!);
|
2019-04-03 15:54:26 +08:00
|
|
|
expect(handleEdit).toHaveBeenCalledWith('1', 'remove');
|
2017-03-02 00:16:37 +08:00
|
|
|
});
|
2019-07-30 16:10:14 +08:00
|
|
|
|
|
|
|
it('validateElement', () => {
|
2022-05-29 22:50:31 +08:00
|
|
|
expect(wrapper.querySelectorAll('.ant-tabs-tab').length).toBe(1);
|
2019-07-30 16:10:14 +08:00
|
|
|
});
|
2017-03-02 00:16:37 +08:00
|
|
|
});
|
2017-08-05 23:01:28 +08:00
|
|
|
|
|
|
|
describe('tabPosition', () => {
|
|
|
|
it('remove card', () => {
|
2022-05-29 22:50:31 +08:00
|
|
|
const { container } = render(
|
2017-08-05 23:01:28 +08:00
|
|
|
<Tabs tabPosition="left" tabBarExtraContent="xxx">
|
2018-12-07 16:17:45 +08:00
|
|
|
<TabPane tab="foo" key="1">
|
|
|
|
foo
|
|
|
|
</TabPane>
|
|
|
|
</Tabs>,
|
2017-08-05 23:01:28 +08:00
|
|
|
);
|
2022-05-29 22:50:31 +08:00
|
|
|
expect(container.firstChild).toMatchSnapshot();
|
2017-08-05 23:01:28 +08:00
|
|
|
});
|
|
|
|
});
|
2018-08-28 18:56:25 +08:00
|
|
|
|
|
|
|
describe('renderTabBar', () => {
|
|
|
|
it('custom-tab-bar', () => {
|
2022-05-29 22:50:31 +08:00
|
|
|
const { container } = render(
|
2018-08-28 18:56:25 +08:00
|
|
|
<Tabs renderTabBar={() => <div>custom-tab-bar</div>}>
|
2018-12-07 16:17:45 +08:00
|
|
|
<TabPane tab="foo" key="1">
|
|
|
|
foo
|
|
|
|
</TabPane>
|
|
|
|
</Tabs>,
|
2018-08-28 18:56:25 +08:00
|
|
|
);
|
2022-05-29 22:50:31 +08:00
|
|
|
expect(container.firstChild).toMatchSnapshot();
|
2018-08-28 18:56:25 +08:00
|
|
|
});
|
|
|
|
});
|
2020-05-30 18:28:25 +08:00
|
|
|
|
|
|
|
it('warning for onNextClick', () => {
|
2023-06-07 21:59:21 +08:00
|
|
|
const errorSpy = jest.spyOn(console, 'error').mockImplementation(() => {});
|
2022-09-05 19:41:32 +08:00
|
|
|
const onNextClick = { onNextClick() {} } as any;
|
|
|
|
render(<Tabs {...onNextClick} />);
|
2020-05-30 18:28:25 +08:00
|
|
|
expect(errorSpy).toHaveBeenCalledWith(
|
|
|
|
'Warning: [antd: Tabs] `onPrevClick` and `onNextClick` has been removed. Please use `onTabScroll` instead.',
|
|
|
|
);
|
|
|
|
errorSpy.mockRestore();
|
|
|
|
});
|
2021-05-24 16:24:00 +08:00
|
|
|
|
|
|
|
it('tabBarGutter should work', () => {
|
2022-05-29 22:50:31 +08:00
|
|
|
const { container: wrapper } = render(
|
2021-12-04 17:06:36 +08:00
|
|
|
<Tabs tabBarGutter={0}>
|
|
|
|
<TabPane />
|
|
|
|
<TabPane />
|
|
|
|
<TabPane />
|
|
|
|
</Tabs>,
|
|
|
|
);
|
2022-05-29 22:50:31 +08:00
|
|
|
expect(wrapper.firstChild).toMatchSnapshot();
|
|
|
|
const { container: wrapper2 } = render(
|
2021-12-04 17:06:36 +08:00
|
|
|
<Tabs tabBarGutter={0} tabPosition="left">
|
|
|
|
<TabPane />
|
|
|
|
<TabPane />
|
|
|
|
<TabPane />
|
|
|
|
</Tabs>,
|
|
|
|
);
|
2022-05-29 22:50:31 +08:00
|
|
|
expect(wrapper2.firstChild).toMatchSnapshot();
|
2021-05-24 16:24:00 +08:00
|
|
|
});
|
2022-08-05 10:49:08 +08:00
|
|
|
|
|
|
|
it('deprecated warning', () => {
|
|
|
|
resetWarned();
|
2023-06-07 21:59:21 +08:00
|
|
|
const errorSpy = jest.spyOn(console, 'error').mockImplementation(() => {});
|
2022-08-05 10:49:08 +08:00
|
|
|
|
|
|
|
const { container } = render(
|
|
|
|
<Tabs>
|
|
|
|
<TabPane />
|
|
|
|
invalidate
|
|
|
|
</Tabs>,
|
|
|
|
);
|
|
|
|
expect(container.querySelectorAll('.ant-tabs-tab')).toHaveLength(1);
|
|
|
|
|
|
|
|
expect(errorSpy).toHaveBeenCalledWith(
|
2023-09-13 22:07:33 +08:00
|
|
|
'Warning: [antd: Tabs] `Tabs.TabPane` is deprecated. Please use `items` instead.',
|
2022-08-05 10:49:08 +08:00
|
|
|
);
|
|
|
|
errorSpy.mockRestore();
|
|
|
|
});
|
2023-08-30 21:28:45 +08:00
|
|
|
|
|
|
|
it('indicator in ConfigProvider should work', () => {
|
|
|
|
const { container } = render(
|
|
|
|
<ConfigProvider tabs={{ indicatorSize: 12 }}>
|
|
|
|
<Tabs items={[{ key: '1', label: 'foo' }]} className="Tabs_1" />
|
|
|
|
<Tabs items={[{ key: '2', label: 'bar' }]} className="Tabs_2" />
|
|
|
|
<Tabs items={[{ key: '3', label: 'too' }]} indicatorSize={4} className="Tabs_3" />
|
|
|
|
</ConfigProvider>,
|
|
|
|
);
|
|
|
|
|
|
|
|
expect(container.querySelector('.Tabs_1 .ant-tabs-ink-bar')).toHaveStyle({ width: 12 });
|
|
|
|
expect(container.querySelector('.Tabs_2 .ant-tabs-ink-bar')).toHaveStyle({ width: 12 });
|
|
|
|
expect(container.querySelector('.Tabs_3 .ant-tabs-ink-bar')).toHaveStyle({ width: 4 });
|
|
|
|
});
|
2017-03-02 00:16:37 +08:00
|
|
|
});
|